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