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.

994 lines
39 KiB

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