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.

876 lines
35 KiB

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