]>
Commit | Line | Data |
---|---|---|
e5763a7a | 1 | from .common import InfoExtractor |
e5763a7a | 2 | from ..utils import ( |
45b05962 | 3 | determine_ext, |
cec9727c | 4 | KNOWN_EXTENSIONS, |
e5763a7a | 5 | str_to_int, |
e5763a7a NJ |
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' | |
cec9727c | 12 | _TESTS = [{ |
e5763a7a | 13 | 'url': 'https://hearthis.at/moofi/dr-kreep', |
b55ee18f | 14 | 'md5': 'ab6ec33c8fed6556029337c7885eb4e0', |
e5763a7a NJ |
15 | 'info_dict': { |
16 | 'id': '150939', | |
b55ee18f | 17 | 'ext': 'wav', |
e5763a7a | 18 | 'title': 'Moofi - Dr. Kreep', |
ec85ded8 | 19 | 'thumbnail': r're:^https?://.*\.jpg$', |
e5763a7a | 20 | 'timestamp': 1421564134, |
45b05962 | 21 | 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a', |
e5763a7a | 22 | 'upload_date': '20150118', |
e5763a7a | 23 | 'view_count': int, |
e5763a7a | 24 | 'duration': 71, |
45b05962 | 25 | 'genre': 'Experimental', |
e5763a7a | 26 | } |
cec9727c YCH |
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!', | |
45b05962 | 35 | 'description': 'md5:ef26815ca8f483272a87b137ff175be2', |
cec9727c YCH |
36 | 'upload_date': '20160328', |
37 | 'timestamp': 1459186146, | |
ec85ded8 | 38 | 'thumbnail': r're:^https?://.*\.jpg$', |
cec9727c | 39 | 'view_count': int, |
cec9727c | 40 | 'duration': 4360, |
45b05962 | 41 | 'genre': 'Dance', |
cec9727c YCH |
42 | }, |
43 | }] | |
e5763a7a NJ |
44 | |
45 | def _real_extract(self, url): | |
5ad28e7f | 46 | m = self._match_valid_url(url) |
e5763a7a | 47 | display_id = '{artist:s} - {title:s}'.format(**m.groupdict()) |
45b05962 A |
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') | |
e5763a7a | 59 | |
b55ee18f | 60 | formats = [] |
45b05962 A |
61 | mp3_url = data_json.get('stream_url') |
62 | ||
b55ee18f PH |
63 | if mp3_url: |
64 | formats.append({ | |
65 | 'format_id': 'mp3', | |
66 | 'vcodec': 'none', | |
67 | 'acodec': 'mp3', | |
68 | 'url': mp3_url, | |
45b05962 | 69 | 'ext': 'mp3', |
b55ee18f | 70 | }) |
45b05962 A |
71 | |
72 | if data_json.get('download_url'): | |
73 | download_url = data_json['download_url'] | |
74 | ext = determine_ext(data_json['download_filename']) | |
cec9727c YCH |
75 | if ext in KNOWN_EXTENSIONS: |
76 | formats.append({ | |
45b05962 | 77 | 'format_id': ext, |
cec9727c YCH |
78 | 'vcodec': 'none', |
79 | 'ext': ext, | |
80 | 'url': download_url, | |
45b05962 | 81 | 'acodec': ext, |
f983b875 | 82 | 'quality': 2, # Usually better quality |
cec9727c | 83 | }) |
b55ee18f | 84 | self._sort_formats(formats) |
e5763a7a NJ |
85 | |
86 | return { | |
87 | 'id': track_id, | |
b55ee18f | 88 | 'display_id': display_id, |
e5763a7a NJ |
89 | 'title': title, |
90 | 'formats': formats, | |
91 | 'thumbnail': thumbnail, | |
92 | 'description': description, | |
93 | 'duration': duration, | |
94 | 'timestamp': timestamp, | |
95 | 'view_count': view_count, | |
45b05962 | 96 | 'genre': genre, |
e5763a7a | 97 | } |