]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mtv.py
[cleanup] Upgrade syntax
[yt-dlp.git] / yt_dlp / extractor / mtv.py
CommitLineData
fc287219 1import re
fc287219 2
0af25f78 3from .common import InfoExtractor
1cc79574 4from ..compat import (
e525d9a3 5 compat_str,
1cc79574
PH
6)
7from ..utils import (
fc287219 8 ExtractorError,
90834c78 9 find_xpath_attr,
5aafe895 10 fix_xml_ampersands,
8765151c 11 float_or_none,
0ef68e04 12 HEADRequest,
605b684c 13 int_or_none,
34921b43 14 join_nonempty,
0c75abbb 15 RegexNotFoundError,
5c2266df 16 sanitized_Request,
7cdfc4c9 17 strip_or_none,
712c7530 18 timeconvert,
adf063da 19 try_get,
340b0468 20 unescapeHTML,
0c75abbb 21 update_url_query,
8d9453b9 22 url_basename,
5767b4ee 23 xpath_text,
fc287219
PH
24)
25
90834c78 26
300fcad8
JMF
27def _media_xml_tag(tag):
28 return '{http://search.yahoo.com/mrss/}%s' % tag
fc287219 29
f7e02595 30
0af25f78 31class MTVServicesInfoExtractor(InfoExtractor):
340b0468 32 _MOBILE_TEMPLATE = None
a542e372 33 _LANG = None
8940c1c0 34
f7e02595
JMF
35 @staticmethod
36 def _id_from_uri(uri):
37 return uri.split(':')[-1]
38
0c75abbb
YCH
39 @staticmethod
40 def _remove_template_parameter(url):
41 # Remove the templates, like &device={device}
42 return re.sub(r'&[^=]*?={.*?}(?=(&|$))', '', url)
43
02def271 44 def _get_feed_url(self, uri, url=None):
8940c1c0
JMF
45 return self._FEED_URL
46
ab2f744b 47 def _get_thumbnail_url(self, uri, itemdoc):
84db8181
JMF
48 search_path = '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail'))
49 thumb_node = itemdoc.find(search_path)
50 if thumb_node is None:
51 return None
70bfab0e 52 return thumb_node.get('url') or thumb_node.text or None
f7e02595 53
340b0468
JMF
54 def _extract_mobile_video_formats(self, mtvn_id):
55 webpage_url = self._MOBILE_TEMPLATE % mtvn_id
5c2266df 56 req = sanitized_Request(webpage_url)
340b0468 57 # Otherwise we get a webpage that would execute some javascript
3fcfb8e9 58 req.add_header('User-Agent', 'curl/7')
340b0468 59 webpage = self._download_webpage(req, mtvn_id,
9e1a5b84 60 'Downloading mobile page')
0ef68e04
JMF
61 metrics_url = unescapeHTML(self._search_regex(r'<a href="(http://metrics.+?)"', webpage, 'url'))
62 req = HEADRequest(metrics_url)
63 response = self._request_webpage(req, mtvn_id, 'Resolving url')
64 url = response.geturl()
65 # Transform the url to get the best quality:
66 url = re.sub(r'.+pxE=mp4', 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=mp4', url, 1)
5f6a1245 67 return [{'url': url, 'ext': 'mp4'}]
340b0468 68
dbaf6016 69 def _extract_video_formats(self, mdoc, mtvn_id, video_id):
054d43bb 70 if re.match(r'.*/(error_country_block\.swf|geoblock\.mp4|copyright_error\.flv(?:\?geo\b.+?)?)$', mdoc.find('.//src').text) is not None:
340b0468 71 if mtvn_id is not None and self._MOBILE_TEMPLATE is not None:
0ef68e04 72 self.to_screen('The normal version is not available from your '
9e1a5b84 73 'country, trying with the mobile version')
340b0468 74 return self._extract_mobile_video_formats(mtvn_id)
cc1db7f9 75 raise ExtractorError('This video is not available from your country.',
9e1a5b84 76 expected=True)
f7e02595 77
f13d0933
PH
78 formats = []
79 for rendition in mdoc.findall('.//rendition'):
20faad74 80 if rendition.get('method') == 'hls':
dbaf6016 81 hls_url = rendition.find('./src').text
cdd11c05 82 formats.extend(self._extract_m3u8_formats(
adf063da 83 hls_url, video_id, ext='mp4', entry_protocol='m3u8_native',
e0f1fb0a 84 m3u8_id='hls', fatal=False))
dbaf6016
PH
85 else:
86 # fms
87 try:
88 _, _, ext = rendition.attrib['type'].partition('/')
89 rtmp_video_url = rendition.find('./src').text
adf063da
S
90 if 'error_not_available.swf' in rtmp_video_url:
91 raise ExtractorError(
92 '%s said: video is not available' % self.IE_NAME,
93 expected=True)
dbaf6016
PH
94 if rtmp_video_url.endswith('siteunavail.png'):
95 continue
dbaf6016 96 formats.extend([{
adf063da
S
97 'ext': 'flv' if rtmp_video_url.startswith('rtmp') else ext,
98 'url': rtmp_video_url,
34921b43 99 'format_id': join_nonempty(
adf063da 100 'rtmp' if rtmp_video_url.startswith('rtmp') else None,
34921b43 101 rendition.get('bitrate')),
dbaf6016
PH
102 'width': int(rendition.get('width')),
103 'height': int(rendition.get('height')),
adf063da 104 }])
dbaf6016
PH
105 except (KeyError, TypeError):
106 raise ExtractorError('Invalid rendition field.')
e0f1fb0a
S
107 if formats:
108 self._sort_formats(formats)
f13d0933 109 return formats
f7e02595 110
e525d9a3
S
111 def _extract_subtitles(self, mdoc, mtvn_id):
112 subtitles = {}
e525d9a3
S
113 for transcript in mdoc.findall('.//transcript'):
114 if transcript.get('kind') != 'captions':
115 continue
116 lang = transcript.get('srclang')
5ea765fb
RA
117 for typographic in transcript.findall('./typographic'):
118 sub_src = typographic.get('src')
119 if not sub_src:
120 continue
121 ext = typographic.get('format')
122 if ext == 'cea-608':
123 ext = 'scc'
124 subtitles.setdefault(lang, []).append({
125 'url': compat_str(sub_src),
126 'ext': ext
127 })
0af25f78 128 return subtitles
e525d9a3 129
67fc365b 130 def _get_video_info(self, itemdoc, use_hls=True):
f7e02595
JMF
131 uri = itemdoc.find('guid').text
132 video_id = self._id_from_uri(uri)
133 self.report_extraction(video_id)
04cbc498 134 content_el = itemdoc.find('%s/%s' % (_media_xml_tag('group'), _media_xml_tag('content')))
0c75abbb 135 mediagen_url = self._remove_template_parameter(content_el.attrib['url'])
dbaf6016 136 mediagen_url = mediagen_url.replace('device={device}', '')
f7e02595 137 if 'acceptMethods' not in mediagen_url:
56f447be 138 mediagen_url += '&' if '?' in mediagen_url else '?'
dbaf6016
PH
139 mediagen_url += 'acceptMethods='
140 mediagen_url += 'hls' if use_hls else 'fms'
6562df76 141
e0f1fb0a
S
142 mediagen_doc = self._download_xml(
143 mediagen_url, video_id, 'Downloading video urls', fatal=False)
144
145 if mediagen_doc is False:
146 return None
f7e02595 147
0dfe9bc9
S
148 item = mediagen_doc.find('./video/item')
149 if item is not None and item.get('type') == 'text':
150 message = '%s returned error: ' % self.IE_NAME
151 if item.get('code') is not None:
152 message += '%s - ' % item.get('code')
153 message += item.text
154 raise ExtractorError(message, expected=True)
155
7cdfc4c9 156 description = strip_or_none(xpath_text(itemdoc, 'description'))
f13d0933 157
712c7530
YCH
158 timestamp = timeconvert(xpath_text(itemdoc, 'pubDate'))
159
90834c78
PH
160 title_el = None
161 if title_el is None:
162 title_el = find_xpath_attr(
163 itemdoc, './/{http://search.yahoo.com/mrss/}category',
164 'scheme', 'urn:mtvn:video_title')
90834c78 165 if title_el is None:
f9934b96 166 title_el = itemdoc.find('.//{http://search.yahoo.com/mrss/}title')
96cb10a5 167 if title_el is None:
f9934b96 168 title_el = itemdoc.find('.//title')
1df4229b
PH
169 if title_el.text is None:
170 title_el = None
1df4229b 171
90834c78
PH
172 title = title_el.text
173 if title is None:
174 raise ExtractorError('Could not find video title')
780ee4e5 175 title = title.strip()
90834c78 176
605b684c 177 series = find_xpath_attr(
178 itemdoc, './/{http://search.yahoo.com/mrss/}category',
179 'scheme', 'urn:mtvn:franchise')
180 season = find_xpath_attr(
181 itemdoc, './/{http://search.yahoo.com/mrss/}category',
182 'scheme', 'urn:mtvn:seasonN')
183 episode = find_xpath_attr(
184 itemdoc, './/{http://search.yahoo.com/mrss/}category',
185 'scheme', 'urn:mtvn:episodeN')
186 series = series.text if series is not None else None
187 season = season.text if season is not None else None
188 episode = episode.text if episode is not None else None
189 if season and episode:
190 # episode number includes season, so remove it
191 episode = re.sub(r'^%s' % season, '', episode)
192
340b0468
JMF
193 # This a short id that's used in the webpage urls
194 mtvn_id = None
195 mtvn_id_node = find_xpath_attr(itemdoc, './/{http://search.yahoo.com/mrss/}category',
9e1a5b84 196 'scheme', 'urn:mtvn:id')
340b0468
JMF
197 if mtvn_id_node is not None:
198 mtvn_id = mtvn_id_node.text
199
dbaf6016
PH
200 formats = self._extract_video_formats(mediagen_doc, mtvn_id, video_id)
201
e0f1fb0a
S
202 # Some parts of complete video may be missing (e.g. missing Act 3 in
203 # http://www.southpark.de/alle-episoden/s14e01-sexual-healing)
204 if not formats:
205 return None
206
207 self._sort_formats(formats)
208
fb7abb31 209 return {
90834c78 210 'title': title,
dbaf6016 211 'formats': formats,
e525d9a3 212 'subtitles': self._extract_subtitles(mediagen_doc, mtvn_id),
f13d0933
PH
213 'id': video_id,
214 'thumbnail': self._get_thumbnail_url(uri, itemdoc),
215 'description': description,
04cbc498 216 'duration': float_or_none(content_el.attrib.get('duration')),
712c7530 217 'timestamp': timestamp,
605b684c 218 'series': series,
219 'season_number': int_or_none(season),
220 'episode_number': int_or_none(episode),
f13d0933
PH
221 }
222
c1e90619 223 def _get_feed_query(self, uri):
224 data = {'uri': uri}
225 if self._LANG:
226 data['lang'] = self._LANG
0c75abbb 227 return data
c1e90619 228
02def271 229 def _get_videos_info(self, uri, use_hls=True, url=None):
f7e02595 230 video_id = self._id_from_uri(uri)
02def271 231 feed_url = self._get_feed_url(uri, url)
0c75abbb 232 info_url = update_url_query(feed_url, self._get_feed_query(uri))
dbaf6016 233 return self._get_videos_info_from_url(info_url, video_id, use_hls)
79fa9db0 234
67fc365b 235 def _get_videos_info_from_url(self, url, video_id, use_hls=True):
e2b38da9 236 idoc = self._download_xml(
79fa9db0 237 url, video_id,
32dac694 238 'Downloading info', transform_source=fix_xml_ampersands)
712c7530
YCH
239
240 title = xpath_text(idoc, './channel/title')
241 description = xpath_text(idoc, './channel/description')
242
e0f1fb0a
S
243 entries = []
244 for item in idoc.findall('.//item'):
245 info = self._get_video_info(item, use_hls)
246 if info:
247 entries.append(info)
248
bc97cdae 249 # TODO: should be multi-video
5239075b 250 return self.playlist_result(
e0f1fb0a 251 entries, playlist_title=title, playlist_description=description)
fc287219 252
adf063da
S
253 def _extract_triforce_mgid(self, webpage, data_zone=None, video_id=None):
254 triforce_feed = self._parse_json(self._search_regex(
f1e70fc2 255 r'triforceManifestFeed\s*=\s*({.+?})\s*;\s*\n', webpage,
adf063da
S
256 'triforce feed', default='{}'), video_id, fatal=False)
257
258 data_zone = self._search_regex(
259 r'data-zone=(["\'])(?P<zone>.+?_lc_promo.*?)\1', webpage,
260 'data zone', default=data_zone, group='zone')
261
262 feed_url = try_get(
263 triforce_feed, lambda x: x['manifest']['zones'][data_zone]['feed'],
264 compat_str)
265 if not feed_url:
266 return
267
268 feed = self._download_json(feed_url, video_id, fatal=False)
269 if not feed:
270 return
271
272 return try_get(feed, lambda x: x['result']['data']['id'], compat_str)
273
a820dc72
RA
274 @staticmethod
275 def _extract_child_with_type(parent, t):
f7ad7160 276 for c in parent['children']:
277 if c.get('type') == t:
278 return c
a820dc72 279
ee1e0558 280 def _extract_mgid(self, webpage):
8d9453b9 281 try:
4bbf139a
JMF
282 # the url can be http://media.mtvnservices.com/fb/{mgid}.swf
283 # or http://media.mtvnservices.com/{mgid}
284 og_url = self._og_search_video_url(webpage)
285 mgid = url_basename(og_url)
286 if mgid.endswith('.swf'):
287 mgid = mgid[:-4]
8d9453b9 288 except RegexNotFoundError:
b1298d8e
AMW
289 mgid = None
290
291 if mgid is None or ':' not in mgid:
b9381e43 292 mgid = self._search_regex(
197224b7 293 [r'data-mgid="(.*?)"', r'swfobject\.embedSWF\(".*?(mgid:.*?)"'],
fc42bc6e
S
294 webpage, 'mgid', default=None)
295
296 if not mgid:
297 sm4_embed = self._html_search_meta(
298 'sm4:video:embed', webpage, 'sm4 embed', default='')
299 mgid = self._search_regex(
adf063da
S
300 r'embed/(mgid:.+?)["\'&?/]', sm4_embed, 'mgid', default=None)
301
b6e0c7d2 302 if not mgid:
ee1e0558 303 mgid = self._extract_triforce_mgid(webpage)
adf063da 304
a820dc72
RA
305 if not mgid:
306 data = self._parse_json(self._search_regex(
307 r'__DATA__\s*=\s*({.+?});', webpage, 'data'), None)
308 main_container = self._extract_child_with_type(data, 'MainContainer')
f7ad7160 309 ab_testing = self._extract_child_with_type(main_container, 'ABTesting')
310 video_player = self._extract_child_with_type(ab_testing or main_container, 'VideoPlayer')
fec41d17
S
311 if video_player:
312 mgid = try_get(video_player, lambda x: x['props']['media']['video']['config']['uri'])
313 else:
314 flex_wrapper = self._extract_child_with_type(ab_testing or main_container, 'FlexWrapper')
315 auth_suite_wrapper = self._extract_child_with_type(flex_wrapper, 'AuthSuiteWrapper')
316 player = self._extract_child_with_type(auth_suite_wrapper or flex_wrapper, 'Player')
317 if player:
318 mgid = try_get(player, lambda x: x['props']['videoDetail']['mgid'])
319
320 if not mgid:
321 raise ExtractorError('Could not extract mgid')
a820dc72 322
c1e90619 323 return mgid
e525d9a3 324
c1e90619 325 def _real_extract(self, url):
326 title = url_basename(url)
327 webpage = self._download_webpage(url, title)
ee1e0558 328 mgid = self._extract_mgid(webpage)
02def271 329 videos_info = self._get_videos_info(mgid, url=url)
e525d9a3 330 return videos_info
8d9453b9 331
84db8181 332
8940c1c0
JMF
333class MTVServicesEmbeddedIE(MTVServicesInfoExtractor):
334 IE_NAME = 'mtvservices:embedded'
335 _VALID_URL = r'https?://media\.mtvnservices\.com/embed/(?P<mgid>.+?)(\?|/|$)'
336
337 _TEST = {
338 # From http://www.thewrap.com/peter-dinklage-sums-up-game-of-thrones-in-45-seconds-video/
339 'url': 'http://media.mtvnservices.com/embed/mgid:uma:video:mtv.com:1043906/cp~vid%3D1043906%26uri%3Dmgid%3Auma%3Avideo%3Amtv.com%3A1043906',
340 'md5': 'cb349b21a7897164cede95bd7bf3fbb9',
341 'info_dict': {
342 'id': '1043906',
343 'ext': 'mp4',
344 'title': 'Peter Dinklage Sums Up \'Game Of Thrones\' In 45 Seconds',
345 '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
346 'timestamp': 1400126400,
347 'upload_date': '20140515',
8940c1c0
JMF
348 },
349 }
350
fe1d858e
S
351 @staticmethod
352 def _extract_url(webpage):
353 mobj = re.search(
1418a043 354 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//media\.mtvnservices\.com/embed/.+?)\1', webpage)
fe1d858e
S
355 if mobj:
356 return mobj.group('url')
357
02def271 358 def _get_feed_url(self, uri, url=None):
8940c1c0 359 video_id = self._id_from_uri(uri)
0c75abbb
YCH
360 config = self._download_json(
361 'http://media.mtvnservices.com/pmt/e1/access/index.html?uri=%s&configtype=edge' % uri, video_id)
362 return self._remove_template_parameter(config['feedWithQueryParams'])
8940c1c0
JMF
363
364 def _real_extract(self, url):
5ad28e7f 365 mobj = self._match_valid_url(url)
8940c1c0
JMF
366 mgid = mobj.group('mgid')
367 return self._get_videos_info(mgid)
368
369
84db8181 370class MTVIE(MTVServicesInfoExtractor):
a54ffb8a 371 IE_NAME = 'mtv'
cf0cabbe 372 _VALID_URL = r'https?://(?:www\.)?mtv\.com/(?:video-clips|(?:full-)?episodes)/(?P<id>[^/?#.]+)'
8add4bfe
RA
373 _FEED_URL = 'http://www.mtv.com/feeds/mrss/'
374
375 _TESTS = [{
376 'url': 'http://www.mtv.com/video-clips/vl8qof/unlocking-the-truth-trailer',
377 'md5': '1edbcdf1e7628e414a8c5dcebca3d32b',
378 'info_dict': {
379 'id': '5e14040d-18a4-47c4-a582-43ff602de88e',
380 'ext': 'mp4',
381 'title': 'Unlocking The Truth|July 18, 2016|1|101|Trailer',
382 'description': '"Unlocking the Truth" premieres August 17th at 11/10c.',
383 'timestamp': 1468846800,
384 'upload_date': '20160718',
385 },
386 }, {
387 'url': 'http://www.mtv.com/full-episodes/94tujl/unlocking-the-truth-gates-of-hell-season-1-ep-101',
388 'only_matching': True,
cf0cabbe
S
389 }, {
390 'url': 'http://www.mtv.com/episodes/g8xu7q/teen-mom-2-breaking-the-wall-season-7-ep-713',
391 'only_matching': True,
8add4bfe
RA
392 }]
393
394
3cdcebf5
RA
395class MTVJapanIE(MTVServicesInfoExtractor):
396 IE_NAME = 'mtvjapan'
397 _VALID_URL = r'https?://(?:www\.)?mtvjapan\.com/videos/(?P<id>[0-9a-z]+)'
008f2470
S
398
399 _TEST = {
3cdcebf5 400 'url': 'http://www.mtvjapan.com/videos/prayht/fresh-info-cadillac-escalade',
008f2470 401 'info_dict': {
3cdcebf5 402 'id': 'bc01da03-6fe5-4284-8880-f291f4e368f5',
008f2470 403 'ext': 'mp4',
3cdcebf5
RA
404 'title': '【Fresh Info】Cadillac ESCALADE Sport Edition',
405 },
406 'params': {
407 'skip_download': True,
008f2470
S
408 },
409 }
3cdcebf5
RA
410 _GEO_COUNTRIES = ['JP']
411 _FEED_URL = 'http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed'
008f2470 412
3cdcebf5
RA
413 def _get_feed_query(self, uri):
414 return {
415 'arcEp': 'mtvjapan.com',
416 'mgid': uri,
417 }
008f2470
S
418
419
8add4bfe 420class MTVVideoIE(MTVServicesInfoExtractor):
a54ffb8a 421 IE_NAME = 'mtv:video'
5c541b2c
JMF
422 _VALID_URL = r'''(?x)^https?://
423 (?:(?:www\.)?mtv\.com/videos/.+?/(?P<videoid>[0-9]+)/[^/]+$|
424 m\.mtv\.com/videos/video\.rbml\?.*?id=(?P<mgid>[^&]+))'''
84db8181
JMF
425
426 _FEED_URL = 'http://www.mtv.com/player/embed/AS3/rss/'
427
428 _TESTS = [
429 {
32dac694 430 'url': 'http://www.mtv.com/videos/misc/853555/ours-vh1-storytellers.jhtml',
32dac694
PH
431 'md5': '850f3f143316b1e71fa56a4edfd6e0f8',
432 'info_dict': {
ca0f500e
PH
433 'id': '853555',
434 'ext': 'mp4',
32dac694
PH
435 'title': 'Taylor Swift - "Ours (VH1 Storytellers)"',
436 'description': 'Album: Taylor Swift performs "Ours" for VH1 Storytellers at Harvey Mudd College.',
712c7530
YCH
437 'timestamp': 1352610000,
438 'upload_date': '20121111',
84db8181
JMF
439 },
440 },
84db8181
JMF
441 ]
442
443 def _get_thumbnail_url(self, uri, itemdoc):
444 return 'http://mtv.mtvnimages.com/uri/' + uri
445
fc287219 446 def _real_extract(self, url):
5ad28e7f 447 mobj = self._match_valid_url(url)
fc287219 448 video_id = mobj.group('videoid')
c801b205 449 uri = mobj.groupdict().get('mgid')
5c541b2c
JMF
450 if uri is None:
451 webpage = self._download_webpage(url, video_id)
5f6a1245 452
5c541b2c 453 # Some videos come from Vevo.com
ca0f500e
PH
454 m_vevo = re.search(
455 r'(?s)isVevoVideo = true;.*?vevoVideoId = "(.*?)";', webpage)
5c541b2c 456 if m_vevo:
8bcc8756 457 vevo_id = m_vevo.group(1)
32dac694 458 self.to_screen('Vevo video detected: %s' % vevo_id)
5c541b2c 459 return self.url_result('vevo:%s' % vevo_id, ie='Vevo')
5f6a1245 460
32dac694 461 uri = self._html_search_regex(r'/uri/(.*?)\?', webpage, 'uri')
f7e02595 462 return self._get_videos_info(uri)
bc4ba05f
JMF
463
464
071c1013
PH
465class MTVDEIE(MTVServicesInfoExtractor):
466 IE_NAME = 'mtv.de'
cfabc505 467 _VALID_URL = r'https?://(?:www\.)?mtv\.de/(?:musik/videoclips|folgen|news)/(?P<id>[0-9a-z]+)'
79fa9db0 468 _TESTS = [{
cfabc505 469 'url': 'http://www.mtv.de/musik/videoclips/2gpnv7/Traum',
79fa9db0 470 'info_dict': {
cfabc505
RA
471 'id': 'd5d472bc-f5b7-11e5-bffd-a4badb20dab5',
472 'ext': 'mp4',
473 'title': 'Traum',
474 'description': 'Traum',
071c1013 475 },
79fa9db0
S
476 'params': {
477 # rtmp download
478 'skip_download': True,
479 },
35f6e0ff 480 'skip': 'Blocked at Travis CI',
c3c9f879
S
481 }, {
482 # mediagen URL without query (e.g. http://videos.mtvnn.com/mediagen/e865da714c166d18d6f80893195fcb97)
cfabc505 483 'url': 'http://www.mtv.de/folgen/6b1ylu/teen-mom-2-enthuellungen-S5-F1',
c3c9f879 484 'info_dict': {
cfabc505
RA
485 'id': '1e5a878b-31c5-11e7-a442-0e40cf2fc285',
486 'ext': 'mp4',
487 'title': 'Teen Mom 2',
488 'description': 'md5:dc65e357ef7e1085ed53e9e9d83146a7',
c3c9f879
S
489 },
490 'params': {
491 # rtmp download
492 'skip_download': True,
493 },
35f6e0ff 494 'skip': 'Blocked at Travis CI',
65488b82 495 }, {
cfabc505 496 'url': 'http://www.mtv.de/news/glolix/77491-mtv-movies-spotlight--pixels--teil-3',
65488b82
S
497 'info_dict': {
498 'id': 'local_playlist-4e760566473c4c8c5344',
499 'ext': 'mp4',
500 'title': 'Article_mtv-movies-spotlight-pixels-teil-3_short-clips_part1',
501 'description': 'MTV Movies Supercut',
502 },
503 'params': {
504 # rtmp download
505 'skip_download': True,
506 },
712c7530 507 'skip': 'Das Video kann zur Zeit nicht abgespielt werden.',
79fa9db0 508 }]
cfabc505
RA
509 _GEO_COUNTRIES = ['DE']
510 _FEED_URL = 'http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed'
071c1013 511
cfabc505
RA
512 def _get_feed_query(self, uri):
513 return {
514 'arcEp': 'mtv.de',
515 'mgid': uri,
516 }
605b684c 517
518
519class MTVItaliaIE(MTVServicesInfoExtractor):
520 IE_NAME = 'mtv.it'
521 _VALID_URL = r'https?://(?:www\.)?mtv\.it/(?:episodi|video|musica)/(?P<id>[0-9a-z]+)'
522 _TESTS = [{
523 'url': 'http://www.mtv.it/episodi/24bqab/mario-una-serie-di-maccio-capatonda-cavoli-amario-episodio-completo-S1-E1',
524 'info_dict': {
525 'id': '0f0fc78e-45fc-4cce-8f24-971c25477530',
526 'ext': 'mp4',
527 'title': 'Cavoli amario (episodio completo)',
528 'description': 'md5:4962bccea8fed5b7c03b295ae1340660',
529 'series': 'Mario - Una Serie Di Maccio Capatonda',
530 'season_number': 1,
531 'episode_number': 1,
532 },
533 'params': {
534 'skip_download': True,
535 },
536 }]
537 _GEO_COUNTRIES = ['IT']
538 _FEED_URL = 'http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed'
539
540 def _get_feed_query(self, uri):
541 return {
542 'arcEp': 'mtv.it',
543 'mgid': uri,
544 }
545
546
547class MTVItaliaProgrammaIE(MTVItaliaIE):
548 IE_NAME = 'mtv.it:programma'
549 _VALID_URL = r'https?://(?:www\.)?mtv\.it/(?:programmi|playlist)/(?P<id>[0-9a-z]+)'
550 _TESTS = [{
551 # program page: general
552 'url': 'http://www.mtv.it/programmi/s2rppv/mario-una-serie-di-maccio-capatonda',
553 'info_dict': {
554 'id': 'a6f155bc-8220-4640-aa43-9b95f64ffa3d',
555 'title': 'Mario - Una Serie Di Maccio Capatonda',
556 'description': 'md5:72fbffe1f77ccf4e90757dd4e3216153',
557 },
558 'playlist_count': 2,
559 'params': {
560 'skip_download': True,
561 },
562 }, {
563 # program page: specific season
564 'url': 'http://www.mtv.it/programmi/d9ncjf/mario-una-serie-di-maccio-capatonda-S2',
565 'info_dict': {
566 'id': '4deeb5d8-f272-490c-bde2-ff8d261c6dd1',
567 'title': 'Mario - Una Serie Di Maccio Capatonda - Stagione 2',
568 },
569 'playlist_count': 34,
570 'params': {
571 'skip_download': True,
572 },
573 }, {
574 # playlist page + redirect
575 'url': 'http://www.mtv.it/playlist/sexy-videos/ilctal',
576 'info_dict': {
577 'id': 'dee8f9ee-756d-493b-bf37-16d1d2783359',
578 'title': 'Sexy Videos',
579 },
580 'playlist_mincount': 145,
581 'params': {
582 'skip_download': True,
583 },
584 }]
585 _GEO_COUNTRIES = ['IT']
586 _FEED_URL = 'http://www.mtv.it/feeds/triforce/manifest/v8'
587
588 def _get_entries(self, title, url):
589 while True:
590 pg = self._search_regex(r'/(\d+)$', url, 'entries', '1')
591 entries = self._download_json(url, title, 'page %s' % pg)
592 url = try_get(
593 entries, lambda x: x['result']['nextPageURL'], compat_str)
594 entries = try_get(
595 entries, (
596 lambda x: x['result']['data']['items'],
597 lambda x: x['result']['data']['seasons']),
598 list)
599 for entry in entries or []:
600 if entry.get('canonicalURL'):
601 yield self.url_result(entry['canonicalURL'])
602 if not url:
603 break
604
605 def _real_extract(self, url):
606 query = {'url': url}
607 info_url = update_url_query(self._FEED_URL, query)
608 video_id = self._match_id(url)
609 info = self._download_json(info_url, video_id).get('manifest')
610
611 redirect = try_get(
612 info, lambda x: x['newLocation']['url'], compat_str)
613 if redirect:
614 return self.url_result(redirect)
615
616 title = info.get('title')
617 video_id = try_get(
618 info, lambda x: x['reporting']['itemId'], compat_str)
619 parent_id = try_get(
620 info, lambda x: x['reporting']['parentId'], compat_str)
621
622 playlist_url = current_url = None
623 for z in (info.get('zones') or {}).values():
624 if z.get('moduleName') in ('INTL_M304', 'INTL_M209'):
625 info_url = z.get('feed')
626 if z.get('moduleName') in ('INTL_M308', 'INTL_M317'):
627 playlist_url = playlist_url or z.get('feed')
628 if z.get('moduleName') in ('INTL_M300',):
629 current_url = current_url or z.get('feed')
630
631 if not info_url:
632 raise ExtractorError('No info found')
633
634 if video_id == parent_id:
635 video_id = self._search_regex(
636 r'([^\/]+)/[^\/]+$', info_url, 'video_id')
637
638 info = self._download_json(info_url, video_id, 'Show infos')
639 info = try_get(info, lambda x: x['result']['data'], dict)
640 title = title or try_get(
641 info, (
642 lambda x: x['title'],
643 lambda x: x['headline']),
644 compat_str)
645 description = try_get(info, lambda x: x['content'], compat_str)
646
647 if current_url:
648 season = try_get(
649 self._download_json(playlist_url, video_id, 'Seasons info'),
650 lambda x: x['result']['data'], dict)
651 current = try_get(
652 season, lambda x: x['currentSeason'], compat_str)
653 seasons = try_get(
654 season, lambda x: x['seasons'], list) or []
655
656 if current in [s.get('eTitle') for s in seasons]:
657 playlist_url = current_url
658
659 title = re.sub(
660 r'[-|]\s*(?:mtv\s*italia|programma|playlist)',
661 '', title, flags=re.IGNORECASE).strip()
662
663 return self.playlist_result(
664 self._get_entries(title, playlist_url),
665 video_id, title, description)