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.

1009 lines
40 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 ..compat import (
  8. compat_urllib_parse,
  9. compat_urlparse,
  10. compat_xml_parse_error,
  11. )
  12. from ..utils import (
  13. determine_ext,
  14. ExtractorError,
  15. float_or_none,
  16. HEADRequest,
  17. orderedSet,
  18. parse_xml,
  19. smuggle_url,
  20. unescapeHTML,
  21. unified_strdate,
  22. unsmuggle_url,
  23. url_basename,
  24. )
  25. from .brightcove import BrightcoveIE
  26. from .ooyala import OoyalaIE
  27. from .rutv import RUTVIE
  28. from .smotri import SmotriIE
  29. from .condenast import CondeNastIE
  30. class GenericIE(InfoExtractor):
  31. IE_DESC = 'Generic downloader that works on some sites'
  32. _VALID_URL = r'.*'
  33. IE_NAME = 'generic'
  34. _TESTS = [
  35. {
  36. 'url': 'http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html',
  37. 'md5': '85b90ccc9d73b4acd9138d3af4c27f89',
  38. 'info_dict': {
  39. 'id': '13601338388002',
  40. 'ext': 'mp4',
  41. 'uploader': 'www.hodiho.fr',
  42. 'title': 'R\u00e9gis plante sa Jeep',
  43. }
  44. },
  45. # bandcamp page with custom domain
  46. {
  47. 'add_ie': ['Bandcamp'],
  48. 'url': 'http://bronyrock.com/track/the-pony-mash',
  49. 'info_dict': {
  50. 'id': '3235767654',
  51. 'ext': 'mp3',
  52. 'title': 'The Pony Mash',
  53. 'uploader': 'M_Pallante',
  54. },
  55. 'skip': 'There is a limit of 200 free downloads / month for the test song',
  56. },
  57. # embedded brightcove video
  58. # it also tests brightcove videos that need to set the 'Referer' in the
  59. # http requests
  60. {
  61. 'add_ie': ['Brightcove'],
  62. 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
  63. 'info_dict': {
  64. 'id': '2765128793001',
  65. 'ext': 'mp4',
  66. 'title': 'Le cours de bourse : l’analyse technique',
  67. 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
  68. 'uploader': 'BFM BUSINESS',
  69. },
  70. 'params': {
  71. 'skip_download': True,
  72. },
  73. },
  74. {
  75. # https://github.com/rg3/youtube-dl/issues/2253
  76. 'url': 'http://bcove.me/i6nfkrc3',
  77. 'md5': '0ba9446db037002366bab3b3eb30c88c',
  78. 'info_dict': {
  79. 'id': '3101154703001',
  80. 'ext': 'mp4',
  81. 'title': 'Still no power',
  82. 'uploader': 'thestar.com',
  83. '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.',
  84. },
  85. 'add_ie': ['Brightcove'],
  86. },
  87. {
  88. 'url': 'http://www.championat.com/video/football/v/87/87499.html',
  89. 'md5': 'fb973ecf6e4a78a67453647444222983',
  90. 'info_dict': {
  91. 'id': '3414141473001',
  92. 'ext': 'mp4',
  93. 'title': 'Видео. Удаление Дзагоева (ЦСКА)',
  94. 'description': 'Онлайн-трансляция матча ЦСКА - "Волга"',
  95. 'uploader': 'Championat',
  96. },
  97. },
  98. {
  99. 'add_ie': ['Brightcove'],
  100. 'url': 'http://www.kijk.nl/sbs6/leermijvrouwenkennen/videos/jqMiXKAYan2S/aflevering-1',
  101. 'info_dict': {
  102. 'id': '3866516442001',
  103. 'ext': 'flv',
  104. 'title': 'Leer mij vrouwen kennen: Aflevering 1',
  105. 'description': 'Leer mij vrouwen kennen: Aflevering 1',
  106. 'uploader': 'SBS Broadcasting',
  107. },
  108. 'params': {
  109. 'skip_download': True,
  110. },
  111. },
  112. # Direct link to a video
  113. {
  114. 'url': 'http://media.w3.org/2010/05/sintel/trailer.mp4',
  115. 'md5': '67d406c2bcb6af27fa886f31aa934bbe',
  116. 'info_dict': {
  117. 'id': 'trailer',
  118. 'ext': 'mp4',
  119. 'title': 'trailer',
  120. 'upload_date': '20100513',
  121. }
  122. },
  123. # ooyala video
  124. {
  125. 'url': 'http://www.rollingstone.com/music/videos/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-20131219',
  126. 'md5': '5644c6ca5d5782c1d0d350dad9bd840c',
  127. 'info_dict': {
  128. 'id': 'BwY2RxaTrTkslxOfcan0UCf0YqyvWysJ',
  129. 'ext': 'mp4',
  130. 'title': '2cc213299525360.mov', # that's what we get
  131. },
  132. },
  133. # google redirect
  134. {
  135. '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',
  136. 'info_dict': {
  137. 'id': 'cmQHVoWB5FY',
  138. 'ext': 'mp4',
  139. 'upload_date': '20130224',
  140. 'uploader_id': 'TheVerge',
  141. '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.',
  142. 'uploader': 'The Verge',
  143. 'title': 'First Firefox OS phones side-by-side',
  144. },
  145. 'params': {
  146. 'skip_download': False,
  147. }
  148. },
  149. # embed.ly video
  150. {
  151. 'url': 'http://www.tested.com/science/weird/460206-tested-grinding-coffee-2000-frames-second/',
  152. 'info_dict': {
  153. 'id': '9ODmcdjQcHQ',
  154. 'ext': 'mp4',
  155. 'title': 'Tested: Grinding Coffee at 2000 Frames Per Second',
  156. 'upload_date': '20140225',
  157. 'description': 'md5:06a40fbf30b220468f1e0957c0f558ff',
  158. 'uploader': 'Tested',
  159. 'uploader_id': 'testedcom',
  160. },
  161. # No need to test YoutubeIE here
  162. 'params': {
  163. 'skip_download': True,
  164. },
  165. },
  166. # funnyordie embed
  167. {
  168. 'url': 'http://www.theguardian.com/world/2014/mar/11/obama-zach-galifianakis-between-two-ferns',
  169. 'info_dict': {
  170. 'id': '18e820ec3f',
  171. 'ext': 'mp4',
  172. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  173. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  174. },
  175. },
  176. # RUTV embed
  177. {
  178. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  179. 'info_dict': {
  180. 'id': '776940',
  181. 'ext': 'mp4',
  182. 'title': 'Охотское море стало целиком российским',
  183. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  184. },
  185. 'params': {
  186. # m3u8 download
  187. 'skip_download': True,
  188. },
  189. },
  190. # Embedded TED video
  191. {
  192. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  193. 'md5': '65fdff94098e4a607385a60c5177c638',
  194. 'info_dict': {
  195. 'id': '1969',
  196. 'ext': 'mp4',
  197. 'title': 'Hidden miracles of the natural world',
  198. 'uploader': 'Louie Schwartzberg',
  199. 'description': 'md5:8145d19d320ff3e52f28401f4c4283b9',
  200. }
  201. },
  202. # Embeded Ustream video
  203. {
  204. 'url': 'http://www.american.edu/spa/pti/nsa-privacy-janus-2014.cfm',
  205. 'md5': '27b99cdb639c9b12a79bca876a073417',
  206. 'info_dict': {
  207. 'id': '45734260',
  208. 'ext': 'flv',
  209. 'uploader': 'AU SPA: The NSA and Privacy',
  210. 'title': 'NSA and Privacy Forum Debate featuring General Hayden and Barton Gellman'
  211. }
  212. },
  213. # nowvideo embed hidden behind percent encoding
  214. {
  215. 'url': 'http://www.waoanime.tv/the-super-dimension-fortress-macross-episode-1/',
  216. 'md5': '2baf4ddd70f697d94b1c18cf796d5107',
  217. 'info_dict': {
  218. 'id': '06e53103ca9aa',
  219. 'ext': 'flv',
  220. 'title': 'Macross Episode 001 Watch Macross Episode 001 onl',
  221. 'description': 'No description',
  222. },
  223. },
  224. # arte embed
  225. {
  226. 'url': 'http://www.tv-replay.fr/redirection/20-03-14/x-enius-arte-10753389.html',
  227. 'md5': '7653032cbb25bf6c80d80f217055fa43',
  228. 'info_dict': {
  229. 'id': '048195-004_PLUS7-F',
  230. 'ext': 'flv',
  231. 'title': 'X:enius',
  232. 'description': 'md5:d5fdf32ef6613cdbfd516ae658abf168',
  233. 'upload_date': '20140320',
  234. },
  235. 'params': {
  236. 'skip_download': 'Requires rtmpdump'
  237. }
  238. },
  239. # Condé Nast embed
  240. {
  241. 'url': 'http://www.wired.com/2014/04/honda-asimo/',
  242. 'md5': 'ba0dfe966fa007657bd1443ee672db0f',
  243. 'info_dict': {
  244. 'id': '53501be369702d3275860000',
  245. 'ext': 'mp4',
  246. 'title': 'Honda’s New Asimo Robot Is More Human Than Ever',
  247. }
  248. },
  249. # Dailymotion embed
  250. {
  251. 'url': 'http://www.spi0n.com/zap-spi0n-com-n216/',
  252. 'md5': '441aeeb82eb72c422c7f14ec533999cd',
  253. 'info_dict': {
  254. 'id': 'k2mm4bCdJ6CQ2i7c8o2',
  255. 'ext': 'mp4',
  256. 'title': 'Le Zap de Spi0n n°216 - Zapping du Web',
  257. 'uploader': 'Spi0n',
  258. },
  259. 'add_ie': ['Dailymotion'],
  260. },
  261. # YouTube embed
  262. {
  263. 'url': 'http://www.badzine.de/ansicht/datum/2014/06/09/so-funktioniert-die-neue-englische-badminton-liga.html',
  264. 'info_dict': {
  265. 'id': 'FXRb4ykk4S0',
  266. 'ext': 'mp4',
  267. 'title': 'The NBL Auction 2014',
  268. 'uploader': 'BADMINTON England',
  269. 'uploader_id': 'BADMINTONEvents',
  270. 'upload_date': '20140603',
  271. 'description': 'md5:9ef128a69f1e262a700ed83edb163a73',
  272. },
  273. 'add_ie': ['Youtube'],
  274. 'params': {
  275. 'skip_download': True,
  276. }
  277. },
  278. # MTVSercices embed
  279. {
  280. 'url': 'http://www.gametrailers.com/news-post/76093/north-america-europe-is-getting-that-mario-kart-8-mercedes-dlc-too',
  281. 'md5': '35727f82f58c76d996fc188f9755b0d5',
  282. 'info_dict': {
  283. 'id': '0306a69b-8adf-4fb5-aace-75f8e8cbfca9',
  284. 'ext': 'mp4',
  285. 'title': 'Review',
  286. 'description': 'Mario\'s life in the fast lane has never looked so good.',
  287. },
  288. },
  289. # YouTube embed via <data-embed-url="">
  290. {
  291. 'url': 'https://play.google.com/store/apps/details?id=com.gameloft.android.ANMP.GloftA8HM',
  292. 'info_dict': {
  293. 'id': '4vAffPZIT44',
  294. 'ext': 'mp4',
  295. 'title': 'Asphalt 8: Airborne - Update - Welcome to Dubai!',
  296. 'uploader': 'Gameloft',
  297. 'uploader_id': 'gameloft',
  298. 'upload_date': '20140828',
  299. 'description': 'md5:c80da9ed3d83ae6d1876c834de03e1c4',
  300. },
  301. 'params': {
  302. 'skip_download': True,
  303. }
  304. },
  305. # Camtasia studio
  306. {
  307. 'url': 'http://www.ll.mit.edu/workshops/education/videocourses/antennas/lecture1/video/',
  308. 'playlist': [{
  309. 'md5': '0c5e352edabf715d762b0ad4e6d9ee67',
  310. 'info_dict': {
  311. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  312. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - video1',
  313. 'ext': 'flv',
  314. 'duration': 2235.90,
  315. }
  316. }, {
  317. 'md5': '10e4bb3aaca9fd630e273ff92d9f3c63',
  318. 'info_dict': {
  319. 'id': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final_PIP',
  320. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final - pip',
  321. 'ext': 'flv',
  322. 'duration': 2235.93,
  323. }
  324. }],
  325. 'info_dict': {
  326. 'title': 'Fenn-AA_PA_Radar_Course_Lecture_1c_Final',
  327. }
  328. },
  329. # Flowplayer
  330. {
  331. 'url': 'http://www.handjobhub.com/video/busty-blonde-siri-tit-fuck-while-wank-6313.html',
  332. 'md5': '9d65602bf31c6e20014319c7d07fba27',
  333. 'info_dict': {
  334. 'id': '5123ea6d5e5a7',
  335. 'ext': 'mp4',
  336. 'age_limit': 18,
  337. 'uploader': 'www.handjobhub.com',
  338. 'title': 'Busty Blonde Siri Tit Fuck While Wank at HandjobHub.com',
  339. }
  340. },
  341. # RSS feed
  342. {
  343. 'url': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  344. 'info_dict': {
  345. 'id': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  346. 'title': 'Zero Punctuation',
  347. 'description': 're:'
  348. },
  349. 'playlist_mincount': 11,
  350. },
  351. # Multiple brightcove videos
  352. # https://github.com/rg3/youtube-dl/issues/2283
  353. {
  354. 'url': 'http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html',
  355. 'info_dict': {
  356. 'id': 'always-never',
  357. 'title': 'Always / Never - The New Yorker',
  358. },
  359. 'playlist_count': 3,
  360. 'params': {
  361. 'extract_flat': False,
  362. 'skip_download': True,
  363. }
  364. },
  365. # MLB embed
  366. {
  367. 'url': 'http://umpire-empire.com/index.php/topic/58125-laz-decides-no-thats-low/',
  368. 'md5': '96f09a37e44da40dd083e12d9a683327',
  369. 'info_dict': {
  370. 'id': '33322633',
  371. 'ext': 'mp4',
  372. 'title': 'Ump changes call to ball',
  373. 'description': 'md5:71c11215384298a172a6dcb4c2e20685',
  374. 'duration': 48,
  375. 'timestamp': 1401537900,
  376. 'upload_date': '20140531',
  377. 'thumbnail': 're:^https?://.*\.jpg$',
  378. },
  379. },
  380. # Wistia embed
  381. {
  382. 'url': 'http://education-portal.com/academy/lesson/north-american-exploration-failed-colonies-of-spain-france-england.html#lesson',
  383. 'md5': '8788b683c777a5cf25621eaf286d0c23',
  384. 'info_dict': {
  385. 'id': '1cfaf6b7ea',
  386. 'ext': 'mov',
  387. 'title': 'md5:51364a8d3d009997ba99656004b5e20d',
  388. 'duration': 643.0,
  389. 'filesize': 182808282,
  390. 'uploader': 'education-portal.com',
  391. },
  392. },
  393. {
  394. 'url': 'http://thoughtworks.wistia.com/medias/uxjb0lwrcz',
  395. 'md5': 'baf49c2baa8a7de5f3fc145a8506dcd4',
  396. 'info_dict': {
  397. 'id': 'uxjb0lwrcz',
  398. 'ext': 'mp4',
  399. 'title': 'Conversation about Hexagonal Rails Part 1 - ThoughtWorks',
  400. 'duration': 1715.0,
  401. 'uploader': 'thoughtworks.wistia.com',
  402. },
  403. },
  404. # Direct download with broken HEAD
  405. {
  406. 'url': 'http://ai-radio.org:8000/radio.opus',
  407. 'info_dict': {
  408. 'id': 'radio',
  409. 'ext': 'opus',
  410. 'title': 'radio',
  411. },
  412. 'params': {
  413. 'skip_download': True, # infinite live stream
  414. },
  415. 'expected_warnings': [
  416. r'501.*Not Implemented'
  417. ],
  418. },
  419. # Soundcloud embed
  420. {
  421. 'url': 'http://nakedsecurity.sophos.com/2014/10/29/sscc-171-are-you-sure-that-1234-is-a-bad-password-podcast/',
  422. 'info_dict': {
  423. 'id': '174391317',
  424. 'ext': 'mp3',
  425. 'description': 'md5:ff867d6b555488ad3c52572bb33d432c',
  426. 'uploader': 'Sophos Security',
  427. 'title': 'Chet Chat 171 - Oct 29, 2014',
  428. 'upload_date': '20141029',
  429. }
  430. }
  431. ]
  432. def report_following_redirect(self, new_url):
  433. """Report information extraction."""
  434. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  435. def _extract_rss(self, url, video_id, doc):
  436. playlist_title = doc.find('./channel/title').text
  437. playlist_desc_el = doc.find('./channel/description')
  438. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  439. entries = [{
  440. '_type': 'url',
  441. 'url': e.find('link').text,
  442. 'title': e.find('title').text,
  443. } for e in doc.findall('./channel/item')]
  444. return {
  445. '_type': 'playlist',
  446. 'id': url,
  447. 'title': playlist_title,
  448. 'description': playlist_desc,
  449. 'entries': entries,
  450. }
  451. def _extract_camtasia(self, url, video_id, webpage):
  452. """ Returns None if no camtasia video can be found. """
  453. camtasia_cfg = self._search_regex(
  454. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  455. webpage, 'camtasia configuration file', default=None)
  456. if camtasia_cfg is None:
  457. return None
  458. title = self._html_search_meta('DC.title', webpage, fatal=True)
  459. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  460. camtasia_cfg = self._download_xml(
  461. camtasia_url, video_id,
  462. note='Downloading camtasia configuration',
  463. errnote='Failed to download camtasia configuration')
  464. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  465. entries = []
  466. for n in fileset_node.getchildren():
  467. url_n = n.find('./uri')
  468. if url_n is None:
  469. continue
  470. entries.append({
  471. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  472. 'title': '%s - %s' % (title, n.tag),
  473. 'url': compat_urlparse.urljoin(url, url_n.text),
  474. 'duration': float_or_none(n.find('./duration').text),
  475. })
  476. return {
  477. '_type': 'playlist',
  478. 'entries': entries,
  479. 'title': title,
  480. }
  481. def _real_extract(self, url):
  482. if url.startswith('//'):
  483. return {
  484. '_type': 'url',
  485. 'url': self.http_scheme() + url,
  486. }
  487. parsed_url = compat_urlparse.urlparse(url)
  488. if not parsed_url.scheme:
  489. default_search = self._downloader.params.get('default_search')
  490. if default_search is None:
  491. default_search = 'fixup_error'
  492. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  493. if '/' in url:
  494. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  495. return self.url_result('http://' + url)
  496. elif default_search != 'fixup_error':
  497. if default_search == 'auto_warning':
  498. if re.match(r'^(?:url|URL)$', url):
  499. raise ExtractorError(
  500. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  501. expected=True)
  502. else:
  503. self._downloader.report_warning(
  504. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  505. return self.url_result('ytsearch:' + url)
  506. if default_search in ('error', 'fixup_error'):
  507. raise ExtractorError(
  508. ('%r is not a valid URL. '
  509. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  510. ) % (url, url), expected=True)
  511. else:
  512. if ':' not in default_search:
  513. default_search += ':'
  514. return self.url_result(default_search + url)
  515. url, smuggled_data = unsmuggle_url(url)
  516. force_videoid = None
  517. is_intentional = smuggled_data and smuggled_data.get('to_generic')
  518. if smuggled_data and 'force_videoid' in smuggled_data:
  519. force_videoid = smuggled_data['force_videoid']
  520. video_id = force_videoid
  521. else:
  522. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  523. self.to_screen('%s: Requesting header' % video_id)
  524. head_req = HEADRequest(url)
  525. head_response = self._request_webpage(
  526. head_req, video_id,
  527. note=False, errnote='Could not send HEAD request to %s' % url,
  528. fatal=False)
  529. if head_response is not False:
  530. # Check for redirect
  531. new_url = head_response.geturl()
  532. if url != new_url:
  533. self.report_following_redirect(new_url)
  534. if force_videoid:
  535. new_url = smuggle_url(
  536. new_url, {'force_videoid': force_videoid})
  537. return self.url_result(new_url)
  538. full_response = None
  539. if head_response is False:
  540. full_response = self._request_webpage(url, video_id)
  541. head_response = full_response
  542. # Check for direct link to a video
  543. content_type = head_response.headers.get('Content-Type', '')
  544. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  545. if m:
  546. upload_date = unified_strdate(
  547. head_response.headers.get('Last-Modified'))
  548. return {
  549. 'id': video_id,
  550. 'title': os.path.splitext(url_basename(url))[0],
  551. 'formats': [{
  552. 'format_id': m.group('format_id'),
  553. 'url': url,
  554. 'vcodec': 'none' if m.group('type') == 'audio' else None
  555. }],
  556. 'upload_date': upload_date,
  557. }
  558. if not self._downloader.params.get('test', False) and not is_intentional:
  559. self._downloader.report_warning('Falling back on generic information extractor.')
  560. if full_response:
  561. webpage = self._webpage_read_content(full_response, url, video_id)
  562. else:
  563. webpage = self._download_webpage(url, video_id)
  564. self.report_extraction(video_id)
  565. # Is it an RSS feed?
  566. try:
  567. doc = parse_xml(webpage)
  568. if doc.tag == 'rss':
  569. return self._extract_rss(url, video_id, doc)
  570. except compat_xml_parse_error:
  571. pass
  572. # Is it a Camtasia project?
  573. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  574. if camtasia_res is not None:
  575. return camtasia_res
  576. # Sometimes embedded video player is hidden behind percent encoding
  577. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  578. # Unescaping the whole page allows to handle those cases in a generic way
  579. webpage = compat_urllib_parse.unquote(webpage)
  580. # it's tempting to parse this further, but you would
  581. # have to take into account all the variations like
  582. # Video Title - Site Name
  583. # Site Name | Video Title
  584. # Video Title - Tagline | Site Name
  585. # and so on and so forth; it's just not practical
  586. video_title = self._html_search_regex(
  587. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  588. default='video')
  589. # Try to detect age limit automatically
  590. age_limit = self._rta_search(webpage)
  591. # And then there are the jokers who advertise that they use RTA,
  592. # but actually don't.
  593. AGE_LIMIT_MARKERS = [
  594. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  595. ]
  596. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  597. age_limit = 18
  598. # video uploader is domain name
  599. video_uploader = self._search_regex(
  600. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  601. # Helper method
  602. def _playlist_from_matches(matches, getter, ie=None):
  603. urlrs = orderedSet(
  604. self.url_result(self._proto_relative_url(getter(m)), ie)
  605. for m in matches)
  606. return self.playlist_result(
  607. urlrs, playlist_id=video_id, playlist_title=video_title)
  608. # Look for BrightCove:
  609. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  610. if bc_urls:
  611. self.to_screen('Brightcove video detected.')
  612. entries = [{
  613. '_type': 'url',
  614. 'url': smuggle_url(bc_url, {'Referer': url}),
  615. 'ie_key': 'Brightcove'
  616. } for bc_url in bc_urls]
  617. return {
  618. '_type': 'playlist',
  619. 'title': video_title,
  620. 'id': video_id,
  621. 'entries': entries,
  622. }
  623. # Look for embedded (iframe) Vimeo player
  624. mobj = re.search(
  625. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  626. if mobj:
  627. player_url = unescapeHTML(mobj.group('url'))
  628. surl = smuggle_url(player_url, {'Referer': url})
  629. return self.url_result(surl)
  630. # Look for embedded (swf embed) Vimeo player
  631. mobj = re.search(
  632. r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  633. if mobj:
  634. return self.url_result(mobj.group(1))
  635. # Look for embedded YouTube player
  636. matches = re.findall(r'''(?x)
  637. (?:
  638. <iframe[^>]+?src=|
  639. data-video-url=|
  640. <embed[^>]+?src=|
  641. embedSWF\(?:\s*|
  642. new\s+SWFObject\(
  643. )
  644. (["\'])
  645. (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
  646. (?:embed|v|p)/.+?)
  647. \1''', webpage)
  648. if matches:
  649. return _playlist_from_matches(
  650. matches, lambda m: unescapeHTML(m[1]))
  651. # Look for embedded Dailymotion player
  652. matches = re.findall(
  653. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  654. if matches:
  655. return _playlist_from_matches(
  656. matches, lambda m: unescapeHTML(m[1]))
  657. # Look for embedded Dailymotion playlist player (#3822)
  658. m = re.search(
  659. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.[a-z]{2,3}/widget/jukebox\?.+?)\1', webpage)
  660. if m:
  661. playlists = re.findall(
  662. r'list\[\]=/playlist/([^/]+)/', unescapeHTML(m.group('url')))
  663. if playlists:
  664. return _playlist_from_matches(
  665. playlists, lambda p: '//dailymotion.com/playlist/%s' % p)
  666. # Look for embedded Wistia player
  667. match = re.search(
  668. r'<(?:meta[^>]+?content|iframe[^>]+?src)=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  669. if match:
  670. embed_url = self._proto_relative_url(
  671. unescapeHTML(match.group('url')))
  672. return {
  673. '_type': 'url_transparent',
  674. 'url': embed_url,
  675. 'ie_key': 'Wistia',
  676. 'uploader': video_uploader,
  677. 'title': video_title,
  678. 'id': video_id,
  679. }
  680. match = re.search(r'(?:id=["\']wistia_|data-wistia-?id=["\']|Wistia\.embed\(["\'])(?P<id>[^"\']+)', webpage)
  681. if match:
  682. return {
  683. '_type': 'url_transparent',
  684. 'url': 'http://fast.wistia.net/embed/iframe/{0:}'.format(match.group('id')),
  685. 'ie_key': 'Wistia',
  686. 'uploader': video_uploader,
  687. 'title': video_title,
  688. 'id': match.group('id')
  689. }
  690. # Look for embedded blip.tv player
  691. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  692. if mobj:
  693. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  694. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  695. if mobj:
  696. return self.url_result(mobj.group(1), 'BlipTV')
  697. # Look for embedded condenast player
  698. matches = re.findall(
  699. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  700. webpage)
  701. if matches:
  702. return {
  703. '_type': 'playlist',
  704. 'entries': [{
  705. '_type': 'url',
  706. 'ie_key': 'CondeNast',
  707. 'url': ma,
  708. } for ma in matches],
  709. 'title': video_title,
  710. 'id': video_id,
  711. }
  712. # Look for Bandcamp pages with custom domain
  713. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  714. if mobj is not None:
  715. burl = unescapeHTML(mobj.group(1))
  716. # Don't set the extractor because it can be a track url or an album
  717. return self.url_result(burl)
  718. # Look for embedded Vevo player
  719. mobj = re.search(
  720. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  721. if mobj is not None:
  722. return self.url_result(mobj.group('url'))
  723. # Look for Ooyala videos
  724. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  725. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  726. if mobj is not None:
  727. return OoyalaIE._build_url_result(mobj.group('ec'))
  728. # Look for Aparat videos
  729. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  730. if mobj is not None:
  731. return self.url_result(mobj.group(1), 'Aparat')
  732. # Look for MPORA videos
  733. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  734. if mobj is not None:
  735. return self.url_result(mobj.group(1), 'Mpora')
  736. # Look for embedded NovaMov-based player
  737. mobj = re.search(
  738. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  739. (?P<url>http://(?:(?:embed|www)\.)?
  740. (?:novamov\.com|
  741. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  742. videoweed\.(?:es|com)|
  743. movshare\.(?:net|sx|ag)|
  744. divxstage\.(?:eu|net|ch|co|at|ag))
  745. /embed\.php.+?)\1''', webpage)
  746. if mobj is not None:
  747. return self.url_result(mobj.group('url'))
  748. # Look for embedded Facebook player
  749. mobj = re.search(
  750. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  751. if mobj is not None:
  752. return self.url_result(mobj.group('url'), 'Facebook')
  753. # Look for embedded VK player
  754. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  755. if mobj is not None:
  756. return self.url_result(mobj.group('url'), 'VK')
  757. # Look for embedded ivi player
  758. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  759. if mobj is not None:
  760. return self.url_result(mobj.group('url'), 'Ivi')
  761. # Look for embedded Huffington Post player
  762. mobj = re.search(
  763. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  764. if mobj is not None:
  765. return self.url_result(mobj.group('url'), 'HuffPost')
  766. # Look for embed.ly
  767. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  768. if mobj is not None:
  769. return self.url_result(mobj.group('url'))
  770. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  771. if mobj is not None:
  772. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  773. # Look for funnyordie embed
  774. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  775. if matches:
  776. return _playlist_from_matches(
  777. matches, getter=unescapeHTML, ie='FunnyOrDie')
  778. # Look for embedded RUTV player
  779. rutv_url = RUTVIE._extract_url(webpage)
  780. if rutv_url:
  781. return self.url_result(rutv_url, 'RUTV')
  782. # Look for embedded TED player
  783. mobj = re.search(
  784. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  785. if mobj is not None:
  786. return self.url_result(mobj.group('url'), 'TED')
  787. # Look for embedded Ustream videos
  788. mobj = re.search(
  789. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  790. if mobj is not None:
  791. return self.url_result(mobj.group('url'), 'Ustream')
  792. # Look for embedded arte.tv player
  793. mobj = re.search(
  794. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  795. webpage)
  796. if mobj is not None:
  797. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  798. # Look for embedded smotri.com player
  799. smotri_url = SmotriIE._extract_url(webpage)
  800. if smotri_url:
  801. return self.url_result(smotri_url, 'Smotri')
  802. # Look for embeded soundcloud player
  803. mobj = re.search(
  804. r'<iframe\s+(?:[a-zA-Z0-9_-]+="[^"]+"\s+)*src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  805. webpage)
  806. if mobj is not None:
  807. url = unescapeHTML(mobj.group('url'))
  808. return self.url_result(url)
  809. # Look for embedded vulture.com player
  810. mobj = re.search(
  811. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  812. webpage)
  813. if mobj is not None:
  814. url = unescapeHTML(mobj.group('url'))
  815. return self.url_result(url, ie='Vulture')
  816. # Look for embedded mtvservices player
  817. mobj = re.search(
  818. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  819. webpage)
  820. if mobj is not None:
  821. url = unescapeHTML(mobj.group('url'))
  822. return self.url_result(url, ie='MTVServicesEmbedded')
  823. # Look for embedded yahoo player
  824. mobj = re.search(
  825. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  826. webpage)
  827. if mobj is not None:
  828. return self.url_result(mobj.group('url'), 'Yahoo')
  829. # Look for embedded sbs.com.au player
  830. mobj = re.search(
  831. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)sbs\.com\.au/ondemand/video/single/.+?)\1',
  832. webpage)
  833. if mobj is not None:
  834. return self.url_result(mobj.group('url'), 'SBS')
  835. mobj = re.search(
  836. r'<iframe[^>]+?src=(["\'])(?P<url>https?://m(?:lb)?\.mlb\.com/shared/video/embed/embed\.html\?.+?)\1',
  837. webpage)
  838. if mobj is not None:
  839. return self.url_result(mobj.group('url'), 'MLB')
  840. mobj = re.search(
  841. r'<iframe[^>]+?src=(["\'])(?P<url>%s)\1' % CondeNastIE.EMBED_URL,
  842. webpage)
  843. if mobj is not None:
  844. return self.url_result(self._proto_relative_url(mobj.group('url'), scheme='http:'), 'CondeNast')
  845. def check_video(vurl):
  846. vpath = compat_urlparse.urlparse(vurl).path
  847. vext = determine_ext(vpath)
  848. return '.' in vpath and vext not in ('swf', 'png', 'jpg', 'srt', 'sbv', 'sub', 'vtt', 'ttml')
  849. def filter_video(urls):
  850. return list(filter(check_video, urls))
  851. # Start with something easy: JW Player in SWFObject
  852. found = filter_video(re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage))
  853. if not found:
  854. # Look for gorilla-vid style embedding
  855. found = filter_video(re.findall(r'''(?sx)
  856. (?:
  857. jw_plugins|
  858. JWPlayerOptions|
  859. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  860. )
  861. .*?file\s*:\s*["\'](.*?)["\']''', webpage))
  862. if not found:
  863. # Broaden the search a little bit
  864. found = filter_video(re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage))
  865. if not found:
  866. # Broaden the findall a little bit: JWPlayer JS loader
  867. found = filter_video(re.findall(
  868. r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage))
  869. if not found:
  870. # Flow player
  871. found = filter_video(re.findall(r'''(?xs)
  872. flowplayer\("[^"]+",\s*
  873. \{[^}]+?\}\s*,
  874. \s*{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  875. ["']?url["']?\s*:\s*["']([^"']+)["']
  876. ''', webpage))
  877. if not found:
  878. # Try to find twitter cards info
  879. found = filter_video(re.findall(
  880. r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage))
  881. if not found:
  882. # We look for Open Graph info:
  883. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  884. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  885. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  886. if m_video_type is not None:
  887. found = filter_video(re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage))
  888. if not found:
  889. # HTML5 video
  890. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source[^>]*)?\s+src="([^"]+)"', webpage)
  891. if not found:
  892. found = re.search(
  893. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  894. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'?([^\'"]+)',
  895. webpage)
  896. if found:
  897. new_url = found.group(1)
  898. self.report_following_redirect(new_url)
  899. return {
  900. '_type': 'url',
  901. 'url': new_url,
  902. }
  903. if not found:
  904. raise ExtractorError('Unsupported URL: %s' % url)
  905. entries = []
  906. for video_url in found:
  907. video_url = compat_urlparse.urljoin(url, video_url)
  908. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  909. # Sometimes, jwplayer extraction will result in a YouTube URL
  910. if YoutubeIE.suitable(video_url):
  911. entries.append(self.url_result(video_url, 'Youtube'))
  912. continue
  913. # here's a fun little line of code for you:
  914. video_id = os.path.splitext(video_id)[0]
  915. entries.append({
  916. 'id': video_id,
  917. 'url': video_url,
  918. 'uploader': video_uploader,
  919. 'title': video_title,
  920. 'age_limit': age_limit,
  921. })
  922. if len(entries) == 1:
  923. return entries[0]
  924. else:
  925. for num, e in enumerate(entries, start=1):
  926. e['title'] = '%s (%d)' % (e['title'], num)
  927. return {
  928. '_type': 'playlist',
  929. 'entries': entries,
  930. }