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