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