]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | determine_ext, | |
4 | KNOWN_EXTENSIONS, | |
5 | str_to_int, | |
6 | ) | |
7 | ||
8 | ||
9 | class HearThisAtIE(InfoExtractor): | |
10 | _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?$' | |
11 | _PLAYLIST_URL = 'https://hearthis.at/playlist.php' | |
12 | _TESTS = [{ | |
13 | 'url': 'https://hearthis.at/moofi/dr-kreep', | |
14 | 'md5': 'ab6ec33c8fed6556029337c7885eb4e0', | |
15 | 'info_dict': { | |
16 | 'id': '150939', | |
17 | 'ext': 'wav', | |
18 | 'title': 'Moofi - Dr. Kreep', | |
19 | 'thumbnail': r're:^https?://.*\.jpg$', | |
20 | 'timestamp': 1421564134, | |
21 | 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a', | |
22 | 'upload_date': '20150118', | |
23 | 'view_count': int, | |
24 | 'duration': 71, | |
25 | 'genre': 'Experimental', | |
26 | } | |
27 | }, { | |
28 | # 'download' link redirects to the original webpage | |
29 | 'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/', | |
30 | 'md5': '5980ceb7c461605d30f1f039df160c6e', | |
31 | 'info_dict': { | |
32 | 'id': '811296', | |
33 | 'ext': 'mp3', | |
34 | 'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!', | |
35 | 'description': 'md5:ef26815ca8f483272a87b137ff175be2', | |
36 | 'upload_date': '20160328', | |
37 | 'timestamp': 1459186146, | |
38 | 'thumbnail': r're:^https?://.*\.jpg$', | |
39 | 'view_count': int, | |
40 | 'duration': 4360, | |
41 | 'genre': 'Dance', | |
42 | }, | |
43 | }] | |
44 | ||
45 | def _real_extract(self, url): | |
46 | m = self._match_valid_url(url) | |
47 | display_id = '{artist:s} - {title:s}'.format(**m.groupdict()) | |
48 | api_url = url.replace('www.', '').replace('hearthis.at', 'api-v2.hearthis.at') | |
49 | data_json = self._download_json(api_url, display_id) | |
50 | track_id = data_json.get('id') | |
51 | artist_json = data_json.get('user') | |
52 | title = '{} - {}'.format(artist_json.get('username'), data_json.get('title')) | |
53 | genre = data_json.get('genre') | |
54 | description = data_json.get('description') | |
55 | thumbnail = data_json.get('artwork_url') or data_json.get('thumb') | |
56 | view_count = str_to_int(data_json.get('playback_count')) | |
57 | duration = str_to_int(data_json.get('duration')) | |
58 | timestamp = data_json.get('release_timestamp') | |
59 | ||
60 | formats = [] | |
61 | mp3_url = data_json.get('stream_url') | |
62 | ||
63 | if mp3_url: | |
64 | formats.append({ | |
65 | 'format_id': 'mp3', | |
66 | 'vcodec': 'none', | |
67 | 'acodec': 'mp3', | |
68 | 'url': mp3_url, | |
69 | 'ext': 'mp3', | |
70 | }) | |
71 | ||
72 | if data_json.get('download_url'): | |
73 | download_url = data_json['download_url'] | |
74 | ext = determine_ext(data_json['download_filename']) | |
75 | if ext in KNOWN_EXTENSIONS: | |
76 | formats.append({ | |
77 | 'format_id': ext, | |
78 | 'vcodec': 'none', | |
79 | 'ext': ext, | |
80 | 'url': download_url, | |
81 | 'acodec': ext, | |
82 | 'quality': 2, # Usually better quality | |
83 | }) | |
84 | ||
85 | return { | |
86 | 'id': track_id, | |
87 | 'display_id': display_id, | |
88 | 'title': title, | |
89 | 'formats': formats, | |
90 | 'thumbnail': thumbnail, | |
91 | 'description': description, | |
92 | 'duration': duration, | |
93 | 'timestamp': timestamp, | |
94 | 'view_count': view_count, | |
95 | 'genre': genre, | |
96 | } |