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.

947 lines
37 KiB

10 years ago
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_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. '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. # Flowplayer
  329. {
  330. 'url': 'http://www.handjobhub.com/video/busty-blonde-siri-tit-fuck-while-wank-6313.html',
  331. 'md5': '9d65602bf31c6e20014319c7d07fba27',
  332. 'info_dict': {
  333. 'id': '5123ea6d5e5a7',
  334. 'ext': 'mp4',
  335. 'age_limit': 18,
  336. 'uploader': 'www.handjobhub.com',
  337. 'title': 'Busty Blonde Siri Tit Fuck While Wank at Handjob Hub',
  338. }
  339. },
  340. # RSS feed
  341. {
  342. 'url': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  343. 'info_dict': {
  344. 'id': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  345. 'title': 'Zero Punctuation',
  346. 'description': 're:'
  347. },
  348. 'playlist_mincount': 11,
  349. },
  350. # Multiple brightcove videos
  351. # https://github.com/rg3/youtube-dl/issues/2283
  352. {
  353. 'url': 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html',
  354. 'info_dict': {
  355. 'id': 'always-never',
  356. 'title': 'Always / Never - The New Yorker',
  357. },
  358. 'playlist_count': 3,
  359. 'params': {
  360. 'extract_flat': False,
  361. 'skip_download': True,
  362. }
  363. },
  364. # MLB embed
  365. {
  366. 'url': 'http://umpire-empire.com/index.php/topic/58125-laz-decides-no-thats-low/',
  367. 'md5': '96f09a37e44da40dd083e12d9a683327',
  368. 'info_dict': {
  369. 'id': '33322633',
  370. 'ext': 'mp4',
  371. 'title': 'Ump changes call to ball',
  372. 'description': 'md5:71c11215384298a172a6dcb4c2e20685',
  373. 'duration': 48,
  374. 'timestamp': 1401537900,
  375. 'upload_date': '20140531',
  376. 'thumbnail': 're:^https?://.*\.jpg$',
  377. },
  378. },
  379. # Wistia embed
  380. {
  381. 'url': 'http://education-portal.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
  382. 'md5': '8788b683c777a5cf25621eaf286d0c23',
  383. 'info_dict': {
  384. 'id': '1cfaf6b7ea',
  385. 'ext': 'mov',
  386. 'title': 'md5:51364a8d3d009997ba99656004b5e20d',
  387. 'duration': 643.0,
  388. 'filesize': 182808282,
  389. 'uploader': 'education-portal.com',
  390. },
  391. },
  392. ]
  393. def report_download_webpage(self, video_id):
  394. """Report webpage download."""
  395. if not self._downloader.params.get('test', False):
  396. self._downloader.report_warning('Falling back on generic information extractor.')
  397. super(GenericIE, self).report_download_webpage(video_id)
  398. def report_following_redirect(self, new_url):
  399. """Report information extraction."""
  400. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  401. def _extract_rss(self, url, video_id, doc):
  402. playlist_title = doc.find('./channel/title').text
  403. playlist_desc_el = doc.find('./channel/description')
  404. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  405. entries = [{
  406. '_type': 'url',
  407. 'url': e.find('link').text,
  408. 'title': e.find('title').text,
  409. } for e in doc.findall('./channel/item')]
  410. return {
  411. '_type': 'playlist',
  412. 'id': url,
  413. 'title': playlist_title,
  414. 'description': playlist_desc,
  415. 'entries': entries,
  416. }
  417. def _extract_camtasia(self, url, video_id, webpage):
  418. """ Returns None if no camtasia video can be found. """
  419. camtasia_cfg = self._search_regex(
  420. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  421. webpage, 'camtasia configuration file', default=None)
  422. if camtasia_cfg is None:
  423. return None
  424. title = self._html_search_meta('DC.title', webpage, fatal=True)
  425. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  426. camtasia_cfg = self._download_xml(
  427. camtasia_url, video_id,
  428. note='Downloading camtasia configuration',
  429. errnote='Failed to download camtasia configuration')
  430. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  431. entries = []
  432. for n in fileset_node.getchildren():
  433. url_n = n.find('./uri')
  434. if url_n is None:
  435. continue
  436. entries.append({
  437. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  438. 'title': '%s - %s' % (title, n.tag),
  439. 'url': compat_urlparse.urljoin(url, url_n.text),
  440. 'duration': float_or_none(n.find('./duration').text),
  441. })
  442. return {
  443. '_type': 'playlist',
  444. 'entries': entries,
  445. 'title': title,
  446. }
  447. def _real_extract(self, url):
  448. if url.startswith('//'):
  449. return {
  450. '_type': 'url',
  451. 'url': self.http_scheme() + url,
  452. }
  453. parsed_url = compat_urlparse.urlparse(url)
  454. if not parsed_url.scheme:
  455. default_search = self._downloader.params.get('default_search')
  456. if default_search is None:
  457. default_search = 'fixup_error'
  458. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  459. if '/' in url:
  460. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  461. return self.url_result('http://' + url)
  462. elif default_search != 'fixup_error':
  463. if default_search == 'auto_warning':
  464. if re.match(r'^(?:url|URL)$', url):
  465. raise ExtractorError(
  466. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  467. expected=True)
  468. else:
  469. self._downloader.report_warning(
  470. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  471. return self.url_result('ytsearch:' + url)
  472. if default_search in ('error', 'fixup_error'):
  473. raise ExtractorError(
  474. ('%r is not a valid URL. '
  475. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  476. ) % (url, url), expected=True)
  477. else:
  478. assert ':' in default_search
  479. return self.url_result(default_search + url)
  480. url, smuggled_data = unsmuggle_url(url)
  481. force_videoid = None
  482. if smuggled_data and 'force_videoid' in smuggled_data:
  483. force_videoid = smuggled_data['force_videoid']
  484. video_id = force_videoid
  485. else:
  486. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  487. self.to_screen('%s: Requesting header' % video_id)
  488. head_req = HEADRequest(url)
  489. response = self._request_webpage(
  490. head_req, video_id,
  491. note=False, errnote='Could not send HEAD request to %s' % url,
  492. fatal=False)
  493. if response is not False:
  494. # Check for redirect
  495. new_url = response.geturl()
  496. if url != new_url:
  497. self.report_following_redirect(new_url)
  498. if force_videoid:
  499. new_url = smuggle_url(
  500. new_url, {'force_videoid': force_videoid})
  501. return self.url_result(new_url)
  502. # Check for direct link to a video
  503. content_type = response.headers.get('Content-Type', '')
  504. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  505. if m:
  506. upload_date = response.headers.get('Last-Modified')
  507. if upload_date:
  508. upload_date = unified_strdate(upload_date)
  509. return {
  510. 'id': video_id,
  511. 'title': os.path.splitext(url_basename(url))[0],
  512. 'formats': [{
  513. 'format_id': m.group('format_id'),
  514. 'url': url,
  515. 'vcodec': 'none' if m.group('type') == 'audio' else None
  516. }],
  517. 'upload_date': upload_date,
  518. }
  519. try:
  520. webpage = self._download_webpage(url, video_id)
  521. except ValueError:
  522. # since this is the last-resort InfoExtractor, if
  523. # this error is thrown, it'll be thrown here
  524. raise ExtractorError('Failed to download URL: %s' % url)
  525. self.report_extraction(video_id)
  526. # Is it an RSS feed?
  527. try:
  528. doc = parse_xml(webpage)
  529. if doc.tag == 'rss':
  530. return self._extract_rss(url, video_id, doc)
  531. except compat_xml_parse_error:
  532. pass
  533. # Is it a Camtasia project?
  534. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  535. if camtasia_res is not None:
  536. return camtasia_res
  537. # Sometimes embedded video player is hidden behind percent encoding
  538. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  539. # Unescaping the whole page allows to handle those cases in a generic way
  540. webpage = compat_urllib_parse.unquote(webpage)
  541. # it's tempting to parse this further, but you would
  542. # have to take into account all the variations like
  543. # Video Title - Site Name
  544. # Site Name | Video Title
  545. # Video Title - Tagline | Site Name
  546. # and so on and so forth; it's just not practical
  547. video_title = self._html_search_regex(
  548. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  549. default='video')
  550. # Try to detect age limit automatically
  551. age_limit = self._rta_search(webpage)
  552. # And then there are the jokers who advertise that they use RTA,
  553. # but actually don't.
  554. AGE_LIMIT_MARKERS = [
  555. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  556. ]
  557. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  558. age_limit = 18
  559. # video uploader is domain name
  560. video_uploader = self._search_regex(
  561. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  562. # Helper method
  563. def _playlist_from_matches(matches, getter, ie=None):
  564. urlrs = orderedSet(
  565. self.url_result(self._proto_relative_url(getter(m)), ie)
  566. for m in matches)
  567. return self.playlist_result(
  568. urlrs, playlist_id=video_id, playlist_title=video_title)
  569. # Look for BrightCove:
  570. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  571. if bc_urls:
  572. self.to_screen('Brightcove video detected.')
  573. entries = [{
  574. '_type': 'url',
  575. 'url': smuggle_url(bc_url, {'Referer': url}),
  576. 'ie_key': 'Brightcove'
  577. } for bc_url in bc_urls]
  578. return {
  579. '_type': 'playlist',
  580. 'title': video_title,
  581. 'id': video_id,
  582. 'entries': entries,
  583. }
  584. # Look for embedded (iframe) Vimeo player
  585. mobj = re.search(
  586. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  587. if mobj:
  588. player_url = unescapeHTML(mobj.group('url'))
  589. surl = smuggle_url(player_url, {'Referer': url})
  590. return self.url_result(surl, 'Vimeo')
  591. # Look for embedded (swf embed) Vimeo player
  592. mobj = re.search(
  593. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  594. if mobj:
  595. return self.url_result(mobj.group(1), 'Vimeo')
  596. # Look for embedded YouTube player
  597. matches = re.findall(r'''(?x)
  598. (?:
  599. <iframe[^>]+?src=|
  600. data-video-url=|
  601. <embed[^>]+?src=|
  602. embedSWF\(?:\s*
  603. )
  604. (["\'])
  605. (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
  606. (?:embed|v|p)/.+?)
  607. \1''', webpage)
  608. if matches:
  609. return _playlist_from_matches(
  610. matches, lambda m: unescapeHTML(m[1]))
  611. # Look for embedded Dailymotion player
  612. matches = re.findall(
  613. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  614. if matches:
  615. return _playlist_from_matches(
  616. matches, lambda m: unescapeHTML(m[1]))
  617. # Look for embedded Wistia player
  618. match = re.search(
  619. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  620. if match:
  621. return {
  622. '_type': 'url_transparent',
  623. 'url': unescapeHTML(match.group('url')),
  624. 'ie_key': 'Wistia',
  625. 'uploader': video_uploader,
  626. 'title': video_title,
  627. 'id': video_id,
  628. }
  629. match = re.search(r'(?:id=["\']wistia_|data-wistiaid=["\']|Wistia\.embed\(["\'])(?P<id>[^"\']+)', webpage)
  630. if match:
  631. return {
  632. '_type': 'url_transparent',
  633. 'url': 'http://fast.wistia.net/embed/iframe/{0:}'.format(match.group('id')),
  634. 'ie_key': 'Wistia',
  635. 'uploader': video_uploader,
  636. 'title': video_title,
  637. 'id': match.group('id')
  638. }
  639. # Look for embedded blip.tv player
  640. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  641. if mobj:
  642. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  643. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  644. if mobj:
  645. return self.url_result(mobj.group(1), 'BlipTV')
  646. # Look for embedded condenast player
  647. matches = re.findall(
  648. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  649. webpage)
  650. if matches:
  651. return {
  652. '_type': 'playlist',
  653. 'entries': [{
  654. '_type': 'url',
  655. 'ie_key': 'CondeNast',
  656. 'url': ma,
  657. } for ma in matches],
  658. 'title': video_title,
  659. 'id': video_id,
  660. }
  661. # Look for Bandcamp pages with custom domain
  662. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  663. if mobj is not None:
  664. burl = unescapeHTML(mobj.group(1))
  665. # Don't set the extractor because it can be a track url or an album
  666. return self.url_result(burl)
  667. # Look for embedded Vevo player
  668. mobj = re.search(
  669. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  670. if mobj is not None:
  671. return self.url_result(mobj.group('url'))
  672. # Look for Ooyala videos
  673. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  674. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  675. if mobj is not None:
  676. return OoyalaIE._build_url_result(mobj.group('ec'))
  677. # Look for Aparat videos
  678. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  679. if mobj is not None:
  680. return self.url_result(mobj.group(1), 'Aparat')
  681. # Look for MPORA videos
  682. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  683. if mobj is not None:
  684. return self.url_result(mobj.group(1), 'Mpora')
  685. # Look for embedded NovaMov-based player
  686. mobj = re.search(
  687. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  688. (?P<url>http://(?:(?:embed|www)\.)?
  689. (?:novamov\.com|
  690. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  691. videoweed\.(?:es|com)|
  692. movshare\.(?:net|sx|ag)|
  693. divxstage\.(?:eu|net|ch|co|at|ag))
  694. /embed\.php.+?)\1''', webpage)
  695. if mobj is not None:
  696. return self.url_result(mobj.group('url'))
  697. # Look for embedded Facebook player
  698. mobj = re.search(
  699. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  700. if mobj is not None:
  701. return self.url_result(mobj.group('url'), 'Facebook')
  702. # Look for embedded VK player
  703. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  704. if mobj is not None:
  705. return self.url_result(mobj.group('url'), 'VK')
  706. # Look for embedded ivi player
  707. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  708. if mobj is not None:
  709. return self.url_result(mobj.group('url'), 'Ivi')
  710. # Look for embedded Huffington Post player
  711. mobj = re.search(
  712. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  713. if mobj is not None:
  714. return self.url_result(mobj.group('url'), 'HuffPost')
  715. # Look for embed.ly
  716. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  717. if mobj is not None:
  718. return self.url_result(mobj.group('url'))
  719. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  720. if mobj is not None:
  721. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  722. # Look for funnyordie embed
  723. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  724. if matches:
  725. return _playlist_from_matches(
  726. matches, getter=unescapeHTML, ie='FunnyOrDie')
  727. # Look for embedded RUTV player
  728. rutv_url = RUTVIE._extract_url(webpage)
  729. if rutv_url:
  730. return self.url_result(rutv_url, 'RUTV')
  731. # Look for embedded TED player
  732. mobj = re.search(
  733. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  734. if mobj is not None:
  735. return self.url_result(mobj.group('url'), 'TED')
  736. # Look for embedded Ustream videos
  737. mobj = re.search(
  738. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  739. if mobj is not None:
  740. return self.url_result(mobj.group('url'), 'Ustream')
  741. # Look for embedded arte.tv player
  742. mobj = re.search(
  743. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  744. webpage)
  745. if mobj is not None:
  746. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  747. # Look for embedded smotri.com player
  748. smotri_url = SmotriIE._extract_url(webpage)
  749. if smotri_url:
  750. return self.url_result(smotri_url, 'Smotri')
  751. # Look for embeded soundcloud player
  752. mobj = re.search(
  753. r'<iframe src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  754. webpage)
  755. if mobj is not None:
  756. url = unescapeHTML(mobj.group('url'))
  757. return self.url_result(url)
  758. # Look for embedded vulture.com player
  759. mobj = re.search(
  760. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  761. webpage)
  762. if mobj is not None:
  763. url = unescapeHTML(mobj.group('url'))
  764. return self.url_result(url, ie='Vulture')
  765. # Look for embedded mtvservices player
  766. mobj = re.search(
  767. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  768. webpage)
  769. if mobj is not None:
  770. url = unescapeHTML(mobj.group('url'))
  771. return self.url_result(url, ie='MTVServicesEmbedded')
  772. # Look for embedded yahoo player
  773. mobj = re.search(
  774. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  775. webpage)
  776. if mobj is not None:
  777. return self.url_result(mobj.group('url'), 'Yahoo')
  778. # Look for embedded sbs.com.au player
  779. mobj = re.search(
  780. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)sbs\.com\.au/ondemand/video/single/.+?)\1',
  781. webpage)
  782. if mobj is not None:
  783. return self.url_result(mobj.group('url'), 'SBS')
  784. mobj = re.search(
  785. r'<iframe[^>]+?src=(["\'])(?P<url>https?://m\.mlb\.com/shared/video/embed/embed\.html\?.+?)\1',
  786. webpage)
  787. if mobj is not None:
  788. return self.url_result(mobj.group('url'), 'MLB')
  789. # Start with something easy: JW Player in SWFObject
  790. found = re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  791. if not found:
  792. # Look for gorilla-vid style embedding
  793. found = re.findall(r'''(?sx)
  794. (?:
  795. jw_plugins|
  796. JWPlayerOptions|
  797. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  798. )
  799. .*?file\s*:\s*["\'](.*?)["\']''', webpage)
  800. if not found:
  801. # Broaden the search a little bit
  802. found = re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  803. if not found:
  804. # Broaden the findall a little bit: JWPlayer JS loader
  805. found = re.findall(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  806. if not found:
  807. # Flow player
  808. found = re.findall(r'''(?xs)
  809. flowplayer\("[^"]+",\s*
  810. \{[^}]+?\}\s*,
  811. \s*{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  812. ["']?url["']?\s*:\s*["']([^"']+)["']
  813. ''', webpage)
  814. if not found:
  815. # Try to find twitter cards info
  816. found = re.findall(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  817. if not found:
  818. # We look for Open Graph info:
  819. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  820. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  821. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  822. if m_video_type is not None:
  823. def check_video(vurl):
  824. vpath = compat_urlparse.urlparse(vurl).path
  825. vext = determine_ext(vpath)
  826. return '.' in vpath and vext not in ('swf', 'png', 'jpg')
  827. found = list(filter(
  828. check_video,
  829. re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)))
  830. if not found:
  831. # HTML5 video
  832. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source[^>]+)? src="([^"]+)"', webpage)
  833. if not found:
  834. found = re.search(
  835. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  836. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'?([^\'"]+)',
  837. webpage)
  838. if found:
  839. new_url = found.group(1)
  840. self.report_following_redirect(new_url)
  841. return {
  842. '_type': 'url',
  843. 'url': new_url,
  844. }
  845. if not found:
  846. raise ExtractorError('Unsupported URL: %s' % url)
  847. entries = []
  848. for video_url in found:
  849. video_url = compat_urlparse.urljoin(url, video_url)
  850. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  851. # Sometimes, jwplayer extraction will result in a YouTube URL
  852. if YoutubeIE.suitable(video_url):
  853. entries.append(self.url_result(video_url, 'Youtube'))
  854. continue
  855. # here's a fun little line of code for you:
  856. video_id = os.path.splitext(video_id)[0]
  857. entries.append({
  858. 'id': video_id,
  859. 'url': video_url,
  860. 'uploader': video_uploader,
  861. 'title': video_title,
  862. 'age_limit': age_limit,
  863. })
  864. if len(entries) == 1:
  865. return entries[0]
  866. else:
  867. for num, e in enumerate(entries, start=1):
  868. e['title'] = '%s (%d)' % (e['title'], num)
  869. return {
  870. '_type': 'playlist',
  871. 'entries': entries,
  872. }