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