]>
Commit | Line | Data |
---|---|---|
2b1b2d83 | 1 | # coding: utf-8 |
e8f2025e PH |
2 | from __future__ import unicode_literals |
3 | ||
df1d7da2 | 4 | from .common import InfoExtractor |
34921b43 | 5 | from ..compat import compat_urlparse |
2b1b2d83 S |
6 | from ..utils import ( |
7 | determine_ext, | |
8 | int_or_none, | |
34921b43 | 9 | join_nonempty, |
2b1b2d83 S |
10 | parse_duration, |
11 | parse_iso8601, | |
29f7c58a | 12 | url_or_none, |
2b1b2d83 S |
13 | xpath_text, |
14 | ) | |
df1d7da2 | 15 | |
09dacfa5 | 16 | |
df1d7da2 | 17 | class MDRIE(InfoExtractor): |
2b1b2d83 | 18 | IE_DESC = 'MDR.DE and KiKA' |
a5cf1798 | 19 | _VALID_URL = r'https?://(?:www\.)?(?:mdr|kika)\.de/(?:.*)/[a-z-]+-?(?P<id>\d+)(?:_.+?)?\.html' |
5f6a1245 | 20 | |
29f7c58a | 21 | _GEO_COUNTRIES = ['DE'] |
22 | ||
2b1b2d83 | 23 | _TESTS = [{ |
dfb1b146 | 24 | # MDR regularly deletes its videos |
e8f2025e PH |
25 | 'url': 'http://www.mdr.de/fakt/video189002.html', |
26 | 'only_matching': True, | |
82b69a5c | 27 | }, { |
8cdb5c84 S |
28 | # audio |
29 | 'url': 'http://www.mdr.de/kultur/audio1312272_zc-15948bad_zs-86171fdd.html', | |
30 | 'md5': '64c4ee50f0a791deb9479cd7bbe9d2fa', | |
31 | 'info_dict': { | |
32 | 'id': '1312272', | |
33 | 'ext': 'mp3', | |
34 | 'title': 'Feuilleton vom 30. Oktober 2015', | |
35 | 'duration': 250, | |
36 | 'uploader': 'MITTELDEUTSCHER RUNDFUNK', | |
37 | }, | |
a5cf1798 | 38 | 'skip': '404 not found', |
2b1b2d83 S |
39 | }, { |
40 | 'url': 'http://www.kika.de/baumhaus/videos/video19636.html', | |
41 | 'md5': '4930515e36b06c111213e80d1e4aad0e', | |
42 | 'info_dict': { | |
43 | 'id': '19636', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Baumhaus vom 30. Oktober 2015', | |
46 | 'duration': 134, | |
47 | 'uploader': 'KIKA', | |
48 | }, | |
a5cf1798 | 49 | 'skip': '404 not found', |
2b1b2d83 S |
50 | }, { |
51 | 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/videos/video8182.html', | |
52 | 'md5': '5fe9c4dd7d71e3b238f04b8fdd588357', | |
53 | 'info_dict': { | |
54 | 'id': '8182', | |
55 | 'ext': 'mp4', | |
56 | 'title': 'Beutolomäus und der geheime Weihnachtswunsch', | |
57 | 'description': 'md5:b69d32d7b2c55cbe86945ab309d39bbd', | |
a5cf1798 YCH |
58 | 'timestamp': 1482541200, |
59 | 'upload_date': '20161224', | |
2b1b2d83 S |
60 | 'duration': 4628, |
61 | 'uploader': 'KIKA', | |
62 | }, | |
a5cf1798 YCH |
63 | }, { |
64 | # audio with alternative playerURL pattern | |
65 | 'url': 'http://www.mdr.de/kultur/videos-und-audios/audio-radio/operation-mindfuck-robert-wilson100.html', | |
66 | 'info_dict': { | |
67 | 'id': '100', | |
68 | 'ext': 'mp4', | |
69 | 'title': 'Feature: Operation Mindfuck - Robert Anton Wilson', | |
70 | 'duration': 3239, | |
71 | 'uploader': 'MITTELDEUTSCHER RUNDFUNK', | |
72 | }, | |
29f7c58a | 73 | }, { |
74 | # empty bitrateVideo and bitrateAudio | |
75 | 'url': 'https://www.kika.de/filme/sendung128372_zc-572e3f45_zs-1d9fb70e.html', | |
76 | 'info_dict': { | |
77 | 'id': '128372', | |
78 | 'ext': 'mp4', | |
79 | 'title': 'Der kleine Wichtel kehrt zurück', | |
80 | 'description': 'md5:f77fafdff90f7aa1e9dca14f662c052a', | |
81 | 'duration': 4876, | |
82 | 'timestamp': 1607823300, | |
83 | 'upload_date': '20201213', | |
84 | 'uploader': 'ZDF', | |
85 | }, | |
86 | 'params': { | |
87 | 'skip_download': True, | |
88 | }, | |
2b1b2d83 S |
89 | }, { |
90 | 'url': 'http://www.kika.de/baumhaus/sendungen/video19636_zc-fea7f8a0_zs-4bf89c60.html', | |
91 | 'only_matching': True, | |
92 | }, { | |
93 | 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/einzelsendung2534.html', | |
94 | 'only_matching': True, | |
2812c24c S |
95 | }, { |
96 | 'url': 'http://www.mdr.de/mediathek/mdr-videos/a/video-1334.html', | |
97 | 'only_matching': True, | |
2b1b2d83 | 98 | }] |
df1d7da2 | 99 | |
100 | def _real_extract(self, url): | |
2b1b2d83 S |
101 | video_id = self._match_id(url) |
102 | ||
103 | webpage = self._download_webpage(url, video_id) | |
df1d7da2 | 104 | |
2b1b2d83 | 105 | data_url = self._search_regex( |
a5cf1798 | 106 | r'(?:dataURL|playerXml(?:["\'])?)\s*:\s*(["\'])(?P<url>.+?-avCustom\.xml)\1', |
ec85ded8 | 107 | webpage, 'data url', group='url').replace(r'\/', '/') |
df1d7da2 | 108 | |
2b1b2d83 S |
109 | doc = self._download_xml( |
110 | compat_urlparse.urljoin(url, data_url), video_id) | |
111 | ||
11465da7 | 112 | title = xpath_text(doc, ['./title', './broadcast/broadcastName'], 'title', fatal=True) |
09dacfa5 | 113 | |
29f7c58a | 114 | type_ = xpath_text(doc, './type', default=None) |
115 | ||
09dacfa5 | 116 | formats = [] |
2b1b2d83 S |
117 | processed_urls = [] |
118 | for asset in doc.findall('./assets/asset'): | |
119 | for source in ( | |
29f7c58a | 120 | 'download', |
2b1b2d83 S |
121 | 'progressiveDownload', |
122 | 'dynamicHttpStreamingRedirector', | |
123 | 'adaptiveHttpStreamingRedirector'): | |
124 | url_el = asset.find('./%sUrl' % source) | |
125 | if url_el is None: | |
126 | continue | |
127 | ||
29f7c58a | 128 | video_url = url_or_none(url_el.text) |
129 | if not video_url or video_url in processed_urls: | |
2b1b2d83 S |
130 | continue |
131 | ||
132 | processed_urls.append(video_url) | |
133 | ||
29f7c58a | 134 | ext = determine_ext(video_url) |
2b1b2d83 | 135 | if ext == 'm3u8': |
29f7c58a | 136 | formats.extend(self._extract_m3u8_formats( |
2b1b2d83 | 137 | video_url, video_id, 'mp4', entry_protocol='m3u8_native', |
f983b875 | 138 | quality=1, m3u8_id='HLS', fatal=False)) |
2b1b2d83 | 139 | elif ext == 'f4m': |
29f7c58a | 140 | formats.extend(self._extract_f4m_formats( |
2b1b2d83 | 141 | video_url + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id, |
f983b875 | 142 | quality=1, f4m_id='HDS', fatal=False)) |
2b1b2d83 S |
143 | else: |
144 | media_type = xpath_text(asset, './mediaType', 'media type', default='MP4') | |
145 | vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000) | |
146 | abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000) | |
147 | filesize = int_or_none(xpath_text(asset, './fileSize', 'file size')) | |
148 | ||
149 | f = { | |
150 | 'url': video_url, | |
34921b43 | 151 | 'format_id': join_nonempty(media_type, vbr or abr), |
2b1b2d83 S |
152 | 'filesize': filesize, |
153 | 'abr': abr, | |
29f7c58a | 154 | 'vbr': vbr, |
2b1b2d83 S |
155 | } |
156 | ||
157 | if vbr: | |
2b1b2d83 | 158 | f.update({ |
29f7c58a | 159 | 'width': int_or_none(xpath_text(asset, './frameWidth', 'width')), |
160 | 'height': int_or_none(xpath_text(asset, './frameHeight', 'height')), | |
2b1b2d83 S |
161 | }) |
162 | ||
29f7c58a | 163 | if type_ == 'audio': |
164 | f['vcodec'] = 'none' | |
2b1b2d83 | 165 | |
29f7c58a | 166 | formats.append(f) |
76f0c50d | 167 | |
b874fe2d PH |
168 | self._sort_formats(formats) |
169 | ||
2b1b2d83 S |
170 | description = xpath_text(doc, './broadcast/broadcastDescription', 'description') |
171 | timestamp = parse_iso8601( | |
11465da7 S |
172 | xpath_text( |
173 | doc, [ | |
174 | './broadcast/broadcastDate', | |
175 | './broadcast/broadcastStartDate', | |
176 | './broadcast/broadcastEndDate'], | |
177 | 'timestamp', default=None)) | |
2b1b2d83 S |
178 | duration = parse_duration(xpath_text(doc, './duration', 'duration')) |
179 | uploader = xpath_text(doc, './rights', 'uploader') | |
180 | ||
09dacfa5 PH |
181 | return { |
182 | 'id': video_id, | |
183 | 'title': title, | |
2b1b2d83 S |
184 | 'description': description, |
185 | 'timestamp': timestamp, | |
186 | 'duration': duration, | |
187 | 'uploader': uploader, | |
09dacfa5 PH |
188 | 'formats': formats, |
189 | } |