[cleanup] Misc (#11574)
[yt-dlp3.git] / yt_dlp / extractor / hypem.py
blob204a72e2d63591f359184d847abe3eb58d50e7d6
1 from .common import InfoExtractor
2 from ..utils import int_or_none
5 class HypemIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?hypem\.com/track/(?P<id>[0-9a-z]{5})'
7 _TEST = {
8 'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
9 'md5': 'b9cc91b5af8995e9f0c1cee04c575828',
10 'info_dict': {
11 'id': '1v6ga',
12 'ext': 'mp3',
13 'title': 'Tame',
14 'uploader': 'BODYWORK',
15 'timestamp': 1371810457,
16 'upload_date': '20130621',
20 def _real_extract(self, url):
21 track_id = self._match_id(url)
23 response = self._download_webpage(url, track_id)
25 track = self._parse_json(self._html_search_regex(
26 r'(?s)<script\s+type="application/json"\s+id="displayList-data">(.+?)</script>',
27 response, 'tracks'), track_id)['tracks'][0]
29 track_id = track['id']
30 title = track['song']
32 final_url = self._download_json(
33 'http://hypem.com/serve/source/{}/{}'.format(track_id, track['key']),
34 track_id, 'Downloading metadata', headers={
35 'Content-Type': 'application/json',
36 })['url']
38 return {
39 'id': track_id,
40 'url': final_url,
41 'ext': 'mp3',
42 'title': title,
43 'uploader': track.get('artist'),
44 'duration': int_or_none(track.get('time')),
45 'timestamp': int_or_none(track.get('ts')),
46 'track': title,