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.

901 lines
36 KiB

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