]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | float_or_none, | |
4 | int_or_none, | |
5 | orderedSet, | |
6 | parse_iso8601, | |
7 | parse_qs, | |
8 | parse_resolution, | |
9 | str_or_none, | |
10 | traverse_obj, | |
11 | url_or_none, | |
12 | ) | |
13 | ||
14 | ||
15 | class EpidemicSoundIE(InfoExtractor): | |
16 | _VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/track/(?P<id>[0-9a-zA-Z]+)' | |
17 | _TESTS = [{ | |
18 | 'url': 'https://www.epidemicsound.com/track/yFfQVRpSPz/', | |
19 | 'md5': 'd98ff2ddb49e8acab9716541cbc9dfac', | |
20 | 'info_dict': { | |
21 | 'id': '45014', | |
22 | 'display_id': 'yFfQVRpSPz', | |
23 | 'ext': 'mp3', | |
24 | 'title': 'Door Knock Door 1', | |
25 | 'alt_title': 'Door Knock Door 1', | |
26 | 'tags': ['foley', 'door', 'knock', 'glass', 'window', 'glass door knock'], | |
27 | 'categories': ['Misc. Door'], | |
28 | 'duration': 1, | |
29 | 'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/default-sfx/3000x3000.jpg', | |
30 | 'timestamp': 1415320353, | |
31 | 'upload_date': '20141107', | |
32 | }, | |
33 | }, { | |
34 | 'url': 'https://www.epidemicsound.com/track/mj8GTTwsZd/', | |
35 | 'md5': 'c82b745890f9baf18dc2f8d568ee3830', | |
36 | 'info_dict': { | |
37 | 'id': '148700', | |
38 | 'display_id': 'mj8GTTwsZd', | |
39 | 'ext': 'mp3', | |
40 | 'title': 'Noplace', | |
41 | 'tags': ['liquid drum n bass', 'energetic'], | |
42 | 'categories': ['drum and bass'], | |
43 | 'duration': 237, | |
44 | 'timestamp': 1694426482, | |
45 | 'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/11138/3000x3000.jpg', | |
46 | 'upload_date': '20230911', | |
47 | 'release_timestamp': 1700535606, | |
48 | 'release_date': '20231121', | |
49 | }, | |
50 | }] | |
51 | ||
52 | @staticmethod | |
53 | def _epidemic_parse_thumbnail(url: str): | |
54 | if not url_or_none(url): | |
55 | return None | |
56 | ||
57 | return { | |
58 | 'url': url, | |
59 | **(traverse_obj(url, ({parse_qs}, { | |
60 | 'width': ('width', 0, {int_or_none}), | |
61 | 'height': ('height', 0, {int_or_none}), | |
62 | })) or parse_resolution(url)), | |
63 | } | |
64 | ||
65 | @staticmethod | |
66 | def _epidemic_fmt_or_none(f): | |
67 | if not f.get('format'): | |
68 | f['format'] = f.get('format_id') | |
69 | elif not f.get('format_id'): | |
70 | f['format_id'] = f['format'] | |
71 | if not f['url'] or not f['format']: | |
72 | return None | |
73 | if f.get('format_note'): | |
74 | f['format_note'] = f'track ID {f["format_note"]}' | |
75 | if f['format'] != 'full': | |
76 | f['preference'] = -2 | |
77 | return f | |
78 | ||
79 | def _real_extract(self, url): | |
80 | video_id = self._match_id(url) | |
81 | json_data = self._download_json(f'https://www.epidemicsound.com/json/track/{video_id}', video_id) | |
82 | ||
83 | thumbnails = traverse_obj(json_data, [('imageUrl', 'cover')]) | |
84 | thumb_base_url = traverse_obj(json_data, ('coverArt', 'baseUrl', {url_or_none})) | |
85 | if thumb_base_url: | |
86 | thumbnails.extend(traverse_obj(json_data, ( | |
87 | 'coverArt', 'sizes', ..., {thumb_base_url.__add__}))) | |
88 | ||
89 | return traverse_obj(json_data, { | |
90 | 'id': ('id', {str_or_none}), | |
91 | 'display_id': ('publicSlug', {str}), | |
92 | 'title': ('title', {str}), | |
93 | 'alt_title': ('oldTitle', {str}), | |
94 | 'duration': ('length', {float_or_none}), | |
95 | 'timestamp': ('added', {parse_iso8601}), | |
96 | 'release_timestamp': ('releaseDate', {parse_iso8601}), | |
97 | 'categories': ('genres', ..., 'tag', {str}), | |
98 | 'tags': ('metadataTags', ..., {str}), | |
99 | 'age_limit': ('isExplicit', {lambda b: 18 if b else None}), | |
100 | 'thumbnails': ({lambda _: thumbnails}, {orderedSet}, ..., {self._epidemic_parse_thumbnail}), | |
101 | 'formats': ('stems', {dict.items}, ..., { | |
102 | 'format': (0, {str_or_none}), | |
103 | 'format_note': (1, 's3TrackId', {str_or_none}), | |
104 | 'format_id': (1, 'stemType', {str}), | |
105 | 'url': (1, 'lqMp3Url', {url_or_none}), | |
106 | }, {self._epidemic_fmt_or_none}), | |
107 | }) |