]>
Commit | Line | Data |
---|---|---|
32dac694 PH |
1 | from __future__ import unicode_literals |
2 | ||
fc287219 | 3 | import re |
fc287219 | 4 | |
0af25f78 | 5 | from .common import InfoExtractor |
1cc79574 | 6 | from ..compat import ( |
e525d9a3 | 7 | compat_str, |
20a6a154 | 8 | compat_xpath, |
1cc79574 PH |
9 | ) |
10 | from ..utils import ( | |
fc287219 | 11 | ExtractorError, |
90834c78 | 12 | find_xpath_attr, |
5aafe895 | 13 | fix_xml_ampersands, |
8765151c | 14 | float_or_none, |
0ef68e04 | 15 | HEADRequest, |
0c75abbb | 16 | RegexNotFoundError, |
5c2266df | 17 | sanitized_Request, |
7cdfc4c9 | 18 | strip_or_none, |
712c7530 | 19 | timeconvert, |
adf063da | 20 | try_get, |
340b0468 | 21 | unescapeHTML, |
0c75abbb | 22 | update_url_query, |
8d9453b9 | 23 | url_basename, |
5767b4ee | 24 | xpath_text, |
fc287219 PH |
25 | ) |
26 | ||
90834c78 | 27 | |
300fcad8 JMF |
28 | def _media_xml_tag(tag): |
29 | return '{http://search.yahoo.com/mrss/}%s' % tag | |
fc287219 | 30 | |
f7e02595 | 31 | |
0af25f78 | 32 | class MTVServicesInfoExtractor(InfoExtractor): |
340b0468 | 33 | _MOBILE_TEMPLATE = None |
a542e372 | 34 | _LANG = None |
8940c1c0 | 35 | |
f7e02595 JMF |
36 | @staticmethod |
37 | def _id_from_uri(uri): | |
38 | return uri.split(':')[-1] | |
39 | ||
0c75abbb YCH |
40 | @staticmethod |
41 | def _remove_template_parameter(url): | |
42 | # Remove the templates, like &device={device} | |
43 | return re.sub(r'&[^=]*?={.*?}(?=(&|$))', '', url) | |
44 | ||
8940c1c0 JMF |
45 | def _get_feed_url(self, uri): |
46 | return self._FEED_URL | |
47 | ||
ab2f744b | 48 | def _get_thumbnail_url(self, uri, itemdoc): |
84db8181 JMF |
49 | search_path = '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail')) |
50 | thumb_node = itemdoc.find(search_path) | |
51 | if thumb_node is None: | |
52 | return None | |
70bfab0e | 53 | return thumb_node.get('url') or thumb_node.text or None |
f7e02595 | 54 | |
340b0468 JMF |
55 | def _extract_mobile_video_formats(self, mtvn_id): |
56 | webpage_url = self._MOBILE_TEMPLATE % mtvn_id | |
5c2266df | 57 | req = sanitized_Request(webpage_url) |
340b0468 | 58 | # Otherwise we get a webpage that would execute some javascript |
3fcfb8e9 | 59 | req.add_header('User-Agent', 'curl/7') |
340b0468 | 60 | webpage = self._download_webpage(req, mtvn_id, |
9e1a5b84 | 61 | 'Downloading mobile page') |
0ef68e04 JMF |
62 | metrics_url = unescapeHTML(self._search_regex(r'<a href="(http://metrics.+?)"', webpage, 'url')) |
63 | req = HEADRequest(metrics_url) | |
64 | response = self._request_webpage(req, mtvn_id, 'Resolving url') | |
65 | url = response.geturl() | |
66 | # Transform the url to get the best quality: | |
67 | url = re.sub(r'.+pxE=mp4', 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=mp4', url, 1) | |
5f6a1245 | 68 | return [{'url': url, 'ext': 'mp4'}] |
340b0468 | 69 | |
dbaf6016 | 70 | def _extract_video_formats(self, mdoc, mtvn_id, video_id): |
054d43bb | 71 | if re.match(r'.*/(error_country_block\.swf|geoblock\.mp4|copyright_error\.flv(?:\?geo\b.+?)?)$', mdoc.find('.//src').text) is not None: |
340b0468 | 72 | if mtvn_id is not None and self._MOBILE_TEMPLATE is not None: |
0ef68e04 | 73 | self.to_screen('The normal version is not available from your ' |
9e1a5b84 | 74 | 'country, trying with the mobile version') |
340b0468 | 75 | return self._extract_mobile_video_formats(mtvn_id) |
cc1db7f9 | 76 | raise ExtractorError('This video is not available from your country.', |
9e1a5b84 | 77 | expected=True) |
f7e02595 | 78 | |
f13d0933 PH |
79 | formats = [] |
80 | for rendition in mdoc.findall('.//rendition'): | |
20faad74 | 81 | if rendition.get('method') == 'hls': |
dbaf6016 | 82 | hls_url = rendition.find('./src').text |
cdd11c05 | 83 | formats.extend(self._extract_m3u8_formats( |
adf063da | 84 | hls_url, video_id, ext='mp4', entry_protocol='m3u8_native', |
e0f1fb0a | 85 | m3u8_id='hls', fatal=False)) |
dbaf6016 PH |
86 | else: |
87 | # fms | |
88 | try: | |
89 | _, _, ext = rendition.attrib['type'].partition('/') | |
90 | rtmp_video_url = rendition.find('./src').text | |
adf063da S |
91 | if 'error_not_available.swf' in rtmp_video_url: |
92 | raise ExtractorError( | |
93 | '%s said: video is not available' % self.IE_NAME, | |
94 | expected=True) | |
dbaf6016 PH |
95 | if rtmp_video_url.endswith('siteunavail.png'): |
96 | continue | |
dbaf6016 | 97 | formats.extend([{ |
adf063da S |
98 | 'ext': 'flv' if rtmp_video_url.startswith('rtmp') else ext, |
99 | 'url': rtmp_video_url, | |
100 | 'format_id': '-'.join(filter(None, [ | |
101 | 'rtmp' if rtmp_video_url.startswith('rtmp') else None, | |
102 | rendition.get('bitrate')])), | |
dbaf6016 PH |
103 | 'width': int(rendition.get('width')), |
104 | 'height': int(rendition.get('height')), | |
adf063da | 105 | }]) |
dbaf6016 PH |
106 | except (KeyError, TypeError): |
107 | raise ExtractorError('Invalid rendition field.') | |
e0f1fb0a S |
108 | if formats: |
109 | self._sort_formats(formats) | |
f13d0933 | 110 | return formats |
f7e02595 | 111 | |
e525d9a3 S |
112 | def _extract_subtitles(self, mdoc, mtvn_id): |
113 | subtitles = {} | |
e525d9a3 S |
114 | for transcript in mdoc.findall('.//transcript'): |
115 | if transcript.get('kind') != 'captions': | |
116 | continue | |
117 | lang = transcript.get('srclang') | |
5ea765fb RA |
118 | for typographic in transcript.findall('./typographic'): |
119 | sub_src = typographic.get('src') | |
120 | if not sub_src: | |
121 | continue | |
122 | ext = typographic.get('format') | |
123 | if ext == 'cea-608': | |
124 | ext = 'scc' | |
125 | subtitles.setdefault(lang, []).append({ | |
126 | 'url': compat_str(sub_src), | |
127 | 'ext': ext | |
128 | }) | |
0af25f78 | 129 | return subtitles |
e525d9a3 | 130 | |
67fc365b | 131 | def _get_video_info(self, itemdoc, use_hls=True): |
f7e02595 JMF |
132 | uri = itemdoc.find('guid').text |
133 | video_id = self._id_from_uri(uri) | |
134 | self.report_extraction(video_id) | |
04cbc498 | 135 | content_el = itemdoc.find('%s/%s' % (_media_xml_tag('group'), _media_xml_tag('content'))) |
0c75abbb | 136 | mediagen_url = self._remove_template_parameter(content_el.attrib['url']) |
dbaf6016 | 137 | mediagen_url = mediagen_url.replace('device={device}', '') |
f7e02595 | 138 | if 'acceptMethods' not in mediagen_url: |
56f447be | 139 | mediagen_url += '&' if '?' in mediagen_url else '?' |
dbaf6016 PH |
140 | mediagen_url += 'acceptMethods=' |
141 | mediagen_url += 'hls' if use_hls else 'fms' | |
6562df76 | 142 | |
e0f1fb0a S |
143 | mediagen_doc = self._download_xml( |
144 | mediagen_url, video_id, 'Downloading video urls', fatal=False) | |
145 | ||
146 | if mediagen_doc is False: | |
147 | return None | |
f7e02595 | 148 | |
0dfe9bc9 S |
149 | item = mediagen_doc.find('./video/item') |
150 | if item is not None and item.get('type') == 'text': | |
151 | message = '%s returned error: ' % self.IE_NAME | |
152 | if item.get('code') is not None: | |
153 | message += '%s - ' % item.get('code') | |
154 | message += item.text | |
155 | raise ExtractorError(message, expected=True) | |
156 | ||
7cdfc4c9 | 157 | description = strip_or_none(xpath_text(itemdoc, 'description')) |
f13d0933 | 158 | |
712c7530 YCH |
159 | timestamp = timeconvert(xpath_text(itemdoc, 'pubDate')) |
160 | ||
90834c78 PH |
161 | title_el = None |
162 | if title_el is None: | |
163 | title_el = find_xpath_attr( | |
164 | itemdoc, './/{http://search.yahoo.com/mrss/}category', | |
165 | 'scheme', 'urn:mtvn:video_title') | |
90834c78 | 166 | if title_el is None: |
20a6a154 | 167 | title_el = itemdoc.find(compat_xpath('.//{http://search.yahoo.com/mrss/}title')) |
96cb10a5 | 168 | if title_el is None: |
20a6a154 | 169 | title_el = itemdoc.find(compat_xpath('.//title')) |
1df4229b PH |
170 | if title_el.text is None: |
171 | title_el = None | |
1df4229b | 172 | |
90834c78 PH |
173 | title = title_el.text |
174 | if title is None: | |
175 | raise ExtractorError('Could not find video title') | |
780ee4e5 | 176 | title = title.strip() |
90834c78 | 177 | |
340b0468 JMF |
178 | # This a short id that's used in the webpage urls |
179 | mtvn_id = None | |
180 | mtvn_id_node = find_xpath_attr(itemdoc, './/{http://search.yahoo.com/mrss/}category', | |
9e1a5b84 | 181 | 'scheme', 'urn:mtvn:id') |
340b0468 JMF |
182 | if mtvn_id_node is not None: |
183 | mtvn_id = mtvn_id_node.text | |
184 | ||
dbaf6016 PH |
185 | formats = self._extract_video_formats(mediagen_doc, mtvn_id, video_id) |
186 | ||
e0f1fb0a S |
187 | # Some parts of complete video may be missing (e.g. missing Act 3 in |
188 | # http://www.southpark.de/alle-episoden/s14e01-sexual-healing) | |
189 | if not formats: | |
190 | return None | |
191 | ||
192 | self._sort_formats(formats) | |
193 | ||
fb7abb31 | 194 | return { |
90834c78 | 195 | 'title': title, |
dbaf6016 | 196 | 'formats': formats, |
e525d9a3 | 197 | 'subtitles': self._extract_subtitles(mediagen_doc, mtvn_id), |
f13d0933 PH |
198 | 'id': video_id, |
199 | 'thumbnail': self._get_thumbnail_url(uri, itemdoc), | |
200 | 'description': description, | |
04cbc498 | 201 | 'duration': float_or_none(content_el.attrib.get('duration')), |
712c7530 | 202 | 'timestamp': timestamp, |
f13d0933 PH |
203 | } |
204 | ||
c1e90619 | 205 | def _get_feed_query(self, uri): |
206 | data = {'uri': uri} | |
207 | if self._LANG: | |
208 | data['lang'] = self._LANG | |
0c75abbb | 209 | return data |
c1e90619 | 210 | |
67fc365b | 211 | def _get_videos_info(self, uri, use_hls=True): |
f7e02595 | 212 | video_id = self._id_from_uri(uri) |
8940c1c0 | 213 | feed_url = self._get_feed_url(uri) |
0c75abbb | 214 | info_url = update_url_query(feed_url, self._get_feed_query(uri)) |
dbaf6016 | 215 | return self._get_videos_info_from_url(info_url, video_id, use_hls) |
79fa9db0 | 216 | |
67fc365b | 217 | def _get_videos_info_from_url(self, url, video_id, use_hls=True): |
e2b38da9 | 218 | idoc = self._download_xml( |
79fa9db0 | 219 | url, video_id, |
32dac694 | 220 | 'Downloading info', transform_source=fix_xml_ampersands) |
712c7530 YCH |
221 | |
222 | title = xpath_text(idoc, './channel/title') | |
223 | description = xpath_text(idoc, './channel/description') | |
224 | ||
e0f1fb0a S |
225 | entries = [] |
226 | for item in idoc.findall('.//item'): | |
227 | info = self._get_video_info(item, use_hls) | |
228 | if info: | |
229 | entries.append(info) | |
230 | ||
5239075b | 231 | return self.playlist_result( |
e0f1fb0a | 232 | entries, playlist_title=title, playlist_description=description) |
fc287219 | 233 | |
adf063da S |
234 | def _extract_triforce_mgid(self, webpage, data_zone=None, video_id=None): |
235 | triforce_feed = self._parse_json(self._search_regex( | |
f1e70fc2 | 236 | r'triforceManifestFeed\s*=\s*({.+?})\s*;\s*\n', webpage, |
adf063da S |
237 | 'triforce feed', default='{}'), video_id, fatal=False) |
238 | ||
239 | data_zone = self._search_regex( | |
240 | r'data-zone=(["\'])(?P<zone>.+?_lc_promo.*?)\1', webpage, | |
241 | 'data zone', default=data_zone, group='zone') | |
242 | ||
243 | feed_url = try_get( | |
244 | triforce_feed, lambda x: x['manifest']['zones'][data_zone]['feed'], | |
245 | compat_str) | |
246 | if not feed_url: | |
247 | return | |
248 | ||
249 | feed = self._download_json(feed_url, video_id, fatal=False) | |
250 | if not feed: | |
251 | return | |
252 | ||
253 | return try_get(feed, lambda x: x['result']['data']['id'], compat_str) | |
254 | ||
255 | def _extract_mgid(self, webpage): | |
8d9453b9 | 256 | try: |
4bbf139a JMF |
257 | # the url can be http://media.mtvnservices.com/fb/{mgid}.swf |
258 | # or http://media.mtvnservices.com/{mgid} | |
259 | og_url = self._og_search_video_url(webpage) | |
260 | mgid = url_basename(og_url) | |
261 | if mgid.endswith('.swf'): | |
262 | mgid = mgid[:-4] | |
8d9453b9 | 263 | except RegexNotFoundError: |
b1298d8e AMW |
264 | mgid = None |
265 | ||
266 | if mgid is None or ':' not in mgid: | |
b9381e43 | 267 | mgid = self._search_regex( |
197224b7 | 268 | [r'data-mgid="(.*?)"', r'swfobject\.embedSWF\(".*?(mgid:.*?)"'], |
fc42bc6e S |
269 | webpage, 'mgid', default=None) |
270 | ||
271 | if not mgid: | |
272 | sm4_embed = self._html_search_meta( | |
273 | 'sm4:video:embed', webpage, 'sm4 embed', default='') | |
274 | mgid = self._search_regex( | |
adf063da S |
275 | r'embed/(mgid:.+?)["\'&?/]', sm4_embed, 'mgid', default=None) |
276 | ||
277 | if not mgid: | |
278 | mgid = self._extract_triforce_mgid(webpage) | |
279 | ||
c1e90619 | 280 | return mgid |
e525d9a3 | 281 | |
c1e90619 | 282 | def _real_extract(self, url): |
283 | title = url_basename(url) | |
284 | webpage = self._download_webpage(url, title) | |
285 | mgid = self._extract_mgid(webpage) | |
e525d9a3 | 286 | videos_info = self._get_videos_info(mgid) |
e525d9a3 | 287 | return videos_info |
8d9453b9 | 288 | |
84db8181 | 289 | |
8940c1c0 JMF |
290 | class MTVServicesEmbeddedIE(MTVServicesInfoExtractor): |
291 | IE_NAME = 'mtvservices:embedded' | |
292 | _VALID_URL = r'https?://media\.mtvnservices\.com/embed/(?P<mgid>.+?)(\?|/|$)' | |
293 | ||
294 | _TEST = { | |
295 | # From http://www.thewrap.com/peter-dinklage-sums-up-game-of-thrones-in-45-seconds-video/ | |
296 | 'url': 'http://media.mtvnservices.com/embed/mgid:uma:video:mtv.com:1043906/cp~vid%3D1043906%26uri%3Dmgid%3Auma%3Avideo%3Amtv.com%3A1043906', | |
297 | 'md5': 'cb349b21a7897164cede95bd7bf3fbb9', | |
298 | 'info_dict': { | |
299 | 'id': '1043906', | |
300 | 'ext': 'mp4', | |
301 | 'title': 'Peter Dinklage Sums Up \'Game Of Thrones\' In 45 Seconds', | |
302 | 'description': '"Sexy sexy sexy, stabby stabby stabby, beautiful language," says Peter Dinklage as he tries summarizing "Game of Thrones" in under a minute.', | |
712c7530 YCH |
303 | 'timestamp': 1400126400, |
304 | 'upload_date': '20140515', | |
8940c1c0 JMF |
305 | }, |
306 | } | |
307 | ||
fe1d858e S |
308 | @staticmethod |
309 | def _extract_url(webpage): | |
310 | mobj = re.search( | |
311 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//media.mtvnservices.com/embed/.+?)\1', webpage) | |
312 | if mobj: | |
313 | return mobj.group('url') | |
314 | ||
8940c1c0 JMF |
315 | def _get_feed_url(self, uri): |
316 | video_id = self._id_from_uri(uri) | |
0c75abbb YCH |
317 | config = self._download_json( |
318 | 'http://media.mtvnservices.com/pmt/e1/access/index.html?uri=%s&configtype=edge' % uri, video_id) | |
319 | return self._remove_template_parameter(config['feedWithQueryParams']) | |
8940c1c0 JMF |
320 | |
321 | def _real_extract(self, url): | |
322 | mobj = re.match(self._VALID_URL, url) | |
323 | mgid = mobj.group('mgid') | |
324 | return self._get_videos_info(mgid) | |
325 | ||
326 | ||
84db8181 | 327 | class MTVIE(MTVServicesInfoExtractor): |
a54ffb8a | 328 | IE_NAME = 'mtv' |
cf0cabbe | 329 | _VALID_URL = r'https?://(?:www\.)?mtv\.com/(?:video-clips|(?:full-)?episodes)/(?P<id>[^/?#.]+)' |
8add4bfe RA |
330 | _FEED_URL = 'http://www.mtv.com/feeds/mrss/' |
331 | ||
332 | _TESTS = [{ | |
333 | 'url': 'http://www.mtv.com/video-clips/vl8qof/unlocking-the-truth-trailer', | |
334 | 'md5': '1edbcdf1e7628e414a8c5dcebca3d32b', | |
335 | 'info_dict': { | |
336 | 'id': '5e14040d-18a4-47c4-a582-43ff602de88e', | |
337 | 'ext': 'mp4', | |
338 | 'title': 'Unlocking The Truth|July 18, 2016|1|101|Trailer', | |
339 | 'description': '"Unlocking the Truth" premieres August 17th at 11/10c.', | |
340 | 'timestamp': 1468846800, | |
341 | 'upload_date': '20160718', | |
342 | }, | |
343 | }, { | |
344 | 'url': 'http://www.mtv.com/full-episodes/94tujl/unlocking-the-truth-gates-of-hell-season-1-ep-101', | |
345 | 'only_matching': True, | |
cf0cabbe S |
346 | }, { |
347 | 'url': 'http://www.mtv.com/episodes/g8xu7q/teen-mom-2-breaking-the-wall-season-7-ep-713', | |
348 | 'only_matching': True, | |
8add4bfe RA |
349 | }] |
350 | ||
351 | ||
008f2470 S |
352 | class MTV81IE(InfoExtractor): |
353 | IE_NAME = 'mtv81' | |
354 | _VALID_URL = r'https?://(?:www\.)?mtv81\.com/videos/(?P<id>[^/?#.]+)' | |
355 | ||
356 | _TEST = { | |
357 | 'url': 'http://www.mtv81.com/videos/artist-to-watch/the-godfather-of-japanese-hip-hop-segment-1/', | |
358 | 'md5': '1edbcdf1e7628e414a8c5dcebca3d32b', | |
359 | 'info_dict': { | |
360 | 'id': '5e14040d-18a4-47c4-a582-43ff602de88e', | |
361 | 'ext': 'mp4', | |
362 | 'title': 'Unlocking The Truth|July 18, 2016|1|101|Trailer', | |
363 | 'description': '"Unlocking the Truth" premieres August 17th at 11/10c.', | |
364 | 'timestamp': 1468846800, | |
365 | 'upload_date': '20160718', | |
366 | }, | |
367 | } | |
368 | ||
369 | def _extract_mgid(self, webpage): | |
370 | return self._search_regex( | |
371 | r'getTheVideo\((["\'])(?P<id>mgid:.+?)\1', webpage, | |
372 | 'mgid', group='id') | |
373 | ||
374 | def _real_extract(self, url): | |
375 | video_id = self._match_id(url) | |
376 | webpage = self._download_webpage(url, video_id) | |
377 | mgid = self._extract_mgid(webpage) | |
378 | return self.url_result('http://media.mtvnservices.com/embed/%s' % mgid) | |
379 | ||
380 | ||
8add4bfe | 381 | class MTVVideoIE(MTVServicesInfoExtractor): |
a54ffb8a | 382 | IE_NAME = 'mtv:video' |
5c541b2c JMF |
383 | _VALID_URL = r'''(?x)^https?:// |
384 | (?:(?:www\.)?mtv\.com/videos/.+?/(?P<videoid>[0-9]+)/[^/]+$| | |
385 | m\.mtv\.com/videos/video\.rbml\?.*?id=(?P<mgid>[^&]+))''' | |
84db8181 JMF |
386 | |
387 | _FEED_URL = 'http://www.mtv.com/player/embed/AS3/rss/' | |
388 | ||
389 | _TESTS = [ | |
390 | { | |
32dac694 | 391 | 'url': 'http://www.mtv.com/videos/misc/853555/ours-vh1-storytellers.jhtml', |
32dac694 PH |
392 | 'md5': '850f3f143316b1e71fa56a4edfd6e0f8', |
393 | 'info_dict': { | |
ca0f500e PH |
394 | 'id': '853555', |
395 | 'ext': 'mp4', | |
32dac694 PH |
396 | 'title': 'Taylor Swift - "Ours (VH1 Storytellers)"', |
397 | 'description': 'Album: Taylor Swift performs "Ours" for VH1 Storytellers at Harvey Mudd College.', | |
712c7530 YCH |
398 | 'timestamp': 1352610000, |
399 | 'upload_date': '20121111', | |
84db8181 JMF |
400 | }, |
401 | }, | |
84db8181 JMF |
402 | ] |
403 | ||
404 | def _get_thumbnail_url(self, uri, itemdoc): | |
405 | return 'http://mtv.mtvnimages.com/uri/' + uri | |
406 | ||
fc287219 PH |
407 | def _real_extract(self, url): |
408 | mobj = re.match(self._VALID_URL, url) | |
fc287219 | 409 | video_id = mobj.group('videoid') |
c801b205 | 410 | uri = mobj.groupdict().get('mgid') |
5c541b2c JMF |
411 | if uri is None: |
412 | webpage = self._download_webpage(url, video_id) | |
5f6a1245 | 413 | |
5c541b2c | 414 | # Some videos come from Vevo.com |
ca0f500e PH |
415 | m_vevo = re.search( |
416 | r'(?s)isVevoVideo = true;.*?vevoVideoId = "(.*?)";', webpage) | |
5c541b2c | 417 | if m_vevo: |
8bcc8756 | 418 | vevo_id = m_vevo.group(1) |
32dac694 | 419 | self.to_screen('Vevo video detected: %s' % vevo_id) |
5c541b2c | 420 | return self.url_result('vevo:%s' % vevo_id, ie='Vevo') |
5f6a1245 | 421 | |
32dac694 | 422 | uri = self._html_search_regex(r'/uri/(.*?)\?', webpage, 'uri') |
f7e02595 | 423 | return self._get_videos_info(uri) |
bc4ba05f JMF |
424 | |
425 | ||
071c1013 PH |
426 | class MTVDEIE(MTVServicesInfoExtractor): |
427 | IE_NAME = 'mtv.de' | |
65488b82 | 428 | _VALID_URL = r'https?://(?:www\.)?mtv\.de/(?:artists|shows|news)/(?:[^/]+/)*(?P<id>\d+)-[^/#?]+/*(?:[#?].*)?$' |
79fa9db0 S |
429 | _TESTS = [{ |
430 | 'url': 'http://www.mtv.de/artists/10571-cro/videos/61131-traum', | |
431 | 'info_dict': { | |
432 | 'id': 'music_video-a50bc5f0b3aa4b3190aa', | |
712c7530 | 433 | 'ext': 'flv', |
79fa9db0 S |
434 | 'title': 'MusicVideo_cro-traum', |
435 | 'description': 'Cro - Traum', | |
071c1013 | 436 | }, |
79fa9db0 S |
437 | 'params': { |
438 | # rtmp download | |
439 | 'skip_download': True, | |
440 | }, | |
35f6e0ff | 441 | 'skip': 'Blocked at Travis CI', |
c3c9f879 S |
442 | }, { |
443 | # mediagen URL without query (e.g. http://videos.mtvnn.com/mediagen/e865da714c166d18d6f80893195fcb97) | |
444 | 'url': 'http://www.mtv.de/shows/933-teen-mom-2/staffeln/5353/folgen/63565-enthullungen', | |
445 | 'info_dict': { | |
446 | 'id': 'local_playlist-f5ae778b9832cc837189', | |
712c7530 | 447 | 'ext': 'flv', |
c3c9f879 S |
448 | 'title': 'Episode_teen-mom-2_shows_season-5_episode-1_full-episode_part1', |
449 | }, | |
450 | 'params': { | |
451 | # rtmp download | |
452 | 'skip_download': True, | |
453 | }, | |
35f6e0ff | 454 | 'skip': 'Blocked at Travis CI', |
65488b82 | 455 | }, { |
65488b82 S |
456 | 'url': 'http://www.mtv.de/news/77491-mtv-movies-spotlight-pixels-teil-3', |
457 | 'info_dict': { | |
458 | 'id': 'local_playlist-4e760566473c4c8c5344', | |
459 | 'ext': 'mp4', | |
460 | 'title': 'Article_mtv-movies-spotlight-pixels-teil-3_short-clips_part1', | |
461 | 'description': 'MTV Movies Supercut', | |
462 | }, | |
463 | 'params': { | |
464 | # rtmp download | |
465 | 'skip_download': True, | |
466 | }, | |
712c7530 | 467 | 'skip': 'Das Video kann zur Zeit nicht abgespielt werden.', |
79fa9db0 | 468 | }] |
071c1013 PH |
469 | |
470 | def _real_extract(self, url): | |
79fa9db0 S |
471 | video_id = self._match_id(url) |
472 | ||
473 | webpage = self._download_webpage(url, video_id) | |
474 | ||
475 | playlist = self._parse_json( | |
476 | self._search_regex( | |
477 | r'window\.pagePlaylist\s*=\s*(\[.+?\]);\n', webpage, 'page playlist'), | |
478 | video_id) | |
071c1013 | 479 | |
712c7530 YCH |
480 | def _mrss_url(item): |
481 | return item['mrss'] + item.get('mrssvars', '') | |
482 | ||
65488b82 S |
483 | # news pages contain single video in playlist with different id |
484 | if len(playlist) == 1: | |
712c7530 | 485 | return self._get_videos_info_from_url(_mrss_url(playlist[0]), video_id) |
65488b82 | 486 | |
071c1013 | 487 | for item in playlist: |
79fa9db0 S |
488 | item_id = item.get('id') |
489 | if item_id and compat_str(item_id) == video_id: | |
712c7530 | 490 | return self._get_videos_info_from_url(_mrss_url(item), video_id) |