]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/muenchentv.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / muenchentv.py
1 import json
2
3 from .common import InfoExtractor
4 from ..utils import (
5 determine_ext,
6 int_or_none,
7 js_to_json,
8 )
9
10
11 class MuenchenTVIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?muenchen\.tv/livestream'
13 IE_DESC = 'münchen.tv'
14 _TEST = {
15 'url': 'http://www.muenchen.tv/livestream/',
16 'info_dict': {
17 'id': '5334',
18 'display_id': 'live',
19 'ext': 'mp4',
20 'title': 're:^münchen.tv-Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
21 'is_live': True,
22 'thumbnail': r're:^https?://.*\.jpg$'
23 },
24 'params': {
25 'skip_download': True,
26 }
27 }
28
29 def _real_extract(self, url):
30 display_id = 'live'
31 webpage = self._download_webpage(url, display_id)
32
33 title = self._og_search_title(webpage)
34
35 data_js = self._search_regex(
36 r'(?s)\nplaylist:\s*(\[.*?}\]),',
37 webpage, 'playlist configuration')
38 data_json = js_to_json(data_js)
39 data = json.loads(data_json)[0]
40
41 video_id = data['mediaid']
42 thumbnail = data.get('image')
43
44 formats = []
45 for format_num, s in enumerate(data['sources']):
46 ext = determine_ext(s['file'], None)
47 label_str = s.get('label')
48 if label_str is None:
49 label_str = '_%d' % format_num
50
51 if ext is None:
52 format_id = label_str
53 else:
54 format_id = '%s-%s' % (ext, label_str)
55
56 formats.append({
57 'url': s['file'],
58 'tbr': int_or_none(s.get('label')),
59 'ext': 'mp4',
60 'format_id': format_id,
61 'preference': -100 if '.smil' in s['file'] else 0, # Strictly inferior than all other formats?
62 })
63
64 return {
65 'id': video_id,
66 'display_id': display_id,
67 'title': title,
68 'formats': formats,
69 'is_live': True,
70 'thumbnail': thumbnail,
71 }