Merge remote-tracking branch 'JohnyMoSwag/master'
[youtube-dl] / youtube_dl / extractor / hotnewhiphop.py
1 import re
2 import base64
3
4 from .common import InfoExtractor
5
6
7 class HotNewHipHopIE(InfoExtractor):
8     _VALID_URL = r'(http://www\.hotnewhiphop.com/.*\.(?P<id>.*)\.html)'
9     IE_NAME = u'HotNewHipHop'
10
11     def _real_extract(self, url):
12         m = re.match(self._VALID_URL, url)
13         video_id = m.group('id')
14
15         webpage_src = self._download_webpage(url, video_id)
16
17         video_url_base64 = self._search_regex(r'data-path="(.*?)"',
18             webpage_src, u'video URL', fatal=False)
19
20         if video_url_base64 == None:
21             video_url = self._search_regex(r'"contentUrl" content="(.*?)"', webpage_src,
22                 u'video URL')
23             return self.url_result(video_url, ie='Youtube')
24
25         video_url = base64.b64decode(video_url_base64)
26
27         video_title = self._html_search_regex(r"<title>(.*)</title>",
28             webpage_src, u'title')
29         
30         #"og:image" content=
31         # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
32         thumbnail = self._html_search_regex(r'"og:image" content="(.*)"',
33             webpage_src, u'thumbnail', fatal=False)
34
35         results = [{
36                     'id': video_id,
37                     'url' : video_url,
38                     'title' : video_title,
39                     'thumbnail' : thumbnail,
40                     'ext' : 'mp3',
41                     }]
42         return results