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.

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