]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | float_or_none, | |
4 | str_or_none, | |
5 | traverse_obj, | |
6 | url_or_none, | |
7 | ) | |
8 | ||
9 | ||
10 | class WhypIE(InfoExtractor): | |
11 | _VALID_URL = r'https?://(?:www\.)?whyp\.it/tracks/(?P<id>\d+)' | |
12 | _TESTS = [{ | |
13 | 'url': 'https://www.whyp.it/tracks/18337/home-page-example-track-b4kq7', | |
14 | 'md5': 'c1187b42ebf8605284e3dc92aeb33d16', | |
15 | 'info_dict': { | |
16 | 'url': 'https://cdn.whyp.it/50eb17cc-e9ff-4e18-b89b-dc9206a95cb1.mp3', | |
17 | 'id': '18337', | |
18 | 'title': 'Home Page Example Track', | |
19 | 'description': 'md5:bd758000fb93f3159339c852b5b9133c', | |
20 | 'ext': 'mp3', | |
21 | 'duration': 52.82, | |
22 | 'uploader': 'Brad', | |
23 | 'uploader_id': '1', | |
24 | 'thumbnail': 'https://cdn.whyp.it/a537bb36-3373-4c61-96c8-27fc1b2f427a.jpg', | |
25 | }, | |
26 | }, { | |
27 | 'url': 'https://www.whyp.it/tracks/18337', | |
28 | 'only_matching': True, | |
29 | }] | |
30 | ||
31 | def _real_extract(self, url): | |
32 | unique_id = self._match_id(url) | |
33 | webpage = self._download_webpage(url, unique_id) | |
34 | data = self._search_nuxt_data(webpage, unique_id)['rawTrack'] | |
35 | ||
36 | return { | |
37 | 'url': data['audio_url'], | |
38 | 'id': unique_id, | |
39 | **traverse_obj(data, { | |
40 | 'title': 'title', | |
41 | 'description': 'description', | |
42 | 'duration': ('duration', {float_or_none}), | |
43 | 'uploader': ('user', 'username'), | |
44 | 'uploader_id': ('user', 'id', {str_or_none}), | |
45 | 'thumbnail': ('artwork_url', {url_or_none}), | |
46 | }), | |
47 | 'ext': 'mp3', | |
48 | 'vcodec': 'none', | |
49 | 'http_headers': {'Referer': 'https://whyp.it/'}, | |
50 | } |