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.

1106 lines
43 KiB

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