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.

1105 lines
43 KiB

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