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.

718 lines
29 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. from .smotri import SmotriIE
  25. class GenericIE(InfoExtractor):
  26. IE_DESC = 'Generic downloader that works on some sites'
  27. _VALID_URL = r'.*'
  28. IE_NAME = 'generic'
  29. _TESTS = [
  30. {
  31. 'url': 'http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html',
  32. 'md5': '85b90ccc9d73b4acd9138d3af4c27f89',
  33. 'info_dict': {
  34. 'id': '13601338388002',
  35. 'ext': 'mp4',
  36. 'uploader': 'www.hodiho.fr',
  37. 'title': 'R\u00e9gis plante sa Jeep',
  38. }
  39. },
  40. # bandcamp page with custom domain
  41. {
  42. 'add_ie': ['Bandcamp'],
  43. 'url': 'http://bronyrock.com/track/the-pony-mash',
  44. 'info_dict': {
  45. 'id': '3235767654',
  46. 'ext': 'mp3',
  47. 'title': 'The Pony Mash',
  48. 'uploader': 'M_Pallante',
  49. },
  50. 'skip': 'There is a limit of 200 free downloads / month for the test song',
  51. },
  52. # embedded brightcove video
  53. # it also tests brightcove videos that need to set the 'Referer' in the
  54. # http requests
  55. {
  56. 'add_ie': ['Brightcove'],
  57. 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
  58. 'info_dict': {
  59. 'id': '2765128793001',
  60. 'ext': 'mp4',
  61. 'title': 'Le cours de bourse : l’analyse technique',
  62. 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
  63. 'uploader': 'BFM BUSINESS',
  64. },
  65. 'params': {
  66. 'skip_download': True,
  67. },
  68. },
  69. {
  70. # https://github.com/rg3/youtube-dl/issues/2253
  71. 'url': 'http://bcove.me/i6nfkrc3',
  72. 'md5': '0ba9446db037002366bab3b3eb30c88c',
  73. 'info_dict': {
  74. 'id': '3101154703001',
  75. 'ext': 'mp4',
  76. 'title': 'Still no power',
  77. 'uploader': 'thestar.com',
  78. '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.',
  79. },
  80. 'add_ie': ['Brightcove'],
  81. },
  82. {
  83. 'url': 'http://www.championat.com/video/football/v/87/87499.html',
  84. 'md5': 'fb973ecf6e4a78a67453647444222983',
  85. 'info_dict': {
  86. 'id': '3414141473001',
  87. 'ext': 'mp4',
  88. 'title': 'Видео. Удаление Дзагоева (ЦСКА)',
  89. 'description': 'Онлайн-трансляция матча ЦСКА - "Волга"',
  90. 'uploader': 'Championat',
  91. },
  92. },
  93. # Direct link to a video
  94. {
  95. 'url': 'http://media.w3.org/2010/05/sintel/trailer.mp4',
  96. 'md5': '67d406c2bcb6af27fa886f31aa934bbe',
  97. 'info_dict': {
  98. 'id': 'trailer',
  99. 'ext': 'mp4',
  100. 'title': 'trailer',
  101. 'upload_date': '20100513',
  102. }
  103. },
  104. # ooyala video
  105. {
  106. 'url': 'http://www.rollingstone.com/music/videos/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-20131219',
  107. 'md5': '5644c6ca5d5782c1d0d350dad9bd840c',
  108. 'info_dict': {
  109. 'id': 'BwY2RxaTrTkslxOfcan0UCf0YqyvWysJ',
  110. 'ext': 'mp4',
  111. 'title': '2cc213299525360.mov', # that's what we get
  112. },
  113. },
  114. # google redirect
  115. {
  116. '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',
  117. 'info_dict': {
  118. 'id': 'cmQHVoWB5FY',
  119. 'ext': 'mp4',
  120. 'upload_date': '20130224',
  121. 'uploader_id': 'TheVerge',
  122. '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.',
  123. 'uploader': 'The Verge',
  124. 'title': 'First Firefox OS phones side-by-side',
  125. },
  126. 'params': {
  127. 'skip_download': False,
  128. }
  129. },
  130. # embed.ly video
  131. {
  132. 'url': 'http://www.tested.com/science/weird/460206-tested-grinding-coffee-2000-frames-second/',
  133. 'info_dict': {
  134. 'id': '9ODmcdjQcHQ',
  135. 'ext': 'mp4',
  136. 'title': 'Tested: Grinding Coffee at 2000 Frames Per Second',
  137. 'upload_date': '20140225',
  138. 'description': 'md5:06a40fbf30b220468f1e0957c0f558ff',
  139. 'uploader': 'Tested',
  140. 'uploader_id': 'testedcom',
  141. },
  142. # No need to test YoutubeIE here
  143. 'params': {
  144. 'skip_download': True,
  145. },
  146. },
  147. # funnyordie embed
  148. {
  149. 'url': 'http://www.theguardian.com/world/2014/mar/11/obama-zach-galifianakis-between-two-ferns',
  150. 'md5': '7cf780be104d40fea7bae52eed4a470e',
  151. 'info_dict': {
  152. 'id': '18e820ec3f',
  153. 'ext': 'mp4',
  154. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  155. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  156. },
  157. },
  158. # RUTV embed
  159. {
  160. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  161. 'info_dict': {
  162. 'id': '776940',
  163. 'ext': 'mp4',
  164. 'title': 'Охотское море стало целиком российским',
  165. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  166. },
  167. 'params': {
  168. # m3u8 download
  169. 'skip_download': True,
  170. },
  171. },
  172. # Embedded TED video
  173. {
  174. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  175. 'md5': 'deeeabcc1085eb2ba205474e7235a3d5',
  176. 'info_dict': {
  177. 'id': '981',
  178. 'ext': 'mp4',
  179. 'title': 'My web playroom',
  180. 'uploader': 'Ze Frank',
  181. 'description': 'md5:ddb2a40ecd6b6a147e400e535874947b',
  182. }
  183. },
  184. # Embeded Ustream video
  185. {
  186. 'url': 'http://www.american.edu/spa/pti/nsa-privacy-janus-2014.cfm',
  187. 'md5': '27b99cdb639c9b12a79bca876a073417',
  188. 'info_dict': {
  189. 'id': '45734260',
  190. 'ext': 'flv',
  191. 'uploader': 'AU SPA: The NSA and Privacy',
  192. 'title': 'NSA and Privacy Forum Debate featuring General Hayden and Barton Gellman'
  193. }
  194. },
  195. # nowvideo embed hidden behind percent encoding
  196. {
  197. 'url': 'http://www.waoanime.tv/the-super-dimension-fortress-macross-episode-1/',
  198. 'md5': '2baf4ddd70f697d94b1c18cf796d5107',
  199. 'info_dict': {
  200. 'id': '06e53103ca9aa',
  201. 'ext': 'flv',
  202. 'title': 'Macross Episode 001 Watch Macross Episode 001 onl',
  203. 'description': 'No description',
  204. },
  205. },
  206. # arte embed
  207. {
  208. 'url': 'http://www.tv-replay.fr/redirection/20-03-14/x-enius-arte-10753389.html',
  209. 'md5': '7653032cbb25bf6c80d80f217055fa43',
  210. 'info_dict': {
  211. 'id': '048195-004_PLUS7-F',
  212. 'ext': 'flv',
  213. 'title': 'X:enius',
  214. 'description': 'md5:d5fdf32ef6613cdbfd516ae658abf168',
  215. 'upload_date': '20140320',
  216. },
  217. 'params': {
  218. 'skip_download': 'Requires rtmpdump'
  219. }
  220. },
  221. # smotri embed
  222. {
  223. 'url': 'http://rbctv.rbc.ru/archive/news/562949990879132.shtml',
  224. 'md5': 'ec40048448e9284c9a1de77bb188108b',
  225. 'info_dict': {
  226. 'id': 'v27008541fad',
  227. 'ext': 'mp4',
  228. 'title': 'Крым и Севастополь вошли в состав России',
  229. 'description': 'md5:fae01b61f68984c7bd2fa741e11c3175',
  230. 'duration': 900,
  231. 'upload_date': '20140318',
  232. 'uploader': 'rbctv_2012_4',
  233. 'uploader_id': 'rbctv_2012_4',
  234. },
  235. },
  236. # Condé Nast embed
  237. {
  238. 'url': 'http://www.wired.com/2014/04/honda-asimo/',
  239. 'md5': 'ba0dfe966fa007657bd1443ee672db0f',
  240. 'info_dict': {
  241. 'id': '53501be369702d3275860000',
  242. 'ext': 'mp4',
  243. 'title': 'Honda’s New Asimo Robot Is More Human Than Ever',
  244. }
  245. },
  246. # Dailymotion embed
  247. {
  248. 'url': 'http://www.spi0n.com/zap-spi0n-com-n216/',
  249. 'md5': '441aeeb82eb72c422c7f14ec533999cd',
  250. 'info_dict': {
  251. 'id': 'k2mm4bCdJ6CQ2i7c8o2',
  252. 'ext': 'mp4',
  253. 'title': 'Le Zap de Spi0n n°216 - Zapping du Web',
  254. 'uploader': 'Spi0n',
  255. },
  256. 'add_ie': ['Dailymotion'],
  257. }
  258. ]
  259. def report_download_webpage(self, video_id):
  260. """Report webpage download."""
  261. if not self._downloader.params.get('test', False):
  262. self._downloader.report_warning('Falling back on generic information extractor.')
  263. super(GenericIE, self).report_download_webpage(video_id)
  264. def report_following_redirect(self, new_url):
  265. """Report information extraction."""
  266. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  267. def _send_head(self, url):
  268. """Check if it is a redirect, like url shorteners, in case return the new url."""
  269. class HEADRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
  270. """
  271. Subclass the HTTPRedirectHandler to make it use our
  272. HEADRequest also on the redirected URL
  273. """
  274. def redirect_request(self, req, fp, code, msg, headers, newurl):
  275. if code in (301, 302, 303, 307):
  276. newurl = newurl.replace(' ', '%20')
  277. newheaders = dict((k,v) for k,v in req.headers.items()
  278. if k.lower() not in ("content-length", "content-type"))
  279. try:
  280. # This function was deprecated in python 3.3 and removed in 3.4
  281. origin_req_host = req.get_origin_req_host()
  282. except AttributeError:
  283. origin_req_host = req.origin_req_host
  284. return HEADRequest(newurl,
  285. headers=newheaders,
  286. origin_req_host=origin_req_host,
  287. unverifiable=True)
  288. else:
  289. raise compat_urllib_error.HTTPError(req.get_full_url(), code, msg, headers, fp)
  290. class HTTPMethodFallback(compat_urllib_request.BaseHandler):
  291. """
  292. Fallback to GET if HEAD is not allowed (405 HTTP error)
  293. """
  294. def http_error_405(self, req, fp, code, msg, headers):
  295. fp.read()
  296. fp.close()
  297. newheaders = dict((k,v) for k,v in req.headers.items()
  298. if k.lower() not in ("content-length", "content-type"))
  299. return self.parent.open(compat_urllib_request.Request(req.get_full_url(),
  300. headers=newheaders,
  301. origin_req_host=req.get_origin_req_host(),
  302. unverifiable=True))
  303. # Build our opener
  304. opener = compat_urllib_request.OpenerDirector()
  305. for handler in [compat_urllib_request.HTTPHandler, compat_urllib_request.HTTPDefaultErrorHandler,
  306. HTTPMethodFallback, HEADRedirectHandler,
  307. compat_urllib_request.HTTPErrorProcessor, compat_urllib_request.HTTPSHandler]:
  308. opener.add_handler(handler())
  309. response = opener.open(HEADRequest(url))
  310. if response is None:
  311. raise ExtractorError('Invalid URL protocol')
  312. return response
  313. def _extract_rss(self, url, video_id, doc):
  314. playlist_title = doc.find('./channel/title').text
  315. playlist_desc_el = doc.find('./channel/description')
  316. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  317. entries = [{
  318. '_type': 'url',
  319. 'url': e.find('link').text,
  320. 'title': e.find('title').text,
  321. } for e in doc.findall('./channel/item')]
  322. return {
  323. '_type': 'playlist',
  324. 'id': url,
  325. 'title': playlist_title,
  326. 'description': playlist_desc,
  327. 'entries': entries,
  328. }
  329. def _real_extract(self, url):
  330. if url.startswith('//'):
  331. return {
  332. '_type': 'url',
  333. 'url': self.http_scheme() + url,
  334. }
  335. parsed_url = compat_urlparse.urlparse(url)
  336. if not parsed_url.scheme:
  337. default_search = self._downloader.params.get('default_search')
  338. if default_search is None:
  339. default_search = 'auto_warning'
  340. if default_search in ('auto', 'auto_warning'):
  341. if '/' in url:
  342. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  343. return self.url_result('http://' + url)
  344. else:
  345. if default_search == 'auto_warning':
  346. self._downloader.report_warning(
  347. 'Falling back to youtube search for %s . Set --default-search to "auto" to suppress this warning.' % url)
  348. return self.url_result('ytsearch:' + url)
  349. else:
  350. assert ':' in default_search
  351. return self.url_result(default_search + url)
  352. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  353. self.to_screen('%s: Requesting header' % video_id)
  354. try:
  355. response = self._send_head(url)
  356. # Check for redirect
  357. new_url = response.geturl()
  358. if url != new_url:
  359. self.report_following_redirect(new_url)
  360. return self.url_result(new_url)
  361. # Check for direct link to a video
  362. content_type = response.headers.get('Content-Type', '')
  363. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  364. if m:
  365. upload_date = response.headers.get('Last-Modified')
  366. if upload_date:
  367. upload_date = unified_strdate(upload_date)
  368. return {
  369. 'id': video_id,
  370. 'title': os.path.splitext(url_basename(url))[0],
  371. 'formats': [{
  372. 'format_id': m.group('format_id'),
  373. 'url': url,
  374. 'vcodec': 'none' if m.group('type') == 'audio' else None
  375. }],
  376. 'upload_date': upload_date,
  377. }
  378. except compat_urllib_error.HTTPError:
  379. # This may be a stupid server that doesn't like HEAD, our UA, or so
  380. pass
  381. try:
  382. webpage = self._download_webpage(url, video_id)
  383. except ValueError:
  384. # since this is the last-resort InfoExtractor, if
  385. # this error is thrown, it'll be thrown here
  386. raise ExtractorError('Failed to download URL: %s' % url)
  387. self.report_extraction(video_id)
  388. # Is it an RSS feed?
  389. try:
  390. doc = parse_xml(webpage)
  391. if doc.tag == 'rss':
  392. return self._extract_rss(url, video_id, doc)
  393. except compat_xml_parse_error:
  394. pass
  395. # Sometimes embedded video player is hidden behind percent encoding
  396. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  397. # Unescaping the whole page allows to handle those cases in a generic way
  398. webpage = compat_urllib_parse.unquote(webpage)
  399. # it's tempting to parse this further, but you would
  400. # have to take into account all the variations like
  401. # Video Title - Site Name
  402. # Site Name | Video Title
  403. # Video Title - Tagline | Site Name
  404. # and so on and so forth; it's just not practical
  405. video_title = self._html_search_regex(
  406. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  407. default='video')
  408. # video uploader is domain name
  409. video_uploader = self._search_regex(
  410. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  411. # Look for BrightCove:
  412. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  413. if bc_urls:
  414. self.to_screen('Brightcove video detected.')
  415. entries = [{
  416. '_type': 'url',
  417. 'url': smuggle_url(bc_url, {'Referer': url}),
  418. 'ie_key': 'Brightcove'
  419. } for bc_url in bc_urls]
  420. return {
  421. '_type': 'playlist',
  422. 'title': video_title,
  423. 'id': video_id,
  424. 'entries': entries,
  425. }
  426. # Look for embedded (iframe) Vimeo player
  427. mobj = re.search(
  428. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  429. if mobj:
  430. player_url = unescapeHTML(mobj.group('url'))
  431. surl = smuggle_url(player_url, {'Referer': url})
  432. return self.url_result(surl, 'Vimeo')
  433. # Look for embedded (swf embed) Vimeo player
  434. mobj = re.search(
  435. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  436. if mobj:
  437. return self.url_result(mobj.group(1), 'Vimeo')
  438. # Look for embedded YouTube player
  439. matches = re.findall(r'''(?x)
  440. (?:<iframe[^>]+?src=|embedSWF\(\s*)
  441. (["\'])(?P<url>(?:https?:)?//(?:www\.)?youtube\.com/
  442. (?:embed|v)/.+?)
  443. \1''', webpage)
  444. if matches:
  445. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Youtube')
  446. for tuppl in matches]
  447. return self.playlist_result(
  448. urlrs, playlist_id=video_id, playlist_title=video_title)
  449. # Look for embedded Dailymotion player
  450. matches = re.findall(
  451. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  452. if matches:
  453. urlrs = [self.url_result(unescapeHTML(tuppl[1]))
  454. for tuppl in matches]
  455. return self.playlist_result(
  456. urlrs, playlist_id=video_id, playlist_title=video_title)
  457. # Look for embedded Wistia player
  458. match = re.search(
  459. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  460. if match:
  461. return {
  462. '_type': 'url_transparent',
  463. 'url': unescapeHTML(match.group('url')),
  464. 'ie_key': 'Wistia',
  465. 'uploader': video_uploader,
  466. 'title': video_title,
  467. 'id': video_id,
  468. }
  469. # Look for embedded blip.tv player
  470. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  471. if mobj:
  472. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  473. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9]+)', webpage)
  474. if mobj:
  475. return self.url_result(mobj.group(1), 'BlipTV')
  476. # Look for embedded condenast player
  477. matches = re.findall(
  478. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  479. webpage)
  480. if matches:
  481. return {
  482. '_type': 'playlist',
  483. 'entries': [{
  484. '_type': 'url',
  485. 'ie_key': 'CondeNast',
  486. 'url': ma,
  487. } for ma in matches],
  488. 'title': video_title,
  489. 'id': video_id,
  490. }
  491. # Look for Bandcamp pages with custom domain
  492. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  493. if mobj is not None:
  494. burl = unescapeHTML(mobj.group(1))
  495. # Don't set the extractor because it can be a track url or an album
  496. return self.url_result(burl)
  497. # Look for embedded Vevo player
  498. mobj = re.search(
  499. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  500. if mobj is not None:
  501. return self.url_result(mobj.group('url'))
  502. # Look for Ooyala videos
  503. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  504. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  505. if mobj is not None:
  506. return OoyalaIE._build_url_result(mobj.group('ec'))
  507. # Look for Aparat videos
  508. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  509. if mobj is not None:
  510. return self.url_result(mobj.group(1), 'Aparat')
  511. # Look for MPORA videos
  512. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  513. if mobj is not None:
  514. return self.url_result(mobj.group(1), 'Mpora')
  515. # Look for embedded NovaMov-based player
  516. mobj = re.search(
  517. r'''(?x)<iframe[^>]+?src=(["\'])
  518. (?P<url>http://(?:(?:embed|www)\.)?
  519. (?:novamov\.com|
  520. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  521. videoweed\.(?:es|com)|
  522. movshare\.(?:net|sx|ag)|
  523. divxstage\.(?:eu|net|ch|co|at|ag))
  524. /embed\.php.+?)\1''', webpage)
  525. if mobj is not None:
  526. return self.url_result(mobj.group('url'))
  527. # Look for embedded Facebook player
  528. mobj = re.search(
  529. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  530. if mobj is not None:
  531. return self.url_result(mobj.group('url'), 'Facebook')
  532. # Look for embedded VK player
  533. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  534. if mobj is not None:
  535. return self.url_result(mobj.group('url'), 'VK')
  536. # Look for embedded Huffington Post player
  537. mobj = re.search(
  538. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  539. if mobj is not None:
  540. return self.url_result(mobj.group('url'), 'HuffPost')
  541. # Look for embed.ly
  542. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  543. if mobj is not None:
  544. return self.url_result(mobj.group('url'))
  545. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  546. if mobj is not None:
  547. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  548. # Look for funnyordie embed
  549. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  550. if matches:
  551. urlrs = [self.url_result(unescapeHTML(eurl), 'FunnyOrDie')
  552. for eurl in matches]
  553. return self.playlist_result(
  554. urlrs, playlist_id=video_id, playlist_title=video_title)
  555. # Look for embedded RUTV player
  556. rutv_url = RUTVIE._extract_url(webpage)
  557. if rutv_url:
  558. return self.url_result(rutv_url, 'RUTV')
  559. # Look for embedded TED player
  560. mobj = re.search(
  561. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  562. if mobj is not None:
  563. return self.url_result(mobj.group('url'), 'TED')
  564. # Look for embedded Ustream videos
  565. mobj = re.search(
  566. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  567. if mobj is not None:
  568. return self.url_result(mobj.group('url'), 'Ustream')
  569. # Look for embedded arte.tv player
  570. mobj = re.search(
  571. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  572. webpage)
  573. if mobj is not None:
  574. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  575. # Look for embedded smotri.com player
  576. smotri_url = SmotriIE._extract_url(webpage)
  577. if smotri_url:
  578. return self.url_result(smotri_url, 'Smotri')
  579. # Look for embeded soundcloud player
  580. mobj = re.search(
  581. r'<iframe src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  582. webpage)
  583. if mobj is not None:
  584. url = unescapeHTML(mobj.group('url'))
  585. return self.url_result(url)
  586. # Start with something easy: JW Player in SWFObject
  587. found = re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  588. if not found:
  589. # Look for gorilla-vid style embedding
  590. found = re.findall(r'''(?sx)
  591. (?:
  592. jw_plugins|
  593. JWPlayerOptions|
  594. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  595. )
  596. .*?file\s*:\s*["\'](.*?)["\']''', webpage)
  597. if not found:
  598. # Broaden the search a little bit
  599. found = re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  600. if not found:
  601. # Broaden the findall a little bit: JWPlayer JS loader
  602. found = re.findall(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  603. if not found:
  604. # Try to find twitter cards info
  605. found = re.findall(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  606. if not found:
  607. # We look for Open Graph info:
  608. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  609. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  610. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  611. if m_video_type is not None:
  612. found = re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)
  613. if not found:
  614. # HTML5 video
  615. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage)
  616. if not found:
  617. found = re.findall(
  618. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  619. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'([^\']+)\'"',
  620. webpage)
  621. if found:
  622. new_url = found.group(1)
  623. self.report_following_redirect(new_url)
  624. return {
  625. '_type': 'url',
  626. 'url': new_url,
  627. }
  628. if not found:
  629. raise ExtractorError('Unsupported URL: %s' % url)
  630. entries = []
  631. for video_url in found:
  632. video_url = compat_urlparse.urljoin(url, video_url)
  633. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  634. # Sometimes, jwplayer extraction will result in a YouTube URL
  635. if YoutubeIE.suitable(video_url):
  636. entries.append(self.url_result(video_url, 'Youtube'))
  637. continue
  638. # here's a fun little line of code for you:
  639. video_id = os.path.splitext(video_id)[0]
  640. entries.append({
  641. 'id': video_id,
  642. 'url': video_url,
  643. 'uploader': video_uploader,
  644. 'title': video_title,
  645. })
  646. if len(entries) == 1:
  647. return entries[0]
  648. else:
  649. for num, e in enumerate(entries, start=1):
  650. e['title'] = '%s (%d)' % (e['title'], num)
  651. return {
  652. '_type': 'playlist',
  653. 'entries': entries,
  654. }