2014-06-10 04:30:57 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-06-24 04:29:27 +08:00
|
|
|
import json
|
|
|
|
import time
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-11-22 00:18:17 +08:00
|
|
|
from ..compat import compat_urllib_parse
|
2014-12-13 19:24:42 +08:00
|
|
|
from ..utils import (
|
2013-06-24 04:29:27 +08:00
|
|
|
ExtractorError,
|
2015-11-22 00:18:17 +08:00
|
|
|
sanitized_Request,
|
2013-06-24 04:29:27 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class HypemIE(InfoExtractor):
|
2016-03-21 23:36:32 +08:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?hypem\.com/track/(?P<id>[^/]+)/'
|
2013-06-28 02:46:46 +08:00
|
|
|
_TEST = {
|
2014-06-10 04:30:57 +08:00
|
|
|
'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
|
|
|
|
'md5': 'b9cc91b5af8995e9f0c1cee04c575828',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '1v6ga',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'Tame',
|
|
|
|
'uploader': 'BODYWORK',
|
2013-06-28 02:46:46 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-24 04:29:27 +08:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2014-12-13 19:24:42 +08:00
|
|
|
track_id = self._match_id(url)
|
2013-06-24 04:29:27 +08:00
|
|
|
|
2013-11-03 21:03:17 +08:00
|
|
|
data = {'ax': 1, 'ts': time.time()}
|
2015-12-05 22:46:57 +08:00
|
|
|
request = sanitized_Request(url + '?' + compat_urllib_parse.urlencode(data))
|
2014-06-10 04:30:57 +08:00
|
|
|
response, urlh = self._download_webpage_handle(
|
|
|
|
request, track_id, 'Downloading webpage with the url')
|
2013-06-24 04:29:27 +08:00
|
|
|
|
2014-06-10 04:30:57 +08:00
|
|
|
html_tracks = self._html_search_regex(
|
2015-12-05 22:46:57 +08:00
|
|
|
r'(?ms)<script type="application/json" id="displayList-data">(.+?)</script>',
|
2014-06-10 04:30:57 +08:00
|
|
|
response, 'tracks')
|
2013-06-24 04:29:27 +08:00
|
|
|
try:
|
|
|
|
track_list = json.loads(html_tracks)
|
2014-06-10 04:30:57 +08:00
|
|
|
track = track_list['tracks'][0]
|
2013-06-24 04:29:27 +08:00
|
|
|
except ValueError:
|
2014-06-10 04:30:57 +08:00
|
|
|
raise ExtractorError('Hypemachine contained invalid JSON.')
|
2013-06-24 04:29:27 +08:00
|
|
|
|
2014-06-10 04:30:57 +08:00
|
|
|
key = track['key']
|
|
|
|
track_id = track['id']
|
|
|
|
title = track['song']
|
2013-06-24 04:29:27 +08:00
|
|
|
|
2015-11-22 00:18:17 +08:00
|
|
|
request = sanitized_Request(
|
2015-12-05 22:46:57 +08:00
|
|
|
'http://hypem.com/serve/source/%s/%s' % (track_id, key),
|
|
|
|
'', {'Content-Type': 'application/json'})
|
2014-06-10 04:30:57 +08:00
|
|
|
song_data = self._download_json(request, track_id, 'Downloading metadata')
|
2015-12-05 22:46:57 +08:00
|
|
|
final_url = song_data['url']
|
|
|
|
artist = track.get('artist')
|
2013-06-24 04:29:27 +08:00
|
|
|
|
2014-06-10 04:30:57 +08:00
|
|
|
return {
|
|
|
|
'id': track_id,
|
|
|
|
'url': final_url,
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': title,
|
|
|
|
'uploader': artist,
|
|
|
|
}
|