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