yt-dlp/yt_dlp/extractor/muenchentv.py

73 lines
2.0 KiB
Python
Raw Normal View History

2014-09-19 01:57:53 -06:00
import json
from .common import InfoExtractor
from ..utils import (
determine_ext,
int_or_none,
js_to_json,
)
class MuenchenTVIE(InfoExtractor):
_WORKING = False
2014-09-19 01:57:53 -06:00
_VALID_URL = r'https?://(?:www\.)?muenchen\.tv/livestream'
IE_DESC = 'münchen.tv'
_TEST = {
'url': 'http://www.muenchen.tv/livestream/',
'info_dict': {
'id': '5334',
'display_id': 'live',
'ext': 'mp4',
'title': 're:^münchen.tv-Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
'is_live': True,
'thumbnail': r're:^https?://.*\.jpg$',
2014-09-19 01:57:53 -06:00
},
'params': {
'skip_download': True,
},
2014-09-19 01:57:53 -06:00
}
def _real_extract(self, url):
display_id = 'live'
webpage = self._download_webpage(url, display_id)
2021-12-15 09:00:46 -07:00
title = self._og_search_title(webpage)
2014-09-19 01:57:53 -06:00
data_js = self._search_regex(
r'(?s)\nplaylist:\s*(\[.*?}\]),',
2014-09-19 01:57:53 -06:00
webpage, 'playlist configuration')
data_json = js_to_json(data_js)
data = json.loads(data_json)[0]
video_id = data['mediaid']
thumbnail = data.get('image')
formats = []
for format_num, s in enumerate(data['sources']):
ext = determine_ext(s['file'], None)
label_str = s.get('label')
if label_str is None:
label_str = f'_{format_num}'
2014-09-19 01:57:53 -06:00
if ext is None:
format_id = label_str
else:
format_id = f'{ext}-{label_str}'
2014-09-19 01:57:53 -06:00
formats.append({
'url': s['file'],
'tbr': int_or_none(s.get('label')),
'ext': 'mp4',
'format_id': format_id,
'preference': -100 if '.smil' in s['file'] else 0, # Strictly inferior than all other formats?
2014-09-19 01:57:53 -06:00
})
return {
'id': video_id,
'display_id': display_id,
'title': title,
'formats': formats,
'is_live': True,
2014-09-28 02:49:58 -06:00
'thumbnail': thumbnail,
2014-09-19 01:57:53 -06:00
}