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.

929 lines
37 KiB

10 years ago
10 years ago
10 years ago
10 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_parse,
  9. compat_urlparse,
  10. compat_xml_parse_error,
  11. determine_ext,
  12. ExtractorError,
  13. float_or_none,
  14. HEADRequest,
  15. orderedSet,
  16. parse_xml,
  17. smuggle_url,
  18. unescapeHTML,
  19. unified_strdate,
  20. unsmuggle_url,
  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. 'info_dict': {
  153. 'id': '18e820ec3f',
  154. 'ext': 'mp4',
  155. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  156. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  157. },
  158. },
  159. # RUTV embed
  160. {
  161. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  162. 'info_dict': {
  163. 'id': '776940',
  164. 'ext': 'mp4',
  165. 'title': 'Охотское море стало целиком российским',
  166. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  167. },
  168. 'params': {
  169. # m3u8 download
  170. 'skip_download': True,
  171. },
  172. },
  173. # Embedded TED video
  174. {
  175. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  176. 'md5': '65fdff94098e4a607385a60c5177c638',
  177. 'info_dict': {
  178. 'id': '1969',
  179. 'ext': 'mp4',
  180. 'title': 'Hidden miracles of the natural world',
  181. 'uploader': 'Louie Schwartzberg',
  182. 'description': 'md5:8145d19d320ff3e52f28401f4c4283b9',
  183. }
  184. },
  185. # Embeded Ustream video
  186. {
  187. 'url': 'http://www.american.edu/spa/pti/nsa-privacy-janus-2014.cfm',
  188. 'md5': '27b99cdb639c9b12a79bca876a073417',
  189. 'info_dict': {
  190. 'id': '45734260',
  191. 'ext': 'flv',
  192. 'uploader': 'AU SPA: The NSA and Privacy',
  193. 'title': 'NSA and Privacy Forum Debate featuring General Hayden and Barton Gellman'
  194. }
  195. },
  196. # nowvideo embed hidden behind percent encoding
  197. {
  198. 'url': 'http://www.waoanime.tv/the-super-dimension-fortress-macross-episode-1/',
  199. 'md5': '2baf4ddd70f697d94b1c18cf796d5107',
  200. 'info_dict': {
  201. 'id': '06e53103ca9aa',
  202. 'ext': 'flv',
  203. 'title': 'Macross Episode 001 Watch Macross Episode 001 onl',
  204. 'description': 'No description',
  205. },
  206. },
  207. # arte embed
  208. {
  209. 'url': 'http://www.tv-replay.fr/redirection/20-03-14/x-enius-arte-10753389.html',
  210. 'md5': '7653032cbb25bf6c80d80f217055fa43',
  211. 'info_dict': {
  212. 'id': '048195-004_PLUS7-F',
  213. 'ext': 'flv',
  214. 'title': 'X:enius',
  215. 'description': 'md5:d5fdf32ef6613cdbfd516ae658abf168',
  216. 'upload_date': '20140320',
  217. },
  218. 'params': {
  219. 'skip_download': 'Requires rtmpdump'
  220. }
  221. },
  222. # Condé Nast embed
  223. {
  224. 'url': 'http://www.wired.com/2014/04/honda-asimo/',
  225. 'md5': 'ba0dfe966fa007657bd1443ee672db0f',
  226. 'info_dict': {
  227. 'id': '53501be369702d3275860000',
  228. 'ext': 'mp4',
  229. 'title': 'Honda’s New Asimo Robot Is More Human Than Ever',
  230. }
  231. },
  232. # Dailymotion embed
  233. {
  234. 'url': 'http://www.spi0n.com/zap-spi0n-com-n216/',
  235. 'md5': '441aeeb82eb72c422c7f14ec533999cd',
  236. 'info_dict': {
  237. 'id': 'k2mm4bCdJ6CQ2i7c8o2',
  238. 'ext': 'mp4',
  239. 'title': 'Le Zap de Spi0n n°216 - Zapping du Web',
  240. 'uploader': 'Spi0n',
  241. },
  242. 'add_ie': ['Dailymotion'],
  243. },
  244. # YouTube embed
  245. {
  246. 'url': 'http://www.badzine.de/ansicht/datum/2014/06/09/so-funktioniert-die-neue-englische-badminton-liga.html',
  247. 'info_dict': {
  248. 'id': 'FXRb4ykk4S0',
  249. 'ext': 'mp4',
  250. 'title': 'The NBL Auction 2014',
  251. 'uploader': 'BADMINTON England',
  252. 'uploader_id': 'BADMINTONEvents',
  253. 'upload_date': '20140603',
  254. 'description': 'md5:9ef128a69f1e262a700ed83edb163a73',
  255. },
  256. 'add_ie': ['Youtube'],
  257. 'params': {
  258. 'skip_download': True,
  259. }
  260. },
  261. # MTVSercices embed
  262. {
  263. 'url': 'http://www.gametrailers.com/news-post/76093/north-america-europe-is-getting-that-mario-kart-8-mercedes-dlc-too',
  264. 'md5': '35727f82f58c76d996fc188f9755b0d5',
  265. 'info_dict': {
  266. 'id': '0306a69b-8adf-4fb5-aace-75f8e8cbfca9',
  267. 'ext': 'mp4',
  268. 'title': 'Review',
  269. 'description': 'Mario\'s life in the fast lane has never looked so good.',
  270. },
  271. },
  272. # YouTube embed via <data-embed-url="">
  273. {
  274. 'url': 'https://play.google.com/store/apps/details?id=com.gameloft.android.ANMP.GloftA8HM',
  275. 'info_dict': {
  276. 'id': '4vAffPZIT44',
  277. 'ext': 'mp4',
  278. 'title': 'Asphalt 8: Airborne - Update - Welcome to Dubai!',
  279. 'uploader': 'Gameloft',
  280. 'uploader_id': 'gameloft',
  281. 'upload_date': '20140828',
  282. 'description': 'md5:c80da9ed3d83ae6d1876c834de03e1c4',
  283. },
  284. 'params': {
  285. 'skip_download': True,
  286. }
  287. },
  288. # Camtasia studio
  289. {
  290. 'url': 'http://www.ll.mit.edu/workshops/education/videocourses/antennas/lecture1/video/',
  291. 'playlist': [{
  292. 'md5': '0c5e352edabf715d762b0ad4e6d9ee67',
  293. 'info_dict': {
  294. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  295. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - video1',
  296. 'ext': 'flv',
  297. 'duration': 2235.90,
  298. }
  299. }, {
  300. 'md5': '10e4bb3aaca9fd630e273ff92d9f3c63',
  301. 'info_dict': {
  302. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final_PIP',
  303. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - pip',
  304. 'ext': 'flv',
  305. 'duration': 2235.93,
  306. }
  307. }],
  308. 'info_dict': {
  309. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  310. }
  311. },
  312. # Flowplayer
  313. {
  314. 'url': 'http://www.handjobhub.com/video/busty-blonde-siri-tit-fuck-while-wank-6313.html',
  315. 'md5': '9d65602bf31c6e20014319c7d07fba27',
  316. 'info_dict': {
  317. 'id': '5123ea6d5e5a7',
  318. 'ext': 'mp4',
  319. 'age_limit': 18,
  320. 'uploader': 'www.handjobhub.com',
  321. 'title': 'Busty Blonde Siri Tit Fuck While Wank at Handjob Hub',
  322. }
  323. },
  324. # RSS feed
  325. {
  326. 'url': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  327. 'info_dict': {
  328. 'id': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  329. 'title': 'Zero Punctuation',
  330. 'description': 're:'
  331. },
  332. 'playlist_mincount': 11,
  333. },
  334. # Multiple brightcove videos
  335. # https://github.com/rg3/youtube-dl/issues/2283
  336. {
  337. 'url': 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html',
  338. 'info_dict': {
  339. 'id': 'always-never',
  340. 'title': 'Always / Never - The New Yorker',
  341. },
  342. 'playlist_count': 3,
  343. 'params': {
  344. 'extract_flat': False,
  345. 'skip_download': True,
  346. }
  347. },
  348. # MLB embed
  349. {
  350. 'url': 'http://umpire-empire.com/index.php/topic/58125-laz-decides-no-thats-low/',
  351. 'md5': '96f09a37e44da40dd083e12d9a683327',
  352. 'info_dict': {
  353. 'id': '33322633',
  354. 'ext': 'mp4',
  355. 'title': 'Ump changes call to ball',
  356. 'description': 'md5:71c11215384298a172a6dcb4c2e20685',
  357. 'duration': 48,
  358. 'timestamp': 1401537900,
  359. 'upload_date': '20140531',
  360. 'thumbnail': 're:^https?://.*\.jpg$',
  361. },
  362. },
  363. # Wistia embed
  364. {
  365. 'url': 'http://education-portal.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
  366. 'md5': '8788b683c777a5cf25621eaf286d0c23',
  367. 'info_dict': {
  368. 'id': '1cfaf6b7ea',
  369. 'ext': 'mov',
  370. 'title': 'md5:51364a8d3d009997ba99656004b5e20d',
  371. 'duration': 643.0,
  372. 'filesize': 182808282,
  373. 'uploader': 'education-portal.com',
  374. },
  375. },
  376. ]
  377. def report_following_redirect(self, new_url):
  378. """Report information extraction."""
  379. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  380. def _extract_rss(self, url, video_id, doc):
  381. playlist_title = doc.find('./channel/title').text
  382. playlist_desc_el = doc.find('./channel/description')
  383. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  384. entries = [{
  385. '_type': 'url',
  386. 'url': e.find('link').text,
  387. 'title': e.find('title').text,
  388. } for e in doc.findall('./channel/item')]
  389. return {
  390. '_type': 'playlist',
  391. 'id': url,
  392. 'title': playlist_title,
  393. 'description': playlist_desc,
  394. 'entries': entries,
  395. }
  396. def _extract_camtasia(self, url, video_id, webpage):
  397. """ Returns None if no camtasia video can be found. """
  398. camtasia_cfg = self._search_regex(
  399. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  400. webpage, 'camtasia configuration file', default=None)
  401. if camtasia_cfg is None:
  402. return None
  403. title = self._html_search_meta('DC.title', webpage, fatal=True)
  404. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  405. camtasia_cfg = self._download_xml(
  406. camtasia_url, video_id,
  407. note='Downloading camtasia configuration',
  408. errnote='Failed to download camtasia configuration')
  409. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  410. entries = []
  411. for n in fileset_node.getchildren():
  412. url_n = n.find('./uri')
  413. if url_n is None:
  414. continue
  415. entries.append({
  416. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  417. 'title': '%s - %s' % (title, n.tag),
  418. 'url': compat_urlparse.urljoin(url, url_n.text),
  419. 'duration': float_or_none(n.find('./duration').text),
  420. })
  421. return {
  422. '_type': 'playlist',
  423. 'entries': entries,
  424. 'title': title,
  425. }
  426. def _real_extract(self, url):
  427. if url.startswith('//'):
  428. return {
  429. '_type': 'url',
  430. 'url': self.http_scheme() + url,
  431. }
  432. parsed_url = compat_urlparse.urlparse(url)
  433. if not parsed_url.scheme:
  434. default_search = self._downloader.params.get('default_search')
  435. if default_search is None:
  436. default_search = 'fixup_error'
  437. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  438. if '/' in url:
  439. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  440. return self.url_result('http://' + url)
  441. elif default_search != 'fixup_error':
  442. if default_search == 'auto_warning':
  443. if re.match(r'^(?:url|URL)$', url):
  444. raise ExtractorError(
  445. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  446. expected=True)
  447. else:
  448. self._downloader.report_warning(
  449. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  450. return self.url_result('ytsearch:' + url)
  451. if default_search in ('error', 'fixup_error'):
  452. raise ExtractorError(
  453. ('%r is not a valid URL. '
  454. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  455. ) % (url, url), expected=True)
  456. else:
  457. assert ':' in default_search
  458. return self.url_result(default_search + url)
  459. url, smuggled_data = unsmuggle_url(url)
  460. force_videoid = None
  461. is_intentional = smuggled_data and smuggled_data.get('to_generic')
  462. if smuggled_data and 'force_videoid' in smuggled_data:
  463. force_videoid = smuggled_data['force_videoid']
  464. video_id = force_videoid
  465. else:
  466. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  467. self.to_screen('%s: Requesting header' % video_id)
  468. head_req = HEADRequest(url)
  469. response = self._request_webpage(
  470. head_req, video_id,
  471. note=False, errnote='Could not send HEAD request to %s' % url,
  472. fatal=False)
  473. if response is not False:
  474. # Check for redirect
  475. new_url = response.geturl()
  476. if url != new_url:
  477. self.report_following_redirect(new_url)
  478. if force_videoid:
  479. new_url = smuggle_url(
  480. new_url, {'force_videoid': force_videoid})
  481. return self.url_result(new_url)
  482. # Check for direct link to a video
  483. content_type = response.headers.get('Content-Type', '')
  484. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  485. if m:
  486. upload_date = response.headers.get('Last-Modified')
  487. if upload_date:
  488. upload_date = unified_strdate(upload_date)
  489. return {
  490. 'id': video_id,
  491. 'title': os.path.splitext(url_basename(url))[0],
  492. 'formats': [{
  493. 'format_id': m.group('format_id'),
  494. 'url': url,
  495. 'vcodec': 'none' if m.group('type') == 'audio' else None
  496. }],
  497. 'upload_date': upload_date,
  498. }
  499. if not self._downloader.params.get('test', False) and not is_intentional:
  500. self._downloader.report_warning('Falling back on generic information extractor.')
  501. try:
  502. webpage = self._download_webpage(url, video_id)
  503. except ValueError:
  504. # since this is the last-resort InfoExtractor, if
  505. # this error is thrown, it'll be thrown here
  506. raise ExtractorError('Failed to download URL: %s' % url)
  507. self.report_extraction(video_id)
  508. # Is it an RSS feed?
  509. try:
  510. doc = parse_xml(webpage)
  511. if doc.tag == 'rss':
  512. return self._extract_rss(url, video_id, doc)
  513. except compat_xml_parse_error:
  514. pass
  515. # Is it a Camtasia project?
  516. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  517. if camtasia_res is not None:
  518. return camtasia_res
  519. # Sometimes embedded video player is hidden behind percent encoding
  520. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  521. # Unescaping the whole page allows to handle those cases in a generic way
  522. webpage = compat_urllib_parse.unquote(webpage)
  523. # it's tempting to parse this further, but you would
  524. # have to take into account all the variations like
  525. # Video Title - Site Name
  526. # Site Name | Video Title
  527. # Video Title - Tagline | Site Name
  528. # and so on and so forth; it's just not practical
  529. video_title = self._html_search_regex(
  530. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  531. default='video')
  532. # Try to detect age limit automatically
  533. age_limit = self._rta_search(webpage)
  534. # And then there are the jokers who advertise that they use RTA,
  535. # but actually don't.
  536. AGE_LIMIT_MARKERS = [
  537. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  538. ]
  539. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  540. age_limit = 18
  541. # video uploader is domain name
  542. video_uploader = self._search_regex(
  543. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  544. # Helper method
  545. def _playlist_from_matches(matches, getter, ie=None):
  546. urlrs = orderedSet(
  547. self.url_result(self._proto_relative_url(getter(m)), ie)
  548. for m in matches)
  549. return self.playlist_result(
  550. urlrs, playlist_id=video_id, playlist_title=video_title)
  551. # Look for BrightCove:
  552. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  553. if bc_urls:
  554. self.to_screen('Brightcove video detected.')
  555. entries = [{
  556. '_type': 'url',
  557. 'url': smuggle_url(bc_url, {'Referer': url}),
  558. 'ie_key': 'Brightcove'
  559. } for bc_url in bc_urls]
  560. return {
  561. '_type': 'playlist',
  562. 'title': video_title,
  563. 'id': video_id,
  564. 'entries': entries,
  565. }
  566. # Look for embedded (iframe) Vimeo player
  567. mobj = re.search(
  568. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  569. if mobj:
  570. player_url = unescapeHTML(mobj.group('url'))
  571. surl = smuggle_url(player_url, {'Referer': url})
  572. return self.url_result(surl, 'Vimeo')
  573. # Look for embedded (swf embed) Vimeo player
  574. mobj = re.search(
  575. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  576. if mobj:
  577. return self.url_result(mobj.group(1), 'Vimeo')
  578. # Look for embedded YouTube player
  579. matches = re.findall(r'''(?x)
  580. (?:
  581. <iframe[^>]+?src=|
  582. data-video-url=|
  583. <embed[^>]+?src=|
  584. embedSWF\(?:\s*
  585. )
  586. (["\'])
  587. (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
  588. (?:embed|v|p)/.+?)
  589. \1''', webpage)
  590. if matches:
  591. return _playlist_from_matches(
  592. matches, lambda m: unescapeHTML(m[1]))
  593. # Look for embedded Dailymotion player
  594. matches = re.findall(
  595. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  596. if matches:
  597. return _playlist_from_matches(
  598. matches, lambda m: unescapeHTML(m[1]))
  599. # Look for embedded Wistia player
  600. match = re.search(
  601. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  602. if match:
  603. return {
  604. '_type': 'url_transparent',
  605. 'url': unescapeHTML(match.group('url')),
  606. 'ie_key': 'Wistia',
  607. 'uploader': video_uploader,
  608. 'title': video_title,
  609. 'id': video_id,
  610. }
  611. match = re.search(r'(?:id=["\']wistia_|data-wistiaid=["\']|Wistia\.embed\(["\'])(?P<id>[^"\']+)', webpage)
  612. if match:
  613. return {
  614. '_type': 'url_transparent',
  615. 'url': 'http://fast.wistia.net/embed/iframe/{0:}'.format(match.group('id')),
  616. 'ie_key': 'Wistia',
  617. 'uploader': video_uploader,
  618. 'title': video_title,
  619. 'id': match.group('id')
  620. }
  621. # Look for embedded blip.tv player
  622. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  623. if mobj:
  624. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  625. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  626. if mobj:
  627. return self.url_result(mobj.group(1), 'BlipTV')
  628. # Look for embedded condenast player
  629. matches = re.findall(
  630. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  631. webpage)
  632. if matches:
  633. return {
  634. '_type': 'playlist',
  635. 'entries': [{
  636. '_type': 'url',
  637. 'ie_key': 'CondeNast',
  638. 'url': ma,
  639. } for ma in matches],
  640. 'title': video_title,
  641. 'id': video_id,
  642. }
  643. # Look for Bandcamp pages with custom domain
  644. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  645. if mobj is not None:
  646. burl = unescapeHTML(mobj.group(1))
  647. # Don't set the extractor because it can be a track url or an album
  648. return self.url_result(burl)
  649. # Look for embedded Vevo player
  650. mobj = re.search(
  651. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  652. if mobj is not None:
  653. return self.url_result(mobj.group('url'))
  654. # Look for Ooyala videos
  655. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  656. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  657. if mobj is not None:
  658. return OoyalaIE._build_url_result(mobj.group('ec'))
  659. # Look for Aparat videos
  660. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  661. if mobj is not None:
  662. return self.url_result(mobj.group(1), 'Aparat')
  663. # Look for MPORA videos
  664. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  665. if mobj is not None:
  666. return self.url_result(mobj.group(1), 'Mpora')
  667. # Look for embedded NovaMov-based player
  668. mobj = re.search(
  669. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  670. (?P<url>http://(?:(?:embed|www)\.)?
  671. (?:novamov\.com|
  672. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  673. videoweed\.(?:es|com)|
  674. movshare\.(?:net|sx|ag)|
  675. divxstage\.(?:eu|net|ch|co|at|ag))
  676. /embed\.php.+?)\1''', webpage)
  677. if mobj is not None:
  678. return self.url_result(mobj.group('url'))
  679. # Look for embedded Facebook player
  680. mobj = re.search(
  681. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  682. if mobj is not None:
  683. return self.url_result(mobj.group('url'), 'Facebook')
  684. # Look for embedded VK player
  685. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  686. if mobj is not None:
  687. return self.url_result(mobj.group('url'), 'VK')
  688. # Look for embedded ivi player
  689. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  690. if mobj is not None:
  691. return self.url_result(mobj.group('url'), 'Ivi')
  692. # Look for embedded Huffington Post player
  693. mobj = re.search(
  694. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  695. if mobj is not None:
  696. return self.url_result(mobj.group('url'), 'HuffPost')
  697. # Look for embed.ly
  698. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  699. if mobj is not None:
  700. return self.url_result(mobj.group('url'))
  701. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  702. if mobj is not None:
  703. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  704. # Look for funnyordie embed
  705. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  706. if matches:
  707. return _playlist_from_matches(
  708. matches, getter=unescapeHTML, ie='FunnyOrDie')
  709. # Look for embedded RUTV player
  710. rutv_url = RUTVIE._extract_url(webpage)
  711. if rutv_url:
  712. return self.url_result(rutv_url, 'RUTV')
  713. # Look for embedded TED player
  714. mobj = re.search(
  715. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  716. if mobj is not None:
  717. return self.url_result(mobj.group('url'), 'TED')
  718. # Look for embedded Ustream videos
  719. mobj = re.search(
  720. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  721. if mobj is not None:
  722. return self.url_result(mobj.group('url'), 'Ustream')
  723. # Look for embedded arte.tv player
  724. mobj = re.search(
  725. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  726. webpage)
  727. if mobj is not None:
  728. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  729. # Look for embedded smotri.com player
  730. smotri_url = SmotriIE._extract_url(webpage)
  731. if smotri_url:
  732. return self.url_result(smotri_url, 'Smotri')
  733. # Look for embeded soundcloud player
  734. mobj = re.search(
  735. r'<iframe src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  736. webpage)
  737. if mobj is not None:
  738. url = unescapeHTML(mobj.group('url'))
  739. return self.url_result(url)
  740. # Look for embedded vulture.com player
  741. mobj = re.search(
  742. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  743. webpage)
  744. if mobj is not None:
  745. url = unescapeHTML(mobj.group('url'))
  746. return self.url_result(url, ie='Vulture')
  747. # Look for embedded mtvservices player
  748. mobj = re.search(
  749. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  750. webpage)
  751. if mobj is not None:
  752. url = unescapeHTML(mobj.group('url'))
  753. return self.url_result(url, ie='MTVServicesEmbedded')
  754. # Look for embedded yahoo player
  755. mobj = re.search(
  756. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  757. webpage)
  758. if mobj is not None:
  759. return self.url_result(mobj.group('url'), 'Yahoo')
  760. # Look for embedded sbs.com.au player
  761. mobj = re.search(
  762. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)sbs\.com\.au/ondemand/video/single/.+?)\1',
  763. webpage)
  764. if mobj is not None:
  765. return self.url_result(mobj.group('url'), 'SBS')
  766. mobj = re.search(
  767. r'<iframe[^>]+?src=(["\'])(?P<url>https?://m\.mlb\.com/shared/video/embed/embed\.html\?.+?)\1',
  768. webpage)
  769. if mobj is not None:
  770. return self.url_result(mobj.group('url'), 'MLB')
  771. # Start with something easy: JW Player in SWFObject
  772. found = re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  773. if not found:
  774. # Look for gorilla-vid style embedding
  775. found = re.findall(r'''(?sx)
  776. (?:
  777. jw_plugins|
  778. JWPlayerOptions|
  779. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  780. )
  781. .*?file\s*:\s*["\'](.*?)["\']''', webpage)
  782. if not found:
  783. # Broaden the search a little bit
  784. found = re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  785. if not found:
  786. # Broaden the findall a little bit: JWPlayer JS loader
  787. found = re.findall(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  788. if not found:
  789. # Flow player
  790. found = re.findall(r'''(?xs)
  791. flowplayer\("[^"]+",\s*
  792. \{[^}]+?\}\s*,
  793. \s*{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  794. ["']?url["']?\s*:\s*["']([^"']+)["']
  795. ''', webpage)
  796. if not found:
  797. # Try to find twitter cards info
  798. found = re.findall(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  799. if not found:
  800. # We look for Open Graph info:
  801. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  802. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  803. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  804. if m_video_type is not None:
  805. def check_video(vurl):
  806. vpath = compat_urlparse.urlparse(vurl).path
  807. vext = determine_ext(vpath)
  808. return '.' in vpath and vext not in ('swf', 'png', 'jpg')
  809. found = list(filter(
  810. check_video,
  811. re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)))
  812. if not found:
  813. # HTML5 video
  814. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source[^>]+)? src="([^"]+)"', webpage)
  815. if not found:
  816. found = re.search(
  817. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  818. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'?([^\'"]+)',
  819. webpage)
  820. if found:
  821. new_url = found.group(1)
  822. self.report_following_redirect(new_url)
  823. return {
  824. '_type': 'url',
  825. 'url': new_url,
  826. }
  827. if not found:
  828. raise ExtractorError('Unsupported URL: %s' % url)
  829. entries = []
  830. for video_url in found:
  831. video_url = compat_urlparse.urljoin(url, video_url)
  832. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  833. # Sometimes, jwplayer extraction will result in a YouTube URL
  834. if YoutubeIE.suitable(video_url):
  835. entries.append(self.url_result(video_url, 'Youtube'))
  836. continue
  837. # here's a fun little line of code for you:
  838. video_id = os.path.splitext(video_id)[0]
  839. entries.append({
  840. 'id': video_id,
  841. 'url': video_url,
  842. 'uploader': video_uploader,
  843. 'title': video_title,
  844. 'age_limit': age_limit,
  845. })
  846. if len(entries) == 1:
  847. return entries[0]
  848. else:
  849. for num, e in enumerate(entries, start=1):
  850. e['title'] = '%s (%d)' % (e['title'], num)
  851. return {
  852. '_type': 'playlist',
  853. 'entries': entries,
  854. }