]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/jukebox.py
Add encoding to jukebox IE and simplify it a little bit
[yt-dlp.git] / youtube_dl / extractor / jukebox.py
1 # coding: utf-8
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 unescapeHTML,
8 )
9
10 class JukeboxIE(InfoExtractor):
11 _VALID_URL = r'^http://www\.jukebox\.es\/.+[,](?P<video_id>[a-z0-9]+).html'
12 _IFRAME = r'<iframe .*src="(?P<iframe>[^"]*)".*>'
13 _VIDEO_URL = r'"config":{"file":"(?P<video_url>http:[^"]+[.](?P<video_ext>[^.?]+)[?]mdtk=[0-9]+)"'
14 _TITLE = r'<h1 class="inline">(?P<title>[^<]+)</h1>.*<span id="infos_article_artist">(?P<artist>[^<]+)</span>'
15 _NOT_AVAILABLE = r'<span>Este video no está disponible por el momento [!]</span>'
16 _IS_YOUTUBE = r'config":{"file":"(?P<youtube_url>http:[\\][/][\\][/]www[.]youtube[.]com[\\][/]watch[?]v=[^"]+)"'
17
18 def _real_extract(self, url):
19 mobj = re.match(self._VALID_URL, url)
20 video_id = mobj.group('video_id')
21
22 html = self._download_webpage(url, video_id)
23
24 mobj = re.search(self._IFRAME, html)
25 if mobj is None:
26 raise ExtractorError(u'Cannot extract iframe url')
27 iframe_url = unescapeHTML(mobj.group('iframe'))
28
29 iframe_html = self._download_webpage(iframe_url, video_id, 'Downloading iframe')
30 mobj = re.search(self._NOT_AVAILABLE, iframe_html)
31 if mobj is not None:
32 raise ExtractorError(u'Video is not available(in your country?)!')
33
34 self.report_extraction(video_id)
35
36 mobj = re.search(self._VIDEO_URL, iframe_html)
37 if mobj is None:
38 mobj = re.search(self._IS_YOUTUBE, iframe_html)
39 if mobj is None:
40 raise ExtractorError(u'Cannot extract video url')
41 youtube_url = unescapeHTML(mobj.group('youtube_url')).replace('\/','/')
42 self.to_screen(u'Youtube video detected')
43 return self.url_result(youtube_url,ie='Youtube')
44 video_url = unescapeHTML(mobj.group('video_url')).replace('\/','/')
45 video_ext = unescapeHTML(mobj.group('video_ext'))
46
47 mobj = re.search(self._TITLE, html)
48 if mobj is None:
49 raise ExtractorError(u'Cannot extract title')
50 title = unescapeHTML(mobj.group('title'))
51 artist = unescapeHTML(mobj.group('artist'))
52
53 return [{'id': video_id,
54 'url': video_url,
55 'title': artist + '-' + title,
56 'ext': video_ext
57 }]