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.

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