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