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.

887 lines
36 KiB

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