1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

[hypem] Modernize and extract more metadata(closes #15320)

This commit is contained in:
Remita Amine 2019-03-11 09:43:06 +01:00
parent 197cf8b794
commit f517c0c0a7

View file

@ -1,18 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json
import time
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_urllib_parse_urlencode from ..utils import int_or_none
from ..utils import (
ExtractorError,
sanitized_Request,
)
class HypemIE(InfoExtractor): class HypemIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?hypem\.com/track/(?P<id>[^/]+)/' _VALID_URL = r'https?://(?:www\.)?hypem\.com/track/(?P<id>[0-9a-z]{5})'
_TEST = { _TEST = {
'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME', 'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
'md5': 'b9cc91b5af8995e9f0c1cee04c575828', 'md5': 'b9cc91b5af8995e9f0c1cee04c575828',
@ -21,41 +14,36 @@ class HypemIE(InfoExtractor):
'ext': 'mp3', 'ext': 'mp3',
'title': 'Tame', 'title': 'Tame',
'uploader': 'BODYWORK', 'uploader': 'BODYWORK',
'timestamp': 1371810457,
'upload_date': '20130621',
} }
} }
def _real_extract(self, url): def _real_extract(self, url):
track_id = self._match_id(url) track_id = self._match_id(url)
data = {'ax': 1, 'ts': time.time()} response = self._download_webpage(url, track_id)
request = sanitized_Request(url + '?' + compat_urllib_parse_urlencode(data))
response, urlh = self._download_webpage_handle(
request, track_id, 'Downloading webpage with the url')
html_tracks = self._html_search_regex( track = self._parse_json(self._html_search_regex(
r'(?ms)<script type="application/json" id="displayList-data">(.+?)</script>', r'(?s)<script\s+type="application/json"\s+id="displayList-data">(.+?)</script>',
response, 'tracks') response, 'tracks'), track_id)['tracks'][0]
try:
track_list = json.loads(html_tracks)
track = track_list['tracks'][0]
except ValueError:
raise ExtractorError('Hypemachine contained invalid JSON.')
key = track['key']
track_id = track['id'] track_id = track['id']
title = track['song'] title = track['song']
request = sanitized_Request( final_url = self._download_json(
'http://hypem.com/serve/source/%s/%s' % (track_id, key), 'http://hypem.com/serve/source/%s/%s' % (track_id, track['key']),
'', {'Content-Type': 'application/json'}) track_id, 'Downloading metadata', headers={
song_data = self._download_json(request, track_id, 'Downloading metadata') 'Content-Type': 'application/json'
final_url = song_data['url'] })['url']
artist = track.get('artist')
return { return {
'id': track_id, 'id': track_id,
'url': final_url, 'url': final_url,
'ext': 'mp3', 'ext': 'mp3',
'title': title, 'title': title,
'uploader': artist, 'uploader': track.get('artist'),
'duration': int_or_none(track.get('time')),
'timestamp': int_or_none(track.get('ts')),
'track': title,
} }