]>
Commit | Line | Data |
---|---|---|
7267bd53 PH |
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, | |
ec85ded8 | 22 | 'thumbnail': r're:^https?://.*\.jpg$' |
7267bd53 PH |
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 | ||
39ca3b5c | 33 | title = self._og_search_title(webpage) |
7267bd53 PH |
34 | |
35 | data_js = self._search_regex( | |
6a26c5f9 | 36 | r'(?s)\nplaylist:\s*(\[.*?}\]),', |
7267bd53 PH |
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, | |
f983b875 | 61 | 'preference': -100 if '.smil' in s['file'] else 0, # Strictly inferior than all other formats? |
7267bd53 PH |
62 | }) |
63 | self._sort_formats(formats) | |
64 | ||
65 | return { | |
66 | 'id': video_id, | |
67 | 'display_id': display_id, | |
68 | 'title': title, | |
69 | 'formats': formats, | |
70 | 'is_live': True, | |
c8417897 | 71 | 'thumbnail': thumbnail, |
7267bd53 | 72 | } |