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