generic.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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_error,
  9. compat_urllib_parse,
  10. compat_urllib_request,
  11. compat_urlparse,
  12. compat_xml_parse_error,
  13. ExtractorError,
  14. HEADRequest,
  15. parse_xml,
  16. smuggle_url,
  17. unescapeHTML,
  18. unified_strdate,
  19. url_basename,
  20. )
  21. from .brightcove import BrightcoveIE
  22. from .ooyala import OoyalaIE
  23. from .rutv import RUTVIE
  24. class GenericIE(InfoExtractor):
  25. IE_DESC = 'Generic downloader that works on some sites'
  26. _VALID_URL = r'.*'
  27. IE_NAME = 'generic'
  28. _TESTS = [
  29. {
  30. 'url': 'http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html',
  31. 'file': '13601338388002.mp4',
  32. 'md5': '6e15c93721d7ec9e9ca3fdbf07982cfd',
  33. 'info_dict': {
  34. 'uploader': 'www.hodiho.fr',
  35. 'title': 'R\u00e9gis plante sa Jeep',
  36. }
  37. },
  38. # bandcamp page with custom domain
  39. {
  40. 'add_ie': ['Bandcamp'],
  41. 'url': 'http://bronyrock.com/track/the-pony-mash',
  42. 'file': '3235767654.mp3',
  43. 'info_dict': {
  44. 'title': 'The Pony Mash',
  45. 'uploader': 'M_Pallante',
  46. },
  47. 'skip': 'There is a limit of 200 free downloads / month for the test song',
  48. },
  49. # embedded brightcove video
  50. # it also tests brightcove videos that need to set the 'Referer' in the
  51. # http requests
  52. {
  53. 'add_ie': ['Brightcove'],
  54. 'url': 'http://www.bfmtv.com/video/bfmbusiness/cours-bourse/cours-bourse-l-analyse-technique-154522/',
  55. 'info_dict': {
  56. 'id': '2765128793001',
  57. 'ext': 'mp4',
  58. 'title': 'Le cours de bourse : l’analyse technique',
  59. 'description': 'md5:7e9ad046e968cb2d1114004aba466fd9',
  60. 'uploader': 'BFM BUSINESS',
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. },
  66. {
  67. # https://github.com/rg3/youtube-dl/issues/2253
  68. 'url': 'http://bcove.me/i6nfkrc3',
  69. 'file': '3101154703001.mp4',
  70. 'md5': '0ba9446db037002366bab3b3eb30c88c',
  71. 'info_dict': {
  72. 'title': 'Still no power',
  73. 'uploader': 'thestar.com',
  74. '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.',
  75. },
  76. 'add_ie': ['Brightcove'],
  77. },
  78. # Direct link to a video
  79. {
  80. 'url': 'http://media.w3.org/2010/05/sintel/trailer.mp4',
  81. 'md5': '67d406c2bcb6af27fa886f31aa934bbe',
  82. 'info_dict': {
  83. 'id': 'trailer',
  84. 'ext': 'mp4',
  85. 'title': 'trailer',
  86. 'upload_date': '20100513',
  87. }
  88. },
  89. # ooyala video
  90. {
  91. 'url': 'http://www.rollingstone.com/music/videos/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-20131219',
  92. 'md5': '5644c6ca5d5782c1d0d350dad9bd840c',
  93. 'info_dict': {
  94. 'id': 'BwY2RxaTrTkslxOfcan0UCf0YqyvWysJ',
  95. 'ext': 'mp4',
  96. 'title': '2cc213299525360.mov', # that's what we get
  97. },
  98. },
  99. # google redirect
  100. {
  101. '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',
  102. 'info_dict': {
  103. 'id': 'cmQHVoWB5FY',
  104. 'ext': 'mp4',
  105. 'upload_date': '20130224',
  106. 'uploader_id': 'TheVerge',
  107. '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.',
  108. 'uploader': 'The Verge',
  109. 'title': 'First Firefox OS phones side-by-side',
  110. },
  111. 'params': {
  112. 'skip_download': False,
  113. }
  114. },
  115. # embed.ly video
  116. {
  117. 'url': 'http://www.tested.com/science/weird/460206-tested-grinding-coffee-2000-frames-second/',
  118. 'info_dict': {
  119. 'id': '9ODmcdjQcHQ',
  120. 'ext': 'mp4',
  121. 'title': 'Tested: Grinding Coffee at 2000 Frames Per Second',
  122. 'upload_date': '20140225',
  123. 'description': 'md5:06a40fbf30b220468f1e0957c0f558ff',
  124. 'uploader': 'Tested',
  125. 'uploader_id': 'testedcom',
  126. },
  127. # No need to test YoutubeIE here
  128. 'params': {
  129. 'skip_download': True,
  130. },
  131. },
  132. # funnyordie embed
  133. {
  134. 'url': 'http://www.theguardian.com/world/2014/mar/11/obama-zach-galifianakis-between-two-ferns',
  135. 'md5': '7cf780be104d40fea7bae52eed4a470e',
  136. 'info_dict': {
  137. 'id': '18e820ec3f',
  138. 'ext': 'mp4',
  139. 'title': 'Between Two Ferns with Zach Galifianakis: President Barack Obama',
  140. 'description': 'Episode 18: President Barack Obama sits down with Zach Galifianakis for his most memorable interview yet.',
  141. },
  142. },
  143. # RUTV embed
  144. {
  145. 'url': 'http://www.rg.ru/2014/03/15/reg-dfo/anklav-anons.html',
  146. 'info_dict': {
  147. 'id': '776940',
  148. 'ext': 'mp4',
  149. 'title': 'Охотское море стало целиком российским',
  150. 'description': 'md5:5ed62483b14663e2a95ebbe115eb8f43',
  151. },
  152. 'params': {
  153. # m3u8 download
  154. 'skip_download': True,
  155. },
  156. },
  157. # Embedded TED video
  158. {
  159. 'url': 'http://en.support.wordpress.com/videos/ted-talks/',
  160. 'md5': 'deeeabcc1085eb2ba205474e7235a3d5',
  161. 'info_dict': {
  162. 'id': '981',
  163. 'ext': 'mp4',
  164. 'title': 'My web playroom',
  165. 'uploader': 'Ze Frank',
  166. 'description': 'md5:ddb2a40ecd6b6a147e400e535874947b',
  167. }
  168. }
  169. ]
  170. def report_download_webpage(self, video_id):
  171. """Report webpage download."""
  172. if not self._downloader.params.get('test', False):
  173. self._downloader.report_warning('Falling back on generic information extractor.')
  174. super(GenericIE, self).report_download_webpage(video_id)
  175. def report_following_redirect(self, new_url):
  176. """Report information extraction."""
  177. self._downloader.to_screen('[redirect] Following redirect to %s' % new_url)
  178. def _send_head(self, url):
  179. """Check if it is a redirect, like url shorteners, in case return the new url."""
  180. class HEADRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
  181. """
  182. Subclass the HTTPRedirectHandler to make it use our
  183. HEADRequest also on the redirected URL
  184. """
  185. def redirect_request(self, req, fp, code, msg, headers, newurl):
  186. if code in (301, 302, 303, 307):
  187. newurl = newurl.replace(' ', '%20')
  188. newheaders = dict((k,v) for k,v in req.headers.items()
  189. if k.lower() not in ("content-length", "content-type"))
  190. try:
  191. # This function was deprecated in python 3.3 and removed in 3.4
  192. origin_req_host = req.get_origin_req_host()
  193. except AttributeError:
  194. origin_req_host = req.origin_req_host
  195. return HEADRequest(newurl,
  196. headers=newheaders,
  197. origin_req_host=origin_req_host,
  198. unverifiable=True)
  199. else:
  200. raise compat_urllib_error.HTTPError(req.get_full_url(), code, msg, headers, fp)
  201. class HTTPMethodFallback(compat_urllib_request.BaseHandler):
  202. """
  203. Fallback to GET if HEAD is not allowed (405 HTTP error)
  204. """
  205. def http_error_405(self, req, fp, code, msg, headers):
  206. fp.read()
  207. fp.close()
  208. newheaders = dict((k,v) for k,v in req.headers.items()
  209. if k.lower() not in ("content-length", "content-type"))
  210. return self.parent.open(compat_urllib_request.Request(req.get_full_url(),
  211. headers=newheaders,
  212. origin_req_host=req.get_origin_req_host(),
  213. unverifiable=True))
  214. # Build our opener
  215. opener = compat_urllib_request.OpenerDirector()
  216. for handler in [compat_urllib_request.HTTPHandler, compat_urllib_request.HTTPDefaultErrorHandler,
  217. HTTPMethodFallback, HEADRedirectHandler,
  218. compat_urllib_request.HTTPErrorProcessor, compat_urllib_request.HTTPSHandler]:
  219. opener.add_handler(handler())
  220. response = opener.open(HEADRequest(url))
  221. if response is None:
  222. raise ExtractorError('Invalid URL protocol')
  223. return response
  224. def _extract_rss(self, url, video_id, doc):
  225. playlist_title = doc.find('./channel/title').text
  226. playlist_desc_el = doc.find('./channel/description')
  227. playlist_desc = None if playlist_desc_el is None else playlist_desc_el.text
  228. entries = [{
  229. '_type': 'url',
  230. 'url': e.find('link').text,
  231. 'title': e.find('title').text,
  232. } for e in doc.findall('./channel/item')]
  233. return {
  234. '_type': 'playlist',
  235. 'id': url,
  236. 'title': playlist_title,
  237. 'description': playlist_desc,
  238. 'entries': entries,
  239. }
  240. def _real_extract(self, url):
  241. parsed_url = compat_urlparse.urlparse(url)
  242. if not parsed_url.scheme:
  243. default_search = self._downloader.params.get('default_search')
  244. if default_search is None:
  245. default_search = 'auto'
  246. if default_search == 'auto':
  247. if '/' in url:
  248. self._downloader.report_warning('The url doesn\'t specify the protocol, trying with http')
  249. return self.url_result('http://' + url)
  250. else:
  251. return self.url_result('ytsearch:' + url)
  252. else:
  253. assert ':' in default_search
  254. return self.url_result(default_search + url)
  255. video_id = os.path.splitext(url.rstrip('/').split('/')[-1])[0]
  256. self.to_screen('%s: Requesting header' % video_id)
  257. try:
  258. response = self._send_head(url)
  259. # Check for redirect
  260. new_url = response.geturl()
  261. if url != new_url:
  262. self.report_following_redirect(new_url)
  263. return self.url_result(new_url)
  264. # Check for direct link to a video
  265. content_type = response.headers.get('Content-Type', '')
  266. m = re.match(r'^(?P<type>audio|video|application(?=/ogg$))/(?P<format_id>.+)$', content_type)
  267. if m:
  268. upload_date = response.headers.get('Last-Modified')
  269. if upload_date:
  270. upload_date = unified_strdate(upload_date)
  271. return {
  272. 'id': video_id,
  273. 'title': os.path.splitext(url_basename(url))[0],
  274. 'formats': [{
  275. 'format_id': m.group('format_id'),
  276. 'url': url,
  277. 'vcodec': 'none' if m.group('type') == 'audio' else None
  278. }],
  279. 'upload_date': upload_date,
  280. }
  281. except compat_urllib_error.HTTPError:
  282. # This may be a stupid server that doesn't like HEAD, our UA, or so
  283. pass
  284. try:
  285. webpage = self._download_webpage(url, video_id)
  286. except ValueError:
  287. # since this is the last-resort InfoExtractor, if
  288. # this error is thrown, it'll be thrown here
  289. raise ExtractorError('Failed to download URL: %s' % url)
  290. self.report_extraction(video_id)
  291. # Is it an RSS feed?
  292. try:
  293. doc = parse_xml(webpage)
  294. if doc.tag == 'rss':
  295. return self._extract_rss(url, video_id, doc)
  296. except compat_xml_parse_error:
  297. pass
  298. # it's tempting to parse this further, but you would
  299. # have to take into account all the variations like
  300. # Video Title - Site Name
  301. # Site Name | Video Title
  302. # Video Title - Tagline | Site Name
  303. # and so on and so forth; it's just not practical
  304. video_title = self._html_search_regex(
  305. r'(?s)<title>(.*?)</title>', webpage, 'video title',
  306. default='video')
  307. # video uploader is domain name
  308. video_uploader = self._search_regex(
  309. r'^(?:https?://)?([^/]*)/.*', url, 'video uploader')
  310. # Look for BrightCove:
  311. bc_urls = BrightcoveIE._extract_brightcove_urls(webpage)
  312. if bc_urls:
  313. self.to_screen('Brightcove video detected.')
  314. entries = [{
  315. '_type': 'url',
  316. 'url': smuggle_url(bc_url, {'Referer': url}),
  317. 'ie_key': 'Brightcove'
  318. } for bc_url in bc_urls]
  319. return {
  320. '_type': 'playlist',
  321. 'title': video_title,
  322. 'id': video_id,
  323. 'entries': entries,
  324. }
  325. # Look for embedded (iframe) Vimeo player
  326. mobj = re.search(
  327. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  328. if mobj:
  329. player_url = unescapeHTML(mobj.group('url'))
  330. surl = smuggle_url(player_url, {'Referer': url})
  331. return self.url_result(surl, 'Vimeo')
  332. # Look for embedded (swf embed) Vimeo player
  333. mobj = re.search(
  334. r'<embed[^>]+?src="(https?://(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  335. if mobj:
  336. return self.url_result(mobj.group(1), 'Vimeo')
  337. # Look for embedded YouTube player
  338. matches = re.findall(r'''(?x)
  339. (?:<iframe[^>]+?src=|embedSWF\(\s*)
  340. (["\'])(?P<url>(?:https?:)?//(?:www\.)?youtube\.com/
  341. (?:embed|v)/.+?)
  342. \1''', webpage)
  343. if matches:
  344. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Youtube')
  345. for tuppl in matches]
  346. return self.playlist_result(
  347. urlrs, playlist_id=video_id, playlist_title=video_title)
  348. # Look for embedded Dailymotion player
  349. matches = re.findall(
  350. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/embed/video/.+?)\1', webpage)
  351. if matches:
  352. urlrs = [self.url_result(unescapeHTML(tuppl[1]), 'Dailymotion')
  353. for tuppl in matches]
  354. return self.playlist_result(
  355. urlrs, playlist_id=video_id, playlist_title=video_title)
  356. # Look for embedded Wistia player
  357. match = re.search(
  358. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:fast\.)?wistia\.net/embed/iframe/.+?)\1', webpage)
  359. if match:
  360. return {
  361. '_type': 'url_transparent',
  362. 'url': unescapeHTML(match.group('url')),
  363. 'ie_key': 'Wistia',
  364. 'uploader': video_uploader,
  365. 'title': video_title,
  366. 'id': video_id,
  367. }
  368. # Look for embedded blip.tv player
  369. mobj = re.search(r'<meta\s[^>]*https?://api\.blip\.tv/\w+/redirect/\w+/(\d+)', webpage)
  370. if mobj:
  371. return self.url_result('http://blip.tv/a/a-'+mobj.group(1), 'BlipTV')
  372. mobj = re.search(r'<(?:iframe|embed|object)\s[^>]*(https?://(?:\w+\.)?blip\.tv/(?:play/|api\.swf#)[a-zA-Z0-9]+)', webpage)
  373. if mobj:
  374. return self.url_result(mobj.group(1), 'BlipTV')
  375. # Look for Bandcamp pages with custom domain
  376. mobj = re.search(r'<meta property="og:url"[^>]*?content="(.*?bandcamp\.com.*?)"', webpage)
  377. if mobj is not None:
  378. burl = unescapeHTML(mobj.group(1))
  379. # Don't set the extractor because it can be a track url or an album
  380. return self.url_result(burl)
  381. # Look for embedded Vevo player
  382. mobj = re.search(
  383. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:cache\.)?vevo\.com/.+?)\1', webpage)
  384. if mobj is not None:
  385. return self.url_result(mobj.group('url'))
  386. # Look for Ooyala videos
  387. mobj = re.search(r'player.ooyala.com/[^"?]+\?[^"]*?(?:embedCode|ec)=([^"&]+)', webpage)
  388. if mobj is not None:
  389. return OoyalaIE._build_url_result(mobj.group(1))
  390. # Look for Aparat videos
  391. mobj = re.search(r'<iframe src="(http://www\.aparat\.com/video/[^"]+)"', webpage)
  392. if mobj is not None:
  393. return self.url_result(mobj.group(1), 'Aparat')
  394. # Look for MPORA videos
  395. mobj = re.search(r'<iframe .*?src="(http://mpora\.(?:com|de)/videos/[^"]+)"', webpage)
  396. if mobj is not None:
  397. return self.url_result(mobj.group(1), 'Mpora')
  398. # Look for embedded NovaMov player
  399. mobj = re.search(
  400. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?novamov\.com/embed\.php.+?)\1', webpage)
  401. if mobj is not None:
  402. return self.url_result(mobj.group('url'), 'NovaMov')
  403. # Look for embedded NowVideo player
  404. mobj = re.search(
  405. r'<iframe[^>]+?src=(["\'])(?P<url>http://(?:(?:embed|www)\.)?nowvideo\.(?:ch|sx|eu)/embed\.php.+?)\1', webpage)
  406. if mobj is not None:
  407. return self.url_result(mobj.group('url'), 'NowVideo')
  408. # Look for embedded Facebook player
  409. mobj = re.search(
  410. r'<iframe[^>]+?src=(["\'])(?P<url>https://www\.facebook\.com/video/embed.+?)\1', webpage)
  411. if mobj is not None:
  412. return self.url_result(mobj.group('url'), 'Facebook')
  413. # Look for embedded VK player
  414. mobj = re.search(r'<iframe[^>]+?src=(["\'])(?P<url>https?://vk\.com/video_ext\.php.+?)\1', webpage)
  415. if mobj is not None:
  416. return self.url_result(mobj.group('url'), 'VK')
  417. # Look for embedded Huffington Post player
  418. mobj = re.search(
  419. r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1', webpage)
  420. if mobj is not None:
  421. return self.url_result(mobj.group('url'), 'HuffPost')
  422. # Look for embed.ly
  423. mobj = re.search(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage)
  424. if mobj is not None:
  425. return self.url_result(mobj.group('url'))
  426. mobj = re.search(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage)
  427. if mobj is not None:
  428. return self.url_result(compat_urllib_parse.unquote(mobj.group('url')))
  429. # Look for funnyordie embed
  430. matches = re.findall(r'<iframe[^>]+?src="(https?://(?:www\.)?funnyordie\.com/embed/[^"]+)"', webpage)
  431. if matches:
  432. urlrs = [self.url_result(unescapeHTML(eurl), 'FunnyOrDie')
  433. for eurl in matches]
  434. return self.playlist_result(
  435. urlrs, playlist_id=video_id, playlist_title=video_title)
  436. # Look for embedded RUTV player
  437. rutv_url = RUTVIE._extract_url(webpage)
  438. if rutv_url:
  439. return self.url_result(rutv_url, 'RUTV')
  440. # Start with something easy: JW Player in SWFObject
  441. mobj = re.search(r'flashvars: [\'"](?:.*&)?file=(http[^\'"&]*)', webpage)
  442. if mobj is None:
  443. # Look for gorilla-vid style embedding
  444. mobj = re.search(r'(?s)(?:jw_plugins|JWPlayerOptions).*?file\s*:\s*["\'](.*?)["\']', webpage)
  445. if mobj is None:
  446. # Broaden the search a little bit
  447. mobj = re.search(r'[^A-Za-z0-9]?(?:file|source)=(http[^\'"&]*)', webpage)
  448. if mobj is None:
  449. # Broaden the search a little bit: JWPlayer JS loader
  450. mobj = re.search(r'[^A-Za-z0-9]?file["\']?:\s*["\'](http(?![^\'"]+\.[0-9]+[\'"])[^\'"]+)["\']', webpage)
  451. # Look for embedded TED player
  452. mobj = re.search(
  453. r'<iframe[^>]+?src=(["\'])(?P<url>http://embed\.ted\.com/.+?)\1', webpage)
  454. if mobj is not None:
  455. return self.url_result(mobj.group('url'), 'TED')
  456. if mobj is None:
  457. # Try to find twitter cards info
  458. mobj = re.search(r'<meta (?:property|name)="twitter:player:stream" (?:content|value)="(.+?)"', webpage)
  459. if mobj is None:
  460. # We look for Open Graph info:
  461. # We have to match any number spaces between elements, some sites try to align them (eg.: statigr.am)
  462. m_video_type = re.search(r'<meta.*?property="og:video:type".*?content="video/(.*?)"', webpage)
  463. # We only look in og:video if the MIME type is a video, don't try if it's a Flash player:
  464. if m_video_type is not None:
  465. mobj = re.search(r'<meta.*?property="og:video".*?content="(.*?)"', webpage)
  466. if mobj is None:
  467. # HTML5 video
  468. mobj = re.search(r'<video[^<]*(?:>.*?<source.*?)? src="([^"]+)"', webpage, flags=re.DOTALL)
  469. if mobj is None:
  470. mobj = re.search(
  471. r'(?i)<meta\s+(?=(?:[a-z-]+="[^"]+"\s+)*http-equiv="refresh")'
  472. r'(?:[a-z-]+="[^"]+"\s+)*?content="[0-9]{,2};url=\'([^\']+)\'"',
  473. webpage)
  474. if mobj:
  475. new_url = mobj.group(1)
  476. self.report_following_redirect(new_url)
  477. return {
  478. '_type': 'url',
  479. 'url': new_url,
  480. }
  481. if mobj is None:
  482. raise ExtractorError('Unsupported URL: %s' % url)
  483. # It's possible that one of the regexes
  484. # matched, but returned an empty group:
  485. if mobj.group(1) is None:
  486. raise ExtractorError('Did not find a valid video URL at %s' % url)
  487. video_url = mobj.group(1)
  488. video_url = compat_urlparse.urljoin(url, video_url)
  489. video_id = compat_urllib_parse.unquote(os.path.basename(video_url))
  490. # Sometimes, jwplayer extraction will result in a YouTube URL
  491. if YoutubeIE.suitable(video_url):
  492. return self.url_result(video_url, 'Youtube')
  493. # here's a fun little line of code for you:
  494. video_id = os.path.splitext(video_id)[0]
  495. return {
  496. 'id': video_id,
  497. 'url': video_url,
  498. 'uploader': video_uploader,
  499. 'title': video_title,
  500. }