5 from .common import InfoExtractor
15 class HypemIE(InfoExtractor):
16 """Information Extractor for hypem"""
17 _VALID_URL = r'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
19 u'url': u'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
20 u'file': u'1v6ga.mp3',
21 u'md5': u'b9cc91b5af8995e9f0c1cee04c575828',
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
30 raise ExtractorError(u'Invalid URL: %s' % url)
31 track_id = mobj.group(1)
33 data = {'ax': 1, 'ts': time.time()}
34 data_encoded = compat_urllib_parse.urlencode(data)
35 complete_url = url + "?" + data_encoded
36 request = compat_urllib_request.Request(complete_url)
37 response, urlh = self._download_webpage_handle(request, track_id, u'Downloading webpage with the url')
38 cookie = urlh.headers.get('Set-Cookie', '')
40 self.report_extraction(track_id)
42 html_tracks = self._html_search_regex(r'<script type="application/json" id="displayList-data">(.*?)</script>',
43 response, u'tracks', flags=re.MULTILINE|re.DOTALL).strip()
45 track_list = json.loads(html_tracks)
46 track = track_list[u'tracks'][0]
48 raise ExtractorError(u'Hypemachine contained invalid JSON.')
51 track_id = track[u"id"]
52 artist = track[u"artist"]
53 title = track[u"song"]
55 serve_url = "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id), compat_str(key))
56 request = compat_urllib_request.Request(serve_url, "" , {'Content-Type': 'application/json'})
57 request.add_header('cookie', cookie)
58 song_data_json = self._download_webpage(request, track_id, u'Downloading metadata')
60 song_data = json.loads(song_data_json)
62 raise ExtractorError(u'Hypemachine contained invalid JSON.')
63 final_url = song_data[u"url"]