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.

885 lines
35 KiB

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. 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. # RSS feed
  340. {
  341. 'url': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  342. 'info_dict': {
  343. 'id': 'http://phihag.de/2014/youtube-dl/rss2.xml',
  344. 'title': 'Zero Punctuation',
  345. 'description': 're:'
  346. },
  347. 'playlist_mincount': 11,
  348. }
  349. ]
  350. def report_download_webpage(self, video_id):
  351. """Report webpage download."""
  352. if not self._downloader.params.get('test', False):
  353. self._downloader.report_warning('Falling back on generic information extractor.')
  354. super(GenericIE, self).report_download_webpage(video_id)
  355. def report_following_redirect(self, new_url):
  356. """Report information extraction."""
  357. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  358. def _extract_rss(self, url, video_id, doc):
  359. playlist_title = doc.find('./channel/title').text
  360. playlist_desc_el = doc.find('./channel/description')
  361. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  362. entries = [{
  363. '_type': 'url',
  364. 'url': e.find('link').text,
  365. 'title': e.find('title').text,
  366. } for e in doc.findall('./channel/item')]
  367. return {
  368. '_type': 'playlist',
  369. 'id': url,
  370. 'title': playlist_title,
  371. 'description': playlist_desc,
  372. 'entries': entries,
  373. }
  374. def _extract_camtasia(self, url, video_id, webpage):
  375. """ Returns None if no camtasia video can be found. """
  376. camtasia_cfg = self._search_regex(
  377. r'fo\.addVariable\(\s*"csConfigFile",\s*"([^"]+)"\s*\);',
  378. webpage, 'camtasia configuration file', default=None)
  379. if camtasia_cfg is None:
  380. return None
  381. title = self._html_search_meta('DC.title', webpage, fatal=True)
  382. camtasia_url = compat_urlparse.urljoin(url, camtasia_cfg)
  383. camtasia_cfg = self._download_xml(
  384. camtasia_url, video_id,
  385. note='Downloading camtasia configuration',
  386. errnote='Failed to download camtasia configuration')
  387. fileset_node = camtasia_cfg.find('./playlist/array/fileset')
  388. entries = []
  389. for n in fileset_node.getchildren():
  390. url_n = n.find('./uri')
  391. if url_n is None:
  392. continue
  393. entries.append({
  394. 'id': os.path.splitext(url_n.text.rpartition('/')[2])[0],
  395. 'title': '%s - %s' % (title, n.tag),
  396. 'url': compat_urlparse.urljoin(url, url_n.text),
  397. 'duration': float_or_none(n.find('./duration').text),
  398. })
  399. return {
  400. '_type': 'playlist',
  401. 'entries': entries,
  402. 'title': title,
  403. }
  404. def _real_extract(self, url):
  405. if url.startswith('//'):
  406. return {
  407. '_type': 'url',
  408. 'url': self.http_scheme() + url,
  409. }
  410. parsed_url = compat_urlparse.urlparse(url)
  411. if not parsed_url.scheme:
  412. default_search = self._downloader.params.get('default_search')
  413. if default_search is None:
  414. default_search = 'fixup_error'
  415. if default_search in ('auto', 'auto_warning', 'fixup_error'):
  416. if '/' in url:
  417. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  418. return self.url_result('http://' + url)
  419. elif default_search != 'fixup_error':
  420. if default_search == 'auto_warning':
  421. if re.match(r'^(?:url|URL)$', url):
  422. raise ExtractorError(
  423. 'Invalid URL: %r . Call youtube-dl like this: youtube-dl -v "https://www.youtube.com/watch?v=BaW_jenozKc" ' % url,
  424. expected=True)
  425. else:
  426. self._downloader.report_warning(
  427. 'Falling back to youtube search for %s . Set --default-search "auto" to suppress this warning.' % url)
  428. return self.url_result('ytsearch:' + url)
  429. if default_search in ('error', 'fixup_error'):
  430. raise ExtractorError(
  431. ('%r is not a valid URL. '
  432. 'Set --default-search "ytsearch" (or run youtube-dl "ytsearch:%s" ) to search YouTube'
  433. ) % (url, url), expected=True)
  434. else:
  435. assert ':' in default_search
  436. return self.url_result(default_search + url)
  437. url, smuggled_data = unsmuggle_url(url)
  438. force_videoid = None
  439. if smuggled_data and 'force_videoid' in smuggled_data:
  440. force_videoid = smuggled_data['force_videoid']
  441. video_id = force_videoid
  442. else:
  443. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  444. self.to_screen('%s: Requesting header' % video_id)
  445. head_req = HEADRequest(url)
  446. response = self._request_webpage(
  447. head_req, video_id,
  448. note=False, errnote='Could not send HEAD request to %s' % url,
  449. fatal=False)
  450. if response is not False:
  451. # Check for redirect
  452. new_url = response.geturl()
  453. if url != new_url:
  454. self.report_following_redirect(new_url)
  455. if force_videoid:
  456. new_url = smuggle_url(
  457. new_url, {'force_videoid': force_videoid})
  458. return self.url_result(new_url)
  459. # Check for direct link to a video
  460. content_type = response.headers.get('Content-Type', '')
  461. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  462. if m:
  463. upload_date = response.headers.get('Last-Modified')
  464. if upload_date:
  465. upload_date = unified_strdate(upload_date)
  466. return {
  467. 'id': video_id,
  468. 'title': os.path.splitext(url_basename(url))[0],
  469. 'formats': [{
  470. 'format_id': m.group('format_id'),
  471. 'url': url,
  472. 'vcodec': 'none' if m.group('type') == 'audio' else None
  473. }],
  474. 'upload_date': upload_date,
  475. }
  476. try:
  477. webpage = self._download_webpage(url, video_id)
  478. except ValueError:
  479. # since this is the last-resort InfoExtractor, if
  480. # this error is thrown, it'll be thrown here
  481. raise ExtractorError('Failed to download URL: %s' % url)
  482. self.report_extraction(video_id)
  483. # Is it an RSS feed?
  484. try:
  485. doc = parse_xml(webpage)
  486. if doc.tag == 'rss':
  487. return self._extract_rss(url, video_id, doc)
  488. except compat_xml_parse_error:
  489. pass
  490. # Is it a Camtasia project?
  491. camtasia_res = self._extract_camtasia(url, video_id, webpage)
  492. if camtasia_res is not None:
  493. return camtasia_res
  494. # Sometimes embedded video player is hidden behind percent encoding
  495. # (e.g. https://github.com/rg3/youtube-dl/issues/2448)
  496. # Unescaping the whole page allows to handle those cases in a generic way
  497. webpage = compat_urllib_parse.unquote(webpage)
  498. # it's tempting to parse this further, but you would
  499. # have to take into account all the variations like
  500. # Video Title - Site Name
  501. # Site Name | Video Title
  502. # Video Title - Tagline | Site Name
  503. # and so on and so forth; it's just not practical
  504. video_title = self._html_search_regex(
  505. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  506. default='video')
  507. # Try to detect age limit automatically
  508. age_limit = self._rta_search(webpage)
  509. # And then there are the jokers who advertise that they use RTA,
  510. # but actually don't.
  511. AGE_LIMIT_MARKERS = [
  512. r'Proudly Labeled <a href="http://www.rtalabel.org/" title="Restricted to Adults">RTA</a>',
  513. ]
  514. if any(re.search(marker, webpage) for marker in AGE_LIMIT_MARKERS):
  515. age_limit = 18
  516. # video uploader is domain name
  517. video_uploader = self._search_regex(
  518. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  519. # Helper method
  520. def _playlist_from_matches(matches, getter, ie=None):
  521. urlrs = orderedSet(self.url_result(getter(m), ie) for m in matches)
  522. return self.playlist_result(
  523. urlrs, playlist_id=video_id, playlist_title=video_title)
  524. # Look for BrightCove:
  525. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  526. if bc_urls:
  527. self.to_screen('Brightcove video detected.')
  528. entries = [{
  529. '_type': 'url',
  530. 'url': smuggle_url(bc_url, {'Referer': url}),
  531. 'ie_key': 'Brightcove'
  532. } for bc_url in bc_urls]
  533. return {
  534. '_type': 'playlist',
  535. 'title': video_title,
  536. 'id': video_id,
  537. 'entries': entries,
  538. }
  539. # Look for embedded (iframe) Vimeo player
  540. mobj = re.search(
  541. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  542. if mobj:
  543. player_url = unescapeHTML(mobj.group('url'))
  544. surl = smuggle_url(player_url, {'Referer': url})
  545. return self.url_result(surl, 'Vimeo')
  546. # Look for embedded (swf embed) Vimeo player
  547. mobj = re.search(
  548. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  549. if mobj:
  550. return self.url_result(mobj.group(1), 'Vimeo')
  551. # Look for embedded YouTube player
  552. matches = re.findall(r'''(?x)
  553. (?:
  554. <iframe[^>]+?src=|
  555. data-video-url=|
  556. <embed[^>]+?src=|
  557. embedSWF\(?:\s*
  558. )
  559. (["\'])
  560. (?P<url>(?:https?:)?//(?:www\.)?youtube\.com/
  561. (?:embed|v)/.+?)
  562. \1''', webpage)
  563. if matches:
  564. return _playlist_from_matches(
  565. matches, lambda m: unescapeHTML(m[1]), ie='Youtube')
  566. # Look for embedded Dailymotion player
  567. matches = re.findall(
  568. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  569. if matches:
  570. return _playlist_from_matches(
  571. matches, lambda m: unescapeHTML(m[1]))
  572. # Look for embedded Wistia player
  573. match = re.search(
  574. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  575. if match:
  576. return {
  577. '_type': 'url_transparent',
  578. 'url': unescapeHTML(match.group('url')),
  579. 'ie_key': 'Wistia',
  580. 'uploader': video_uploader,
  581. 'title': video_title,
  582. 'id': video_id,
  583. }
  584. # Look for embedded blip.tv player
  585. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  586. if mobj:
  587. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  588. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9_]+)', webpage)
  589. if mobj:
  590. return self.url_result(mobj.group(1), 'BlipTV')
  591. # Look for embedded condenast player
  592. matches = re.findall(
  593. r'<iframe\s+(?:[a-zA-Z-]+="[^"]+"\s+)*?src="(https?://player\.cnevids\.com/embed/[^"]+")',
  594. webpage)
  595. if matches:
  596. return {
  597. '_type': 'playlist',
  598. 'entries': [{
  599. '_type': 'url',
  600. 'ie_key': 'CondeNast',
  601. 'url': ma,
  602. } for ma in matches],
  603. 'title': video_title,
  604. 'id': video_id,
  605. }
  606. # Look for Bandcamp pages with custom domain
  607. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  608. if mobj is not None:
  609. burl = unescapeHTML(mobj.group(1))
  610. # Don't set the extractor because it can be a track url or an album
  611. return self.url_result(burl)
  612. # Look for embedded Vevo player
  613. mobj = re.search(
  614. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  615. if mobj is not None:
  616. return self.url_result(mobj.group('url'))
  617. # Look for Ooyala videos
  618. mobj = (re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=(?P<ec>[^"&]+)', webpage) or
  619. re.search(r'OO.Player.create\([\'"].*?[\'"],\s*[\'"](?P<ec>.{32})[\'"]', webpage))
  620. if mobj is not None:
  621. return OoyalaIE._build_url_result(mobj.group('ec'))
  622. # Look for Aparat videos
  623. mobj = re.search(r'<iframe .*?src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  624. if mobj is not None:
  625. return self.url_result(mobj.group(1), 'Aparat')
  626. # Look for MPORA videos
  627. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  628. if mobj is not None:
  629. return self.url_result(mobj.group(1), 'Mpora')
  630. # Look for embedded NovaMov-based player
  631. mobj = re.search(
  632. r'''(?x)<(?:pagespeed_)?iframe[^>]+?src=(["\'])
  633. (?P<url>http://(?:(?:embed|www)\.)?
  634. (?:novamov\.com|
  635. nowvideo\.(?:ch|sx|eu|at|ag|co)|
  636. videoweed\.(?:es|com)|
  637. movshare\.(?:net|sx|ag)|
  638. divxstage\.(?:eu|net|ch|co|at|ag))
  639. /embed\.php.+?)\1''', webpage)
  640. if mobj is not None:
  641. return self.url_result(mobj.group('url'))
  642. # Look for embedded Facebook player
  643. mobj = re.search(
  644. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  645. if mobj is not None:
  646. return self.url_result(mobj.group('url'), 'Facebook')
  647. # Look for embedded VK player
  648. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  649. if mobj is not None:
  650. return self.url_result(mobj.group('url'), 'VK')
  651. # Look for embedded ivi player
  652. mobj = re.search(r'<embed[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?ivi\.ru/video/player.+?)\1', webpage)
  653. if mobj is not None:
  654. return self.url_result(mobj.group('url'), 'Ivi')
  655. # Look for embedded Huffington Post player
  656. mobj = re.search(
  657. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  658. if mobj is not None:
  659. return self.url_result(mobj.group('url'), 'HuffPost')
  660. # Look for embed.ly
  661. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  662. if mobj is not None:
  663. return self.url_result(mobj.group('url'))
  664. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  665. if mobj is not None:
  666. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  667. # Look for funnyordie embed
  668. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  669. if matches:
  670. return _playlist_from_matches(
  671. matches, getter=unescapeHTML, ie='FunnyOrDie')
  672. # Look for embedded RUTV player
  673. rutv_url = RUTVIE._extract_url(webpage)
  674. if rutv_url:
  675. return self.url_result(rutv_url, 'RUTV')
  676. # Look for embedded TED player
  677. mobj = re.search(
  678. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  679. if mobj is not None:
  680. return self.url_result(mobj.group('url'), 'TED')
  681. # Look for embedded Ustream videos
  682. mobj = re.search(
  683. r'<iframe[^>]+?src=(["\'])(?P<url>http://www\.ustream\.tv/embed/.+?)\1', webpage)
  684. if mobj is not None:
  685. return self.url_result(mobj.group('url'), 'Ustream')
  686. # Look for embedded arte.tv player
  687. mobj = re.search(
  688. r'<script [^>]*?src="(?P<url>http://www\.arte\.tv/playerv2/embed[^"]+)"',
  689. webpage)
  690. if mobj is not None:
  691. return self.url_result(mobj.group('url'), 'ArteTVEmbed')
  692. # Look for embedded smotri.com player
  693. smotri_url = SmotriIE._extract_url(webpage)
  694. if smotri_url:
  695. return self.url_result(smotri_url, 'Smotri')
  696. # Look for embeded soundcloud player
  697. mobj = re.search(
  698. r'<iframe src="(?P<url>https?://(?:w\.)?soundcloud\.com/player[^"]+)"',
  699. webpage)
  700. if mobj is not None:
  701. url = unescapeHTML(mobj.group('url'))
  702. return self.url_result(url)
  703. # Look for embedded vulture.com player
  704. mobj = re.search(
  705. r'<iframe src="(?P<url>https?://video\.vulture\.com/[^"]+)"',
  706. webpage)
  707. if mobj is not None:
  708. url = unescapeHTML(mobj.group('url'))
  709. return self.url_result(url, ie='Vulture')
  710. # Look for embedded mtvservices player
  711. mobj = re.search(
  712. r'<iframe src="(?P<url>https?://media\.mtvnservices\.com/embed/[^"]+)"',
  713. webpage)
  714. if mobj is not None:
  715. url = unescapeHTML(mobj.group('url'))
  716. return self.url_result(url, ie='MTVServicesEmbedded')
  717. # Look for embedded yahoo player
  718. mobj = re.search(
  719. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:screen|movies)\.yahoo\.com/.+?\.html\?format=embed)\1',
  720. webpage)
  721. if mobj is not None:
  722. return self.url_result(mobj.group('url'), 'Yahoo')
  723. # Look for embedded sbs.com.au player
  724. mobj = re.search(
  725. r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)sbs\.com\.au/ondemand/video/single/.+?)\1',
  726. webpage)
  727. if mobj is not None:
  728. return self.url_result(mobj.group('url'), 'SBS')
  729. # Start with something easy: JW Player in SWFObject
  730. found = re.findall(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  731. if not found:
  732. # Look for gorilla-vid style embedding
  733. found = re.findall(r'''(?sx)
  734. (?:
  735. jw_plugins|
  736. JWPlayerOptions|
  737. jwplayer\s*\(\s*["'][^'"]+["']\s*\)\s*\.setup
  738. )
  739. .*?file\s*:\s*["\'](.*?)["\']''', webpage)
  740. if not found:
  741. # Broaden the search a little bit
  742. found = re.findall(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  743. if not found:
  744. # Broaden the findall a little bit: JWPlayer JS loader
  745. found = re.findall(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  746. if not found:
  747. # Flow player
  748. found = re.findall(r'''(?xs)
  749. flowplayer\("[^"]+",\s*
  750. \{[^}]+?\}\s*,
  751. \s*{[^}]+? ["']?clip["']?\s*:\s*\{\s*
  752. ["']?url["']?\s*:\s*["']([^"']+)["']
  753. ''', webpage)
  754. if not found:
  755. # Try to find twitter cards info
  756. found = re.findall(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  757. if not found:
  758. # We look for Open Graph info:
  759. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  760. m_video_type = re.findall(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  761. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  762. if m_video_type is not None:
  763. def check_video(vurl):
  764. vpath = compat_urlparse.urlparse(vurl).path
  765. return '.' in vpath and not vpath.endswith('.swf')
  766. found = list(filter(
  767. check_video,
  768. re.findall(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)))
  769. if not found:
  770. # HTML5 video
  771. found = re.findall(r'(?s)<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage)
  772. if not found:
  773. found = re.search(
  774. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  775. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'([^\']+)\'"',
  776. webpage)
  777. if found:
  778. new_url = found.group(1)
  779. self.report_following_redirect(new_url)
  780. return {
  781. '_type': 'url',
  782. 'url': new_url,
  783. }
  784. if not found:
  785. raise ExtractorError('Unsupported URL: %s' % url)
  786. entries = []
  787. for video_url in found:
  788. video_url = compat_urlparse.urljoin(url, video_url)
  789. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  790. # Sometimes, jwplayer extraction will result in a YouTube URL
  791. if YoutubeIE.suitable(video_url):
  792. entries.append(self.url_result(video_url, 'Youtube'))
  793. continue
  794. # here's a fun little line of code for you:
  795. video_id = os.path.splitext(video_id)[0]
  796. entries.append({
  797. 'id': video_id,
  798. 'url': video_url,
  799. 'uploader': video_uploader,
  800. 'title': video_title,
  801. 'age_limit': age_limit,
  802. })
  803. if len(entries) == 1:
  804. return entries[0]
  805. else:
  806. for num, e in enumerate(entries, start=1):
  807. e['title'] = '%s (%d)' % (e['title'], num)
  808. return {
  809. '_type': 'playlist',
  810. 'entries': entries,
  811. }