]>
Commit | Line | Data |
---|---|---|
e5763a7a | 1 | from .common import InfoExtractor |
e5763a7a | 2 | from ..utils import ( |
cec9727c | 3 | KNOWN_EXTENSIONS, |
e897bd82 | 4 | determine_ext, |
e5763a7a | 5 | str_to_int, |
e5763a7a NJ |
6 | ) |
7 | ||
8 | ||
9 | class HearThisAtIE(InfoExtractor): | |
5bbfdb7c | 10 | _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/?#]+)/(?P<title>[\w.-]+)' |
e5763a7a | 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', | |
5bbfdb7c | 17 | 'display_id': 'moofi - dr-kreep', |
b55ee18f | 18 | 'ext': 'wav', |
e5763a7a | 19 | 'title': 'Moofi - Dr. Kreep', |
ec85ded8 | 20 | 'thumbnail': r're:^https?://.*\.jpg$', |
e5763a7a | 21 | 'timestamp': 1421564134, |
45b05962 | 22 | 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a', |
e5763a7a | 23 | 'upload_date': '20150118', |
e5763a7a | 24 | 'view_count': int, |
5bbfdb7c B |
25 | 'duration': 70, |
26 | 'genres': ['Experimental'], | |
27 | }, | |
cec9727c YCH |
28 | }, { |
29 | # 'download' link redirects to the original webpage | |
30 | 'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/', | |
31 | 'md5': '5980ceb7c461605d30f1f039df160c6e', | |
32 | 'info_dict': { | |
33 | 'id': '811296', | |
5bbfdb7c | 34 | 'display_id': 'twitchsf - dj-jim-hopkins-totally-bitchin-80s-dance-mix', |
cec9727c YCH |
35 | 'ext': 'mp3', |
36 | 'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!', | |
45b05962 | 37 | 'description': 'md5:ef26815ca8f483272a87b137ff175be2', |
cec9727c YCH |
38 | 'upload_date': '20160328', |
39 | 'timestamp': 1459186146, | |
ec85ded8 | 40 | 'thumbnail': r're:^https?://.*\.jpg$', |
cec9727c | 41 | 'view_count': int, |
cec9727c | 42 | 'duration': 4360, |
5bbfdb7c B |
43 | 'genres': ['Dance'], |
44 | }, | |
45 | }, { | |
46 | 'url': 'https://hearthis.at/tindalos/0001-tindalos-gnrique/eQd/', | |
47 | 'md5': 'cd08e51911f147f6da2d9678905b0bd9', | |
48 | 'info_dict': { | |
49 | 'id': '2685222', | |
50 | 'ext': 'mp3', | |
51 | 'duration': 86, | |
52 | 'view_count': int, | |
53 | 'timestamp': 1545471670, | |
54 | 'display_id': 'tindalos - 0001-tindalos-gnrique', | |
55 | 'thumbnail': r're:^https?://.*\.jpg$', | |
56 | 'genres': ['Other'], | |
57 | 'title': 'Tindalos - Tindalos - générique n°1', | |
58 | 'description': '', | |
59 | 'upload_date': '20181222', | |
60 | }, | |
61 | }, { | |
62 | 'url': 'https://hearthis.at/sithi2/biochip-c-classics-set-wolle-xdp-tresor.core-special-tresor-globus-berlin-13.07.20011/', | |
63 | 'md5': 'b45ac60f0c8111eef6ddc10ec232e312', | |
64 | 'info_dict': { | |
65 | 'id': '7145959', | |
66 | 'ext': 'mp3', | |
67 | 'description': 'md5:d7ae36a453d78903f6b7ed6eb2fce1f2', | |
68 | 'duration': 8986, | |
69 | 'thumbnail': r're:^https?://.*\.jpg$', | |
70 | 'title': 'md5:62669ce5b1b67f45c6f846033f37d3b9', | |
71 | 'timestamp': 1588699409, | |
72 | 'display_id': 'sithi2 - biochip-c-classics-set-wolle-xdp-tresor.core-special-tresor-globus-berlin-13.07.20011', | |
73 | 'view_count': int, | |
74 | 'upload_date': '20200505', | |
75 | 'genres': ['Other'], | |
cec9727c YCH |
76 | }, |
77 | }] | |
e5763a7a NJ |
78 | |
79 | def _real_extract(self, url): | |
5ad28e7f | 80 | m = self._match_valid_url(url) |
e5763a7a | 81 | display_id = '{artist:s} - {title:s}'.format(**m.groupdict()) |
45b05962 A |
82 | api_url = url.replace('www.', '').replace('hearthis.at', 'api-v2.hearthis.at') |
83 | data_json = self._download_json(api_url, display_id) | |
84 | track_id = data_json.get('id') | |
85 | artist_json = data_json.get('user') | |
86 | title = '{} - {}'.format(artist_json.get('username'), data_json.get('title')) | |
87 | genre = data_json.get('genre') | |
88 | description = data_json.get('description') | |
89 | thumbnail = data_json.get('artwork_url') or data_json.get('thumb') | |
90 | view_count = str_to_int(data_json.get('playback_count')) | |
91 | duration = str_to_int(data_json.get('duration')) | |
92 | timestamp = data_json.get('release_timestamp') | |
e5763a7a | 93 | |
b55ee18f | 94 | formats = [] |
45b05962 A |
95 | mp3_url = data_json.get('stream_url') |
96 | ||
b55ee18f PH |
97 | if mp3_url: |
98 | formats.append({ | |
99 | 'format_id': 'mp3', | |
100 | 'vcodec': 'none', | |
101 | 'acodec': 'mp3', | |
102 | 'url': mp3_url, | |
45b05962 | 103 | 'ext': 'mp3', |
b55ee18f | 104 | }) |
45b05962 A |
105 | |
106 | if data_json.get('download_url'): | |
107 | download_url = data_json['download_url'] | |
108 | ext = determine_ext(data_json['download_filename']) | |
cec9727c YCH |
109 | if ext in KNOWN_EXTENSIONS: |
110 | formats.append({ | |
45b05962 | 111 | 'format_id': ext, |
cec9727c YCH |
112 | 'vcodec': 'none', |
113 | 'ext': ext, | |
114 | 'url': download_url, | |
45b05962 | 115 | 'acodec': ext, |
f983b875 | 116 | 'quality': 2, # Usually better quality |
cec9727c | 117 | }) |
e5763a7a NJ |
118 | |
119 | return { | |
120 | 'id': track_id, | |
b55ee18f | 121 | 'display_id': display_id, |
e5763a7a NJ |
122 | 'title': title, |
123 | 'formats': formats, | |
124 | 'thumbnail': thumbnail, | |
125 | 'description': description, | |
126 | 'duration': duration, | |
127 | 'timestamp': timestamp, | |
128 | 'view_count': view_count, | |
45b05962 | 129 | 'genre': genre, |
e5763a7a | 130 | } |