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.

589 lines
24 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import os
  4. import re
  5. from .common import InfoExtractor
  6. from .youtube import YoutubeIE
  7. from ..utils import (
  8. compat_urllib_error,
  9. compat_urllib_parse,
  10. compat_urllib_request,
  11. compat_urlparse,
  12. compat_xml_parse_error,
  13. ExtractorError,
  14. HEADRequest,
  15. parse_xml,
  16. smuggle_url,
  17. unescapeHTML,
  18. unified_strdate,
  19. url_basename,
  20. )
  21. from .brightcove import BrightcoveIE
  22. from .ooyala import OoyalaIE
  23. from .rutv import RUTVIE
  24. class GenericIE(InfoExtractor):
  25. IE_DESC = 'Generic downloader that works on some sites'
  26. _VALID_URL = r'.*'
  27. IE_NAME = 'generic'
  28. _TESTS = [
  29. {
  30. 'url': 'http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html',
  31. 'file': '13601338388002.mp4',
  32. 'md5': '6e15c93721d7ec9e9ca3fdbf07982cfd',
  33. 'info_dict': {
  34. 'uploader': 'www.hodiho.fr',
  35. 'title': 'R\u00e9gis plante sa Jeep',
  36. }
  37. },
  38. # bandcamp page with custom domain
  39. {
  40. 'add_ie': ['Bandcamp'],
  41. 'url': 'http://bronyrock.com/track/the-pony-mash',
  42. 'file': '3235767654.mp3',
  43. 'info_dict': {
  44. 'title': 'The Pony Mash',
  45. 'uploader': 'M_Pallante',
  46. },
  47. 'skip': 'There is a limit of 200 free downloads / month for the test song',
  48. },
  49. # embedded brightcove video
  50. # it also tests brightcove videos that need to set the 'Referer' in the
  51. # http requests
  52. {
  53. 'add_ie': ['Brightcove'],
  54. 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
  55. 'info_dict': {
  56. 'id': '2765128793001',
  57. 'ext': 'mp4',
  58. 'title': 'Le cours de bourse : l’analyse technique',
  59. 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
  60. 'uploader': 'BFM BUSINESS',
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. },
  66. {
  67. # https://github.com/rg3/youtube-dl/issues/2253
  68. 'url': 'http://bcove.me/i6nfkrc3',
  69. 'file': '3101154703001.mp4',
  70. 'md5': '0ba9446db037002366bab3b3eb30c88c',
  71. 'info_dict': {
  72. 'title': 'Still no power',
  73. 'uploader': 'thestar.com',
  74. 'description': 'Mississauga resident David Farmer is still out of power as a result of the ice storm a month ago. To keep the house warm, Farmer cuts wood from his property for a wood burning stove downstairs.',
  75. },
  76. 'add_ie': ['Brightcove'],
  77. },
  78. # Direct link to a video
  79. {
  80. 'url': 'http://media.w3.org/2010/05/sintel/trailer.mp4',
  81. 'md5': '67d406c2bcb6af27fa886f31aa934bbe',
  82. 'info_dict': {
  83. 'id': 'trailer',
  84. 'ext': 'mp4',
  85. 'title': 'trailer',
  86. 'upload_date': '20100513',
  87. }
  88. },
  89. # ooyala video
  90. {
  91. 'url': 'http://www.rollingstone.com/music/videos/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-20131219',
  92. 'md5': '5644c6ca5d5782c1d0d350dad9bd840c',
  93. 'info_dict': {
  94. 'id': 'BwY2RxaTrTkslxOfcan0UCf0YqyvWysJ',
  95. 'ext': 'mp4',
  96. 'title': '2cc213299525360.mov', # that's what we get
  97. },
  98. },
  99. # second style of embedded ooyala videos
  100. {
  101. 'url': 'http://www.smh.com.au/tv/business/show/financial-review-sunday/behind-the-scenes-financial-review-sunday--4350201.html',
  102. 'info_dict': {
  103. 'id': '13djJjYjptA1XpPx8r9kuzPyj3UZH0Uk',
  104. 'ext': 'mp4',
  105. 'title': 'Behind-the-scenes: Financial Review Sunday ',
  106. 'description': 'Step inside Channel Nine studios for an exclusive tour of its upcoming financial business show.',
  107. },
  108. 'params': {
  109. # m3u8 download
  110. 'skip_download': True,
  111. },
  112. },
  113. # google redirect
  114. {
  115. 'url': 'http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCUQtwIwAA&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcmQHVoWB5FY&ei=F-sNU-LLCaXk4QT52ICQBQ&usg=AFQjCNEw4hL29zgOohLXvpJ-Bdh2bils1Q&bvm=bv.61965928,d.bGE',
  116. 'info_dict': {
  117. 'id': 'cmQHVoWB5FY',
  118. 'ext': 'mp4',
  119. 'upload_date': '20130224',
  120. 'uploader_id': 'TheVerge',
  121. 'description': 'Chris Ziegler takes a look at the Alcatel OneTouch Fire and the ZTE Open; two of the first Firefox OS handsets to be officially announced.',
  122. 'uploader': 'The Verge',
  123. 'title': 'First Firefox OS phones side-by-side',
  124. },
  125. 'params': {
  126. 'skip_download': False,
  127. }
  128. },
  129. # embed.ly video
  130. {
  131. 'url': 'http://www.tested.com/science/weird/460206-tested-grinding-coffee-2000-frames-second/',
  132. 'info_dict': {
  133. 'id': '9ODmcdjQcHQ',
  134. 'ext': 'mp4',
  135. 'title': 'Tested: Grinding Coffee at 2000 Frames Per Second',
  136. 'upload_date': '20140225',
  137. 'description': 'md5:06a40fbf30b220468f1e0957c0f558ff',
  138. 'uploader': 'Tested',
  139. 'uploader_id': 'testedcom',
  140. },
  141. # No need to test YoutubeIE here
  142. 'params': {
  143. 'skip_download': True,
  144. },
  145. },
  146. # funnyordie embed
  147. {
  148. 'url': 'http://www.theguardian.com/world/2014/mar/11/obama-zach-galifianakis-between-two-ferns',
  149. 'md5': '7cf780be104d40fea7bae52eed4a470e',
  150. 'info_dict': {
  151. 'id': '18e820ec3f',
  152. 'ext': 'mp4',
  153. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  154. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  155. },
  156. },
  157. # RUTV embed
  158. {
  159. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  160. 'info_dict': {
  161. 'id': '776940',
  162. 'ext': 'mp4',
  163. 'title': 'Охотское море стало целиком российским',
  164. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  165. },
  166. 'params': {
  167. # m3u8 download
  168. 'skip_download': True,
  169. },
  170. },
  171. # Embedded TED video
  172. {
  173. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  174. 'md5': 'deeeabcc1085eb2ba205474e7235a3d5',
  175. 'info_dict': {
  176. 'id': '981',
  177. 'ext': 'mp4',
  178. 'title': 'My web playroom',
  179. 'uploader': 'Ze Frank',
  180. 'description': 'md5:ddb2a40ecd6b6a147e400e535874947b',
  181. }
  182. },
  183. # nowvideo embed hidden behind percent encoding
  184. {
  185. 'url': 'http://www.waoanime.tv/the-super-dimension-fortress-macross-episode-1/',
  186. 'md5': '2baf4ddd70f697d94b1c18cf796d5107',
  187. 'info_dict': {
  188. 'id': '06e53103ca9aa',
  189. 'ext': 'flv',
  190. 'title': 'Macross Episode 001 Watch Macross Episode 001 onl',
  191. 'description': 'No description',
  192. },
  193. },
  194. ]
  195. def report_download_webpage(self, video_id):
  196. """Report webpage download."""
  197. if not self._downloader.params.get('test', False):
  198. self._downloader.report_warning('Falling back on generic information extractor.')
  199. super(GenericIE, self).report_download_webpage(video_id)
  200. def report_following_redirect(self, new_url):
  201. """Report information extraction."""
  202. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  203. def _send_head(self, url):
  204. """Check if it is a redirect, like url shorteners, in case return the new url."""
  205. class HEADRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
  206. """
  207. Subclass the HTTPRedirectHandler to make it use our
  208. HEADRequest also on the redirected URL
  209. """
  210. def redirect_request(self, req, fp, code, msg, headers, newurl):
  211. if code in (301, 302, 303, 307):
  212. newurl = newurl.replace(' ', '%20')
  213. newheaders = dict((k,v) for k,v in req.headers.items()
  214. if k.lower() not in ("content-length", "content-type"))
  215. try:
  216. # This function was deprecated in python 3.3 and removed in 3.4
  217. origin_req_host = req.get_origin_req_host()
  218. except AttributeError:
  219. origin_req_host = req.origin_req_host
  220. return HEADRequest(newurl,
  221. headers=newheaders,
  222. origin_req_host=origin_req_host,
  223. unverifiable=True)
  224. else:
  225. raise compat_urllib_error.HTTPError(req.get_full_url(), code, msg, headers, fp)
  226. class HTTPMethodFallback(compat_urllib_request.BaseHandler):
  227. """
  228. Fallback to GET if HEAD is not allowed (405 HTTP error)
  229. """
  230. def http_error_405(self, req, fp, code, msg, headers):
  231. fp.read()
  232. fp.close()
  233. newheaders = dict((k,v) for k,v in req.headers.items()
  234. if k.lower() not in ("content-length", "content-type"))
  235. return self.parent.open(compat_urllib_request.Request(req.get_full_url(),
  236. headers=newheaders,
  237. origin_req_host=req.get_origin_req_host(),
  238. unverifiable=True))
  239. # Build our opener
  240. opener = compat_urllib_request.OpenerDirector()
  241. for handler in [compat_urllib_request.HTTPHandler, compat_urllib_request.HTTPDefaultErrorHandler,
  242. HTTPMethodFallback, HEADRedirectHandler,
  243. compat_urllib_request.HTTPErrorProcessor, compat_urllib_request.HTTPSHandler]:
  244. opener.add_handler(handler())
  245. response = opener.open(HEADRequest(url))
  246. if response is None:
  247. raise ExtractorError('Invalid URL protocol')
  248. return response
  249. def _extract_rss(self, url, video_id, doc):
  250. playlist_title = doc.find('./channel/title').text
  251. playlist_desc_el = doc.find('./channel/description')
  252. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  253. entries = [{
  254. '_type': 'url',
  255. 'url': e.find('link').text,
  256. 'title': e.find('title').text,
  257. } for e in doc.findall('./channel/item')]
  258. return {
  259. '_type': 'playlist',
  260. 'id': url,
  261. 'title': playlist_title,
  262. 'description': playlist_desc,
  263. 'entries': entries,
  264. }
  265. def _real_extract(self, url):
  266. parsed_url = compat_urlparse.urlparse(url)
  267. if not parsed_url.scheme:
  268. default_search = self._downloader.params.get('default_search')
  269. if default_search is None:
  270. default_search = 'auto'
  271. if default_search == 'auto':
  272. if '/' in url:
  273. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  274. return self.url_result('http://' + url)
  275. else:
  276. return self.url_result('ytsearch:' + url)
  277. else:
  278. assert ':' in default_search
  279. return self.url_result(default_search + url)
  280. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  281. self.to_screen('%s: Requesting header' % video_id)
  282. try:
  283. response = self._send_head(url)
  284. # Check for redirect
  285. new_url = response.geturl()
  286. if url != new_url:
  287. self.report_following_redirect(new_url)
  288. return self.url_result(new_url)
  289. # Check for direct link to a video
  290. content_type = response.headers.get('Content-Type', '')
  291. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  292. if m:
  293. upload_date = response.headers.get('Last-Modified')
  294. if upload_date:
  295. upload_date = unified_strdate(upload_date)
  296. return {
  297. 'id': video_id,
  298. 'title': os.path.splitext(url_basename(url))[0],
  299. 'formats': [{
  300. 'format_id': m.group('format_id'),
  301. 'url': url,
  302. 'vcodec': 'none' if m.group('type') == 'audio' else None
  303. }],
  304. 'upload_date': upload_date,
  305. }
  306. except compat_urllib_error.HTTPError:
  307. # This may be a stupid server that doesn't like HEAD, our UA, or so
  308. pass
  309. try:
  310. webpage = self._download_webpage(url, video_id)
  311. except ValueError:
  312. # since this is the last-resort InfoExtractor, if
  313. # this error is thrown, it'll be thrown here
  314. raise ExtractorError('Failed to download URL: %s' % url)
  315. self.report_extraction(video_id)
  316. # Is it an RSS feed?
  317. try:
  318. doc = parse_xml(webpage)
  319. if doc.tag == 'rss':
  320. return self._extract_rss(url, video_id, doc)
  321. except compat_xml_parse_error:
  322. pass
  323. # Sometimes embedded video player is hidden behind percent encoding
  324. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  325. # Unescaping the whole page allows to handle those cases in a generic way
  326. webpage = compat_urllib_parse.unquote(webpage)
  327. # it's tempting to parse this further, but you would
  328. # have to take into account all the variations like
  329. # Video Title - Site Name
  330. # Site Name | Video Title
  331. # Video Title - Tagline | Site Name
  332. # and so on and so forth; it's just not practical
  333. video_title = self._html_search_regex(
  334. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  335. default='video')
  336. # video uploader is domain name
  337. video_uploader = self._search_regex(
  338. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  339. # Look for BrightCove:
  340. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  341. if bc_urls:
  342. self.to_screen('Brightcove video detected.')
  343. entries = [{
  344. '_type': 'url',
  345. 'url': smuggle_url(bc_url, {'Referer': url}),
  346. 'ie_key': 'Brightcove'
  347. } for bc_url in bc_urls]
  348. return {
  349. '_type': 'playlist',
  350. 'title': video_title,
  351. 'id': video_id,
  352. 'entries': entries,
  353. }
  354. # Look for embedded (iframe) Vimeo player
  355. mobj = re.search(
  356. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  357. if mobj:
  358. player_url = unescapeHTML(mobj.group('url'))
  359. surl = smuggle_url(player_url, {'Referer': url})
  360. return self.url_result(surl, 'Vimeo')
  361. # Look for embedded (swf embed) Vimeo player
  362. mobj = re.search(
  363. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  364. if mobj:
  365. return self.url_result(mobj.group(1), 'Vimeo')
  366. # Look for embedded YouTube player
  367. matches = re.findall(r'''(?x)
  368. (?:<iframe[^>]+?src=|embedSWF\(\s*)
  369. (["\'])(?P<url>(?:https?:)?//(?:www\.)?youtube\.com/
  370. (?:embed|v)/.+?)
  371. \1''', webpage)
  372. if matches:
  373. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Youtube')
  374. for tuppl in matches]
  375. return self.playlist_result(
  376. urlrs, playlist_id=video_id, playlist_title=video_title)
  377. # Look for embedded Dailymotion player
  378. matches = re.findall(
  379. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  380. if matches:
  381. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Dailymotion')
  382. for tuppl in matches]
  383. return self.playlist_result(
  384. urlrs, playlist_id=video_id, playlist_title=video_title)
  385. # Look for embedded Wistia player
  386. match = re.search(
  387. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  388. if match:
  389. return {
  390. '_type': 'url_transparent',
  391. 'url': unescapeHTML(match.group('url')),
  392. 'ie_key': 'Wistia',
  393. 'uploader': video_uploader,
  394. 'title': video_title,
  395. 'id': video_id,
  396. }
  397. # Look for embedded blip.tv player
  398. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  399. if mobj:
  400. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  401. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9]+)', webpage)
  402. if mobj:
  403. return self.url_result(mobj.group(1), 'BlipTV')
  404. # Look for Bandcamp pages with custom domain
  405. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  406. if mobj is not None:
  407. burl = unescapeHTML(mobj.group(1))
  408. # Don't set the extractor because it can be a track url or an album
  409. return self.url_result(burl)
  410. # Look for embedded Vevo player
  411. mobj = re.search(
  412. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  413. if mobj is not None:
  414. return self.url_result(mobj.group('url'))
  415. # Look for Ooyala videos
  416. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  417. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  418. if mobj is not None:
  419. return OoyalaIE._build_url_result(mobj.group('ec'))
  420. # Look for Aparat videos
  421. mobj = re.search(r'<iframe src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  422. if mobj is not None:
  423. return self.url_result(mobj.group(1), 'Aparat')
  424. # Look for MPORA videos
  425. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  426. if mobj is not None:
  427. return self.url_result(mobj.group(1), 'Mpora')
  428. # Look for embedded NovaMov player
  429. mobj = re.search(
  430. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?novamov\.com/embed\.php.+?)\1', webpage)
  431. if mobj is not None:
  432. return self.url_result(mobj.group('url'), 'NovaMov')
  433. # Look for embedded NowVideo player
  434. mobj = re.search(
  435. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?nowvideo\.(?:ch|sx|eu)/embed\.php.+?)\1', webpage)
  436. if mobj is not None:
  437. return self.url_result(mobj.group('url'), 'NowVideo')
  438. # Look for embedded Facebook player
  439. mobj = re.search(
  440. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  441. if mobj is not None:
  442. return self.url_result(mobj.group('url'), 'Facebook')
  443. # Look for embedded VK player
  444. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  445. if mobj is not None:
  446. return self.url_result(mobj.group('url'), 'VK')
  447. # Look for embedded Huffington Post player
  448. mobj = re.search(
  449. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  450. if mobj is not None:
  451. return self.url_result(mobj.group('url'), 'HuffPost')
  452. # Look for embed.ly
  453. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  454. if mobj is not None:
  455. return self.url_result(mobj.group('url'))
  456. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  457. if mobj is not None:
  458. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  459. # Look for funnyordie embed
  460. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  461. if matches:
  462. urlrs = [self.url_result(unescapeHTML(eurl), 'FunnyOrDie')
  463. for eurl in matches]
  464. return self.playlist_result(
  465. urlrs, playlist_id=video_id, playlist_title=video_title)
  466. # Look for embedded RUTV player
  467. rutv_url = RUTVIE._extract_url(webpage)
  468. if rutv_url:
  469. return self.url_result(rutv_url, 'RUTV')
  470. # Look for embedded TED player
  471. mobj = re.search(
  472. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  473. if mobj is not None:
  474. return self.url_result(mobj.group('url'), 'TED')
  475. # Start with something easy: JW Player in SWFObject
  476. mobj = re.search(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  477. if mobj is None:
  478. # Look for gorilla-vid style embedding
  479. mobj = re.search(r'(?s)(?:jw_plugins|JWPlayerOptions).*?file\s*:\s*["\'](.*?)["\']', webpage)
  480. if mobj is None:
  481. # Broaden the search a little bit
  482. mobj = re.search(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  483. if mobj is None:
  484. # Broaden the search a little bit: JWPlayer JS loader
  485. mobj = re.search(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  486. if mobj is None:
  487. # Try to find twitter cards info
  488. mobj = re.search(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  489. if mobj is None:
  490. # We look for Open Graph info:
  491. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  492. m_video_type = re.search(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  493. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  494. if m_video_type is not None:
  495. mobj = re.search(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)
  496. if mobj is None:
  497. # HTML5 video
  498. mobj = re.search(r'<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage, flags=re.DOTALL)
  499. if mobj is None:
  500. mobj = re.search(
  501. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  502. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'([^\']+)\'"',
  503. webpage)
  504. if mobj:
  505. new_url = mobj.group(1)
  506. self.report_following_redirect(new_url)
  507. return {
  508. '_type': 'url',
  509. 'url': new_url,
  510. }
  511. if mobj is None:
  512. raise ExtractorError('Unsupported URL: %s' % url)
  513. # It's possible that one of the regexes
  514. # matched, but returned an empty group:
  515. if mobj.group(1) is None:
  516. raise ExtractorError('Did not find a valid video URL at %s' % url)
  517. video_url = mobj.group(1)
  518. video_url = compat_urlparse.urljoin(url, video_url)
  519. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  520. # Sometimes, jwplayer extraction will result in a YouTube URL
  521. if YoutubeIE.suitable(video_url):
  522. return self.url_result(video_url, 'Youtube')
  523. # here's a fun little line of code for you:
  524. video_id = os.path.splitext(video_id)[0]
  525. return {
  526. 'id': video_id,
  527. 'url': video_url,
  528. 'uploader': video_uploader,
  529. 'title': video_title,
  530. }