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