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.

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