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.

611 lines
25 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. # arte embed
  195. {
  196. 'url': 'http://www.tv-replay.fr/redirection/20-03-14/x-enius-arte-10753389.html',
  197. 'md5': '7653032cbb25bf6c80d80f217055fa43',
  198. 'info_dict': {
  199. 'id': '048195-004_PLUS7-F',
  200. 'ext': 'flv',
  201. 'title': 'X:enius',
  202. 'description': 'md5:d5fdf32ef6613cdbfd516ae658abf168',
  203. 'upload_date': '20140320',
  204. },
  205. 'params': {
  206. 'skip_download': 'Requires rtmpdump'
  207. }
  208. },
  209. ]
  210. def report_download_webpage(self, video_id):
  211. """Report webpage download."""
  212. if not self._downloader.params.get('test', False):
  213. self._downloader.report_warning('Falling back on generic information extractor.')
  214. super(GenericIE, self).report_download_webpage(video_id)
  215. def report_following_redirect(self, new_url):
  216. """Report information extraction."""
  217. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  218. def _send_head(self, url):
  219. """Check if it is a redirect, like url shorteners, in case return the new url."""
  220. class HEADRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
  221. """
  222. Subclass the HTTPRedirectHandler to make it use our
  223. HEADRequest also on the redirected URL
  224. """
  225. def redirect_request(self, req, fp, code, msg, headers, newurl):
  226. if code in (301, 302, 303, 307):
  227. newurl = newurl.replace(' ', '%20')
  228. newheaders = dict((k,v) for k,v in req.headers.items()
  229. if k.lower() not in ("content-length", "content-type"))
  230. try:
  231. # This function was deprecated in python 3.3 and removed in 3.4
  232. origin_req_host = req.get_origin_req_host()
  233. except AttributeError:
  234. origin_req_host = req.origin_req_host
  235. return HEADRequest(newurl,
  236. headers=newheaders,
  237. origin_req_host=origin_req_host,
  238. unverifiable=True)
  239. else:
  240. raise compat_urllib_error.HTTPError(req.get_full_url(), code, msg, headers, fp)
  241. class HTTPMethodFallback(compat_urllib_request.BaseHandler):
  242. """
  243. Fallback to GET if HEAD is not allowed (405 HTTP error)
  244. """
  245. def http_error_405(self, req, fp, code, msg, headers):
  246. fp.read()
  247. fp.close()
  248. newheaders = dict((k,v) for k,v in req.headers.items()
  249. if k.lower() not in ("content-length", "content-type"))
  250. return self.parent.open(compat_urllib_request.Request(req.get_full_url(),
  251. headers=newheaders,
  252. origin_req_host=req.get_origin_req_host(),
  253. unverifiable=True))
  254. # Build our opener
  255. opener = compat_urllib_request.OpenerDirector()
  256. for handler in [compat_urllib_request.HTTPHandler, compat_urllib_request.HTTPDefaultErrorHandler,
  257. HTTPMethodFallback, HEADRedirectHandler,
  258. compat_urllib_request.HTTPErrorProcessor, compat_urllib_request.HTTPSHandler]:
  259. opener.add_handler(handler())
  260. response = opener.open(HEADRequest(url))
  261. if response is None:
  262. raise ExtractorError('Invalid URL protocol')
  263. return response
  264. def _extract_rss(self, url, video_id, doc):
  265. playlist_title = doc.find('./channel/title').text
  266. playlist_desc_el = doc.find('./channel/description')
  267. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  268. entries = [{
  269. '_type': 'url',
  270. 'url': e.find('link').text,
  271. 'title': e.find('title').text,
  272. } for e in doc.findall('./channel/item')]
  273. return {
  274. '_type': 'playlist',
  275. 'id': url,
  276. 'title': playlist_title,
  277. 'description': playlist_desc,
  278. 'entries': entries,
  279. }
  280. def _real_extract(self, url):
  281. parsed_url = compat_urlparse.urlparse(url)
  282. if not parsed_url.scheme:
  283. default_search = self._downloader.params.get('default_search')
  284. if default_search is None:
  285. default_search = 'auto'
  286. if default_search == 'auto':
  287. if '/' in url:
  288. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  289. return self.url_result('http://' + url)
  290. else:
  291. return self.url_result('ytsearch:' + url)
  292. else:
  293. assert ':' in default_search
  294. return self.url_result(default_search + url)
  295. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  296. self.to_screen('%s: Requesting header' % video_id)
  297. try:
  298. response = self._send_head(url)
  299. # Check for redirect
  300. new_url = response.geturl()
  301. if url != new_url:
  302. self.report_following_redirect(new_url)
  303. return self.url_result(new_url)
  304. # Check for direct link to a video
  305. content_type = response.headers.get('Content-Type', '')
  306. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  307. if m:
  308. upload_date = response.headers.get('Last-Modified')
  309. if upload_date:
  310. upload_date = unified_strdate(upload_date)
  311. return {
  312. 'id': video_id,
  313. 'title': os.path.splitext(url_basename(url))[0],
  314. 'formats': [{
  315. 'format_id': m.group('format_id'),
  316. 'url': url,
  317. 'vcodec': 'none' if m.group('type') == 'audio' else None
  318. }],
  319. 'upload_date': upload_date,
  320. }
  321. except compat_urllib_error.HTTPError:
  322. # This may be a stupid server that doesn't like HEAD, our UA, or so
  323. pass
  324. try:
  325. webpage = self._download_webpage(url, video_id)
  326. except ValueError:
  327. # since this is the last-resort InfoExtractor, if
  328. # this error is thrown, it'll be thrown here
  329. raise ExtractorError('Failed to download URL: %s' % url)
  330. self.report_extraction(video_id)
  331. # Is it an RSS feed?
  332. try:
  333. doc = parse_xml(webpage)
  334. if doc.tag == 'rss':
  335. return self._extract_rss(url, video_id, doc)
  336. except compat_xml_parse_error:
  337. pass
  338. # Sometimes embedded video player is hidden behind percent encoding
  339. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  340. # Unescaping the whole page allows to handle those cases in a generic way
  341. webpage = compat_urllib_parse.unquote(webpage)
  342. # it's tempting to parse this further, but you would
  343. # have to take into account all the variations like
  344. # Video Title - Site Name
  345. # Site Name | Video Title
  346. # Video Title - Tagline | Site Name
  347. # and so on and so forth; it's just not practical
  348. video_title = self._html_search_regex(
  349. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  350. default='video')
  351. # video uploader is domain name
  352. video_uploader = self._search_regex(
  353. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  354. # Look for BrightCove:
  355. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  356. if bc_urls:
  357. self.to_screen('Brightcove video detected.')
  358. entries = [{
  359. '_type': 'url',
  360. 'url': smuggle_url(bc_url, {'Referer': url}),
  361. 'ie_key': 'Brightcove'
  362. } for bc_url in bc_urls]
  363. return {
  364. '_type': 'playlist',
  365. 'title': video_title,
  366. 'id': video_id,
  367. 'entries': entries,
  368. }
  369. # Look for embedded (iframe) Vimeo player
  370. mobj = re.search(
  371. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  372. if mobj:
  373. player_url = unescapeHTML(mobj.group('url'))
  374. surl = smuggle_url(player_url, {'Referer': url})
  375. return self.url_result(surl, 'Vimeo')
  376. # Look for embedded (swf embed) Vimeo player
  377. mobj = re.search(
  378. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  379. if mobj:
  380. return self.url_result(mobj.group(1), 'Vimeo')
  381. # Look for embedded YouTube player
  382. matches = re.findall(r'''(?x)
  383. (?:<iframe[^>]+?src=|embedSWF\(\s*)
  384. (["\'])(?P<url>(?:https?:)?//(?:www\.)?youtube\.com/
  385. (?:embed|v)/.+?)
  386. \1''', webpage)
  387. if matches:
  388. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Youtube')
  389. for tuppl in matches]
  390. return self.playlist_result(
  391. urlrs, playlist_id=video_id, playlist_title=video_title)
  392. # Look for embedded Dailymotion player
  393. matches = re.findall(
  394. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  395. if matches:
  396. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Dailymotion')
  397. for tuppl in matches]
  398. return self.playlist_result(
  399. urlrs, playlist_id=video_id, playlist_title=video_title)
  400. # Look for embedded Wistia player
  401. match = re.search(
  402. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  403. if match:
  404. return {
  405. '_type': 'url_transparent',
  406. 'url': unescapeHTML(match.group('url')),
  407. 'ie_key': 'Wistia',
  408. 'uploader': video_uploader,
  409. 'title': video_title,
  410. 'id': video_id,
  411. }
  412. # Look for embedded blip.tv player
  413. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  414. if mobj:
  415. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  416. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9]+)', webpage)
  417. if mobj:
  418. return self.url_result(mobj.group(1), 'BlipTV')
  419. # Look for Bandcamp pages with custom domain
  420. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  421. if mobj is not None:
  422. burl = unescapeHTML(mobj.group(1))
  423. # Don't set the extractor because it can be a track url or an album
  424. return self.url_result(burl)
  425. # Look for embedded Vevo player
  426. mobj = re.search(
  427. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  428. if mobj is not None:
  429. return self.url_result(mobj.group('url'))
  430. # Look for Ooyala videos
  431. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  432. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  433. if mobj is not None:
  434. return OoyalaIE._build_url_result(mobj.group('ec'))
  435. # Look for Aparat videos
  436. mobj = re.search(r'<iframe src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  437. if mobj is not None:
  438. return self.url_result(mobj.group(1), 'Aparat')
  439. # Look for MPORA videos
  440. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  441. if mobj is not None:
  442. return self.url_result(mobj.group(1), 'Mpora')
  443. # Look for embedded NovaMov player
  444. mobj = re.search(
  445. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?novamov\.com/embed\.php.+?)\1', webpage)
  446. if mobj is not None:
  447. return self.url_result(mobj.group('url'), 'NovaMov')
  448. # Look for embedded NowVideo player
  449. mobj = re.search(
  450. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?nowvideo\.(?:ch|sx|eu)/embed\.php.+?)\1', webpage)
  451. if mobj is not None:
  452. return self.url_result(mobj.group('url'), 'NowVideo')
  453. # Look for embedded Facebook player
  454. mobj = re.search(
  455. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  456. if mobj is not None:
  457. return self.url_result(mobj.group('url'), 'Facebook')
  458. # Look for embedded VK player
  459. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  460. if mobj is not None:
  461. return self.url_result(mobj.group('url'), 'VK')
  462. # Look for embedded Huffington Post player
  463. mobj = re.search(
  464. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  465. if mobj is not None:
  466. return self.url_result(mobj.group('url'), 'HuffPost')
  467. # Look for embed.ly
  468. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  469. if mobj is not None:
  470. return self.url_result(mobj.group('url'))
  471. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  472. if mobj is not None:
  473. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  474. # Look for funnyordie embed
  475. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  476. if matches:
  477. urlrs = [self.url_result(unescapeHTML(eurl), 'FunnyOrDie')
  478. for eurl in matches]
  479. return self.playlist_result(
  480. urlrs, playlist_id=video_id, playlist_title=video_title)
  481. # Look for embedded RUTV player
  482. rutv_url = RUTVIE._extract_url(webpage)
  483. if rutv_url:
  484. return self.url_result(rutv_url, 'RUTV')
  485. # Look for embedded TED player
  486. mobj = re.search(
  487. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  488. if mobj is not None:
  489. return self.url_result(mobj.group('url'), 'TED')
  490. # Look for embedded arte.tv player
  491. mobj = re.search(
  492. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  493. webpage)
  494. if mobj is not None:
  495. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  496. # Start with something easy: JW Player in SWFObject
  497. mobj = re.search(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  498. if mobj is None:
  499. # Look for gorilla-vid style embedding
  500. mobj = re.search(r'(?s)(?:jw_plugins|JWPlayerOptions).*?file\s*:\s*["\'](.*?)["\']', webpage)
  501. if mobj is None:
  502. # Broaden the search a little bit
  503. mobj = re.search(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  504. if mobj is None:
  505. # Broaden the search a little bit: JWPlayer JS loader
  506. mobj = re.search(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  507. if mobj is None:
  508. # Try to find twitter cards info
  509. mobj = re.search(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  510. if mobj is None:
  511. # We look for Open Graph info:
  512. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  513. m_video_type = re.search(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  514. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  515. if m_video_type is not None:
  516. mobj = re.search(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)
  517. if mobj is None:
  518. # HTML5 video
  519. mobj = re.search(r'<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage, flags=re.DOTALL)
  520. if mobj is None:
  521. mobj = re.search(
  522. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  523. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'([^\']+)\'"',
  524. webpage)
  525. if mobj:
  526. new_url = mobj.group(1)
  527. self.report_following_redirect(new_url)
  528. return {
  529. '_type': 'url',
  530. 'url': new_url,
  531. }
  532. if mobj is None:
  533. raise ExtractorError('Unsupported URL: %s' % url)
  534. # It's possible that one of the regexes
  535. # matched, but returned an empty group:
  536. if mobj.group(1) is None:
  537. raise ExtractorError('Did not find a valid video URL at %s' % url)
  538. video_url = mobj.group(1)
  539. video_url = compat_urlparse.urljoin(url, video_url)
  540. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  541. # Sometimes, jwplayer extraction will result in a YouTube URL
  542. if YoutubeIE.suitable(video_url):
  543. return self.url_result(video_url, 'Youtube')
  544. # here's a fun little line of code for you:
  545. video_id = os.path.splitext(video_id)[0]
  546. return {
  547. 'id': video_id,
  548. 'url': video_url,
  549. 'uploader': video_uploader,
  550. 'title': video_title,
  551. }