You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
18 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_xpath,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. find_xpath_attr,
  11. fix_xml_ampersands,
  12. float_or_none,
  13. HEADRequest,
  14. RegexNotFoundError,
  15. sanitized_Request,
  16. strip_or_none,
  17. timeconvert,
  18. try_get,
  19. unescapeHTML,
  20. update_url_query,
  21. url_basename,
  22. xpath_text,
  23. )
  24. def _media_xml_tag(tag):
  25. return '{http://search.yahoo.com/mrss/}%s' % tag
  26. class MTVServicesInfoExtractor(InfoExtractor):
  27. _MOBILE_TEMPLATE = None
  28. _LANG = None
  29. @staticmethod
  30. def _id_from_uri(uri):
  31. return uri.split(':')[-1]
  32. @staticmethod
  33. def _remove_template_parameter(url):
  34. # Remove the templates, like &device={device}
  35. return re.sub(r'&[^=]*?={.*?}(?=(&|$))', '', url)
  36. def _get_feed_url(self, uri):
  37. return self._FEED_URL
  38. def _get_thumbnail_url(self, uri, itemdoc):
  39. search_path = '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail'))
  40. thumb_node = itemdoc.find(search_path)
  41. if thumb_node is None:
  42. return None
  43. return thumb_node.get('url') or thumb_node.text or None
  44. def _extract_mobile_video_formats(self, mtvn_id):
  45. webpage_url = self._MOBILE_TEMPLATE % mtvn_id
  46. req = sanitized_Request(webpage_url)
  47. # Otherwise we get a webpage that would execute some javascript
  48. req.add_header('User-Agent', 'curl/7')
  49. webpage = self._download_webpage(req, mtvn_id,
  50. 'Downloading mobile page')
  51. metrics_url = unescapeHTML(self._search_regex(r'<a href="(http://metrics.+?)"', webpage, 'url'))
  52. req = HEADRequest(metrics_url)
  53. response = self._request_webpage(req, mtvn_id, 'Resolving url')
  54. url = response.geturl()
  55. # Transform the url to get the best quality:
  56. url = re.sub(r'.+pxE=mp4', 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=mp4', url, 1)
  57. return [{'url': url, 'ext': 'mp4'}]
  58. def _extract_video_formats(self, mdoc, mtvn_id, video_id):
  59. if re.match(r'.*/(error_country_block\.swf|geoblock\.mp4|copyright_error\.flv(?:\?geo\b.+?)?)$', mdoc.find('.//src').text) is not None:
  60. if mtvn_id is not None and self._MOBILE_TEMPLATE is not None:
  61. self.to_screen('The normal version is not available from your '
  62. 'country, trying with the mobile version')
  63. return self._extract_mobile_video_formats(mtvn_id)
  64. raise ExtractorError('This video is not available from your country.',
  65. expected=True)
  66. formats = []
  67. for rendition in mdoc.findall('.//rendition'):
  68. if rendition.get('method') == 'hls':
  69. hls_url = rendition.find('./src').text
  70. formats.extend(self._extract_m3u8_formats(
  71. hls_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  72. m3u8_id='hls', fatal=False))
  73. else:
  74. # fms
  75. try:
  76. _, _, ext = rendition.attrib['type'].partition('/')
  77. rtmp_video_url = rendition.find('./src').text
  78. if 'error_not_available.swf' in rtmp_video_url:
  79. raise ExtractorError(
  80. '%s said: video is not available' % self.IE_NAME,
  81. expected=True)
  82. if rtmp_video_url.endswith('siteunavail.png'):
  83. continue
  84. formats.extend([{
  85. 'ext': 'flv' if rtmp_video_url.startswith('rtmp') else ext,
  86. 'url': rtmp_video_url,
  87. 'format_id': '-'.join(filter(None, [
  88. 'rtmp' if rtmp_video_url.startswith('rtmp') else None,
  89. rendition.get('bitrate')])),
  90. 'width': int(rendition.get('width')),
  91. 'height': int(rendition.get('height')),
  92. }])
  93. except (KeyError, TypeError):
  94. raise ExtractorError('Invalid rendition field.')
  95. if formats:
  96. self._sort_formats(formats)
  97. return formats
  98. def _extract_subtitles(self, mdoc, mtvn_id):
  99. subtitles = {}
  100. for transcript in mdoc.findall('.//transcript'):
  101. if transcript.get('kind') != 'captions':
  102. continue
  103. lang = transcript.get('srclang')
  104. for typographic in transcript.findall('./typographic'):
  105. sub_src = typographic.get('src')
  106. if not sub_src:
  107. continue
  108. ext = typographic.get('format')
  109. if ext == 'cea-608':
  110. ext = 'scc'
  111. subtitles.setdefault(lang, []).append({
  112. 'url': compat_str(sub_src),
  113. 'ext': ext
  114. })
  115. return subtitles
  116. def _get_video_info(self, itemdoc, use_hls=True):
  117. uri = itemdoc.find('guid').text
  118. video_id = self._id_from_uri(uri)
  119. self.report_extraction(video_id)
  120. content_el = itemdoc.find('%s/%s' % (_media_xml_tag('group'), _media_xml_tag('content')))
  121. mediagen_url = self._remove_template_parameter(content_el.attrib['url'])
  122. mediagen_url = mediagen_url.replace('device={device}', '')
  123. if 'acceptMethods' not in mediagen_url:
  124. mediagen_url += '&' if '?' in mediagen_url else '?'
  125. mediagen_url += 'acceptMethods='
  126. mediagen_url += 'hls' if use_hls else 'fms'
  127. mediagen_doc = self._download_xml(
  128. mediagen_url, video_id, 'Downloading video urls', fatal=False)
  129. if mediagen_doc is False:
  130. return None
  131. item = mediagen_doc.find('./video/item')
  132. if item is not None and item.get('type') == 'text':
  133. message = '%s returned error: ' % self.IE_NAME
  134. if item.get('code') is not None:
  135. message += '%s - ' % item.get('code')
  136. message += item.text
  137. raise ExtractorError(message, expected=True)
  138. description = strip_or_none(xpath_text(itemdoc, 'description'))
  139. timestamp = timeconvert(xpath_text(itemdoc, 'pubDate'))
  140. title_el = None
  141. if title_el is None:
  142. title_el = find_xpath_attr(
  143. itemdoc, './/{http://search.yahoo.com/mrss/}category',
  144. 'scheme', 'urn:mtvn:video_title')
  145. if title_el is None:
  146. title_el = itemdoc.find(compat_xpath('.//{http://search.yahoo.com/mrss/}title'))
  147. if title_el is None:
  148. title_el = itemdoc.find(compat_xpath('.//title'))
  149. if title_el.text is None:
  150. title_el = None
  151. title = title_el.text
  152. if title is None:
  153. raise ExtractorError('Could not find video title')
  154. title = title.strip()
  155. # This a short id that's used in the webpage urls
  156. mtvn_id = None
  157. mtvn_id_node = find_xpath_attr(itemdoc, './/{http://search.yahoo.com/mrss/}category',
  158. 'scheme', 'urn:mtvn:id')
  159. if mtvn_id_node is not None:
  160. mtvn_id = mtvn_id_node.text
  161. formats = self._extract_video_formats(mediagen_doc, mtvn_id, video_id)
  162. # Some parts of complete video may be missing (e.g. missing Act 3 in
  163. # http://www.southpark.de/alle-episoden/s14e01-sexual-healing)
  164. if not formats:
  165. return None
  166. self._sort_formats(formats)
  167. return {
  168. 'title': title,
  169. 'formats': formats,
  170. 'subtitles': self._extract_subtitles(mediagen_doc, mtvn_id),
  171. 'id': video_id,
  172. 'thumbnail': self._get_thumbnail_url(uri, itemdoc),
  173. 'description': description,
  174. 'duration': float_or_none(content_el.attrib.get('duration')),
  175. 'timestamp': timestamp,
  176. }
  177. def _get_feed_query(self, uri):
  178. data = {'uri': uri}
  179. if self._LANG:
  180. data['lang'] = self._LANG
  181. return data
  182. def _get_videos_info(self, uri, use_hls=True):
  183. video_id = self._id_from_uri(uri)
  184. feed_url = self._get_feed_url(uri)
  185. info_url = update_url_query(feed_url, self._get_feed_query(uri))
  186. return self._get_videos_info_from_url(info_url, video_id, use_hls)
  187. def _get_videos_info_from_url(self, url, video_id, use_hls=True):
  188. idoc = self._download_xml(
  189. url, video_id,
  190. 'Downloading info', transform_source=fix_xml_ampersands)
  191. title = xpath_text(idoc, './channel/title')
  192. description = xpath_text(idoc, './channel/description')
  193. entries = []
  194. for item in idoc.findall('.//item'):
  195. info = self._get_video_info(item, use_hls)
  196. if info:
  197. entries.append(info)
  198. return self.playlist_result(
  199. entries, playlist_title=title, playlist_description=description)
  200. def _extract_triforce_mgid(self, webpage, data_zone=None, video_id=None):
  201. triforce_feed = self._parse_json(self._search_regex(
  202. r'triforceManifestFeed\s*=\s*({.+?})\s*;\s*\n', webpage,
  203. 'triforce feed', default='{}'), video_id, fatal=False)
  204. data_zone = self._search_regex(
  205. r'data-zone=(["\'])(?P<zone>.+?_lc_promo.*?)\1', webpage,
  206. 'data zone', default=data_zone, group='zone')
  207. feed_url = try_get(
  208. triforce_feed, lambda x: x['manifest']['zones'][data_zone]['feed'],
  209. compat_str)
  210. if not feed_url:
  211. return
  212. feed = self._download_json(feed_url, video_id, fatal=False)
  213. if not feed:
  214. return
  215. return try_get(feed, lambda x: x['result']['data']['id'], compat_str)
  216. def _extract_mgid(self, webpage):
  217. try:
  218. # the url can be http://media.mtvnservices.com/fb/{mgid}.swf
  219. # or http://media.mtvnservices.com/{mgid}
  220. og_url = self._og_search_video_url(webpage)
  221. mgid = url_basename(og_url)
  222. if mgid.endswith('.swf'):
  223. mgid = mgid[:-4]
  224. except RegexNotFoundError:
  225. mgid = None
  226. if mgid is None or ':' not in mgid:
  227. mgid = self._search_regex(
  228. [r'data-mgid="(.*?)"', r'swfobject\.embedSWF\(".*?(mgid:.*?)"'],
  229. webpage, 'mgid', default=None)
  230. if not mgid:
  231. sm4_embed = self._html_search_meta(
  232. 'sm4:video:embed', webpage, 'sm4 embed', default='')
  233. mgid = self._search_regex(
  234. r'embed/(mgid:.+?)["\'&?/]', sm4_embed, 'mgid', default=None)
  235. if not mgid:
  236. mgid = self._extract_triforce_mgid(webpage)
  237. return mgid
  238. def _real_extract(self, url):
  239. title = url_basename(url)
  240. webpage = self._download_webpage(url, title)
  241. mgid = self._extract_mgid(webpage)
  242. videos_info = self._get_videos_info(mgid)
  243. return videos_info
  244. class MTVServicesEmbeddedIE(MTVServicesInfoExtractor):
  245. IE_NAME = 'mtvservices:embedded'
  246. _VALID_URL = r'https?://media\.mtvnservices\.com/embed/(?P<mgid>.+?)(\?|/|$)'
  247. _TEST = {
  248. # From http://www.thewrap.com/peter-dinklage-sums-up-game-of-thrones-in-45-seconds-video/
  249. 'url': 'http://media.mtvnservices.com/embed/mgid:uma:video:mtv.com:1043906/cp~vid%3D1043906%26uri%3Dmgid%3Auma%3Avideo%3Amtv.com%3A1043906',
  250. 'md5': 'cb349b21a7897164cede95bd7bf3fbb9',
  251. 'info_dict': {
  252. 'id': '1043906',
  253. 'ext': 'mp4',
  254. 'title': 'Peter Dinklage Sums Up \'Game Of Thrones\' In 45 Seconds',
  255. 'description': '"Sexy sexy sexy, stabby stabby stabby, beautiful language," says Peter Dinklage as he tries summarizing "Game of Thrones" in under a minute.',
  256. 'timestamp': 1400126400,
  257. 'upload_date': '20140515',
  258. },
  259. }
  260. @staticmethod
  261. def _extract_url(webpage):
  262. mobj = re.search(
  263. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//media.mtvnservices.com/embed/.+?)\1', webpage)
  264. if mobj:
  265. return mobj.group('url')
  266. def _get_feed_url(self, uri):
  267. video_id = self._id_from_uri(uri)
  268. config = self._download_json(
  269. 'http://media.mtvnservices.com/pmt/e1/access/index.html?uri=%s&configtype=edge' % uri, video_id)
  270. return self._remove_template_parameter(config['feedWithQueryParams'])
  271. def _real_extract(self, url):
  272. mobj = re.match(self._VALID_URL, url)
  273. mgid = mobj.group('mgid')
  274. return self._get_videos_info(mgid)
  275. class MTVIE(MTVServicesInfoExtractor):
  276. IE_NAME = 'mtv'
  277. _VALID_URL = r'https?://(?:www\.)?mtv\.com/(?:video-clips|(?:full-)?episodes)/(?P<id>[^/?#.]+)'
  278. _FEED_URL = 'http://www.mtv.com/feeds/mrss/'
  279. _TESTS = [{
  280. 'url': 'http://www.mtv.com/video-clips/vl8qof/unlocking-the-truth-trailer',
  281. 'md5': '1edbcdf1e7628e414a8c5dcebca3d32b',
  282. 'info_dict': {
  283. 'id': '5e14040d-18a4-47c4-a582-43ff602de88e',
  284. 'ext': 'mp4',
  285. 'title': 'Unlocking The Truth|July 18, 2016|1|101|Trailer',
  286. 'description': '"Unlocking the Truth" premieres August 17th at 11/10c.',
  287. 'timestamp': 1468846800,
  288. 'upload_date': '20160718',
  289. },
  290. }, {
  291. 'url': 'http://www.mtv.com/full-episodes/94tujl/unlocking-the-truth-gates-of-hell-season-1-ep-101',
  292. 'only_matching': True,
  293. }, {
  294. 'url': 'http://www.mtv.com/episodes/g8xu7q/teen-mom-2-breaking-the-wall-season-7-ep-713',
  295. 'only_matching': True,
  296. }]
  297. class MTV81IE(InfoExtractor):
  298. IE_NAME = 'mtv81'
  299. _VALID_URL = r'https?://(?:www\.)?mtv81\.com/videos/(?P<id>[^/?#.]+)'
  300. _TEST = {
  301. 'url': 'http://www.mtv81.com/videos/artist-to-watch/the-godfather-of-japanese-hip-hop-segment-1/',
  302. 'md5': '1edbcdf1e7628e414a8c5dcebca3d32b',
  303. 'info_dict': {
  304. 'id': '5e14040d-18a4-47c4-a582-43ff602de88e',
  305. 'ext': 'mp4',
  306. 'title': 'Unlocking The Truth|July 18, 2016|1|101|Trailer',
  307. 'description': '"Unlocking the Truth" premieres August 17th at 11/10c.',
  308. 'timestamp': 1468846800,
  309. 'upload_date': '20160718',
  310. },
  311. }
  312. def _extract_mgid(self, webpage):
  313. return self._search_regex(
  314. r'getTheVideo\((["\'])(?P<id>mgid:.+?)\1', webpage,
  315. 'mgid', group='id')
  316. def _real_extract(self, url):
  317. video_id = self._match_id(url)
  318. webpage = self._download_webpage(url, video_id)
  319. mgid = self._extract_mgid(webpage)
  320. return self.url_result('http://media.mtvnservices.com/embed/%s' % mgid)
  321. class MTVVideoIE(MTVServicesInfoExtractor):
  322. IE_NAME = 'mtv:video'
  323. _VALID_URL = r'''(?x)^https?://
  324. (?:(?:www\.)?mtv\.com/videos/.+?/(?P<videoid>[0-9]+)/[^/]+$|
  325. m\.mtv\.com/videos/video\.rbml\?.*?id=(?P<mgid>[^&]+))'''
  326. _FEED_URL = 'http://www.mtv.com/player/embed/AS3/rss/'
  327. _TESTS = [
  328. {
  329. 'url': 'http://www.mtv.com/videos/misc/853555/ours-vh1-storytellers.jhtml',
  330. 'md5': '850f3f143316b1e71fa56a4edfd6e0f8',
  331. 'info_dict': {
  332. 'id': '853555',
  333. 'ext': 'mp4',
  334. 'title': 'Taylor Swift - "Ours (VH1 Storytellers)"',
  335. 'description': 'Album: Taylor Swift performs "Ours" for VH1 Storytellers at Harvey Mudd College.',
  336. 'timestamp': 1352610000,
  337. 'upload_date': '20121111',
  338. },
  339. },
  340. ]
  341. def _get_thumbnail_url(self, uri, itemdoc):
  342. return 'http://mtv.mtvnimages.com/uri/' + uri
  343. def _real_extract(self, url):
  344. mobj = re.match(self._VALID_URL, url)
  345. video_id = mobj.group('videoid')
  346. uri = mobj.groupdict().get('mgid')
  347. if uri is None:
  348. webpage = self._download_webpage(url, video_id)
  349. # Some videos come from Vevo.com
  350. m_vevo = re.search(
  351. r'(?s)isVevoVideo = true;.*?vevoVideoId = "(.*?)";', webpage)
  352. if m_vevo:
  353. vevo_id = m_vevo.group(1)
  354. self.to_screen('Vevo video detected: %s' % vevo_id)
  355. return self.url_result('vevo:%s' % vevo_id, ie='Vevo')
  356. uri = self._html_search_regex(r'/uri/(.*?)\?', webpage, 'uri')
  357. return self._get_videos_info(uri)
  358. class MTVDEIE(MTVServicesInfoExtractor):
  359. IE_NAME = 'mtv.de'
  360. _VALID_URL = r'https?://(?:www\.)?mtv\.de/(?:artists|shows|news)/(?:[^/]+/)*(?P<id>\d+)-[^/#?]+/*(?:[#?].*)?$'
  361. _TESTS = [{
  362. 'url': 'http://www.mtv.de/artists/10571-cro/videos/61131-traum',
  363. 'info_dict': {
  364. 'id': 'music_video-a50bc5f0b3aa4b3190aa',
  365. 'ext': 'flv',
  366. 'title': 'MusicVideo_cro-traum',
  367. 'description': 'Cro - Traum',
  368. },
  369. 'params': {
  370. # rtmp download
  371. 'skip_download': True,
  372. },
  373. 'skip': 'Blocked at Travis CI',
  374. }, {
  375. # mediagen URL without query (e.g. http://videos.mtvnn.com/mediagen/e865da714c166d18d6f80893195fcb97)
  376. 'url': 'http://www.mtv.de/shows/933-teen-mom-2/staffeln/5353/folgen/63565-enthullungen',
  377. 'info_dict': {
  378. 'id': 'local_playlist-f5ae778b9832cc837189',
  379. 'ext': 'flv',
  380. 'title': 'Episode_teen-mom-2_shows_season-5_episode-1_full-episode_part1',
  381. },
  382. 'params': {
  383. # rtmp download
  384. 'skip_download': True,
  385. },
  386. 'skip': 'Blocked at Travis CI',
  387. }, {
  388. 'url': 'http://www.mtv.de/news/77491-mtv-movies-spotlight-pixels-teil-3',
  389. 'info_dict': {
  390. 'id': 'local_playlist-4e760566473c4c8c5344',
  391. 'ext': 'mp4',
  392. 'title': 'Article_mtv-movies-spotlight-pixels-teil-3_short-clips_part1',
  393. 'description': 'MTV Movies Supercut',
  394. },
  395. 'params': {
  396. # rtmp download
  397. 'skip_download': True,
  398. },
  399. 'skip': 'Das Video kann zur Zeit nicht abgespielt werden.',
  400. }]
  401. def _real_extract(self, url):
  402. video_id = self._match_id(url)
  403. webpage = self._download_webpage(url, video_id)
  404. playlist = self._parse_json(
  405. self._search_regex(
  406. r'window\.pagePlaylist\s*=\s*(\[.+?\]);\n', webpage, 'page playlist'),
  407. video_id)
  408. def _mrss_url(item):
  409. return item['mrss'] + item.get('mrssvars', '')
  410. # news pages contain single video in playlist with different id
  411. if len(playlist) == 1:
  412. return self._get_videos_info_from_url(_mrss_url(playlist[0]), video_id)
  413. for item in playlist:
  414. item_id = item.get('id')
  415. if item_id and compat_str(item_id) == video_id:
  416. return self._get_videos_info_from_url(_mrss_url(item), video_id)