]>
Commit | Line | Data |
---|---|---|
1 | import json | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | int_or_none, | |
7 | try_get, | |
8 | ) | |
9 | ||
10 | ||
11 | class DroobleIE(InfoExtractor): | |
12 | _VALID_URL = r'''(?x)https?://drooble\.com/(?: | |
13 | (?:(?P<user>[^/]+)/)?(?P<kind>song|videos|music/albums)/(?P<id>\d+)| | |
14 | (?P<user_2>[^/]+)/(?P<kind_2>videos|music)) | |
15 | ''' | |
16 | _TESTS = [{ | |
17 | 'url': 'https://drooble.com/song/2858030', | |
18 | 'md5': '5ffda90f61c7c318dc0c3df4179eb064', | |
19 | 'info_dict': { | |
20 | 'id': '2858030', | |
21 | 'ext': 'mp3', | |
22 | 'title': 'Skankocillin', | |
23 | 'upload_date': '20200801', | |
24 | 'timestamp': 1596241390, | |
25 | 'uploader_id': '95894', | |
26 | 'uploader': 'Bluebeat Shelter', | |
27 | }, | |
28 | }, { | |
29 | 'url': 'https://drooble.com/karl340758/videos/2859183', | |
30 | 'info_dict': { | |
31 | 'id': 'J6QCQY_I5Tk', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'Skankocillin', | |
34 | 'uploader_id': 'UCrSRoI5vVyeYihtWEYua7rg', | |
35 | 'description': 'md5:ffc0bd8ba383db5341a86a6cd7d9bcca', | |
36 | 'upload_date': '20200731', | |
37 | 'uploader': 'Bluebeat Shelter', | |
38 | }, | |
39 | }, { | |
40 | 'url': 'https://drooble.com/karl340758/music/albums/2858031', | |
41 | 'info_dict': { | |
42 | 'id': '2858031', | |
43 | }, | |
44 | 'playlist_mincount': 8, | |
45 | }, { | |
46 | 'url': 'https://drooble.com/karl340758/music', | |
47 | 'info_dict': { | |
48 | 'id': 'karl340758', | |
49 | }, | |
50 | 'playlist_mincount': 8, | |
51 | }, { | |
52 | 'url': 'https://drooble.com/karl340758/videos', | |
53 | 'info_dict': { | |
54 | 'id': 'karl340758', | |
55 | }, | |
56 | 'playlist_mincount': 8, | |
57 | }] | |
58 | ||
59 | def _call_api(self, method, video_id, data=None): | |
60 | response = self._download_json( | |
61 | f'https://drooble.com/api/dt/{method}', video_id, data=json.dumps(data).encode()) | |
62 | if not response[0]: | |
63 | raise ExtractorError('Unable to download JSON metadata') | |
64 | return response[1] | |
65 | ||
66 | def _real_extract(self, url): | |
67 | mobj = self._match_valid_url(url) | |
68 | user = mobj.group('user') or mobj.group('user_2') | |
69 | kind = mobj.group('kind') or mobj.group('kind_2') | |
70 | display_id = mobj.group('id') or user | |
71 | ||
72 | if mobj.group('kind_2') == 'videos': | |
73 | data = {'from_user': display_id, 'album': -1, 'limit': 18, 'offset': 0, 'order': 'new2old', 'type': 'video'} | |
74 | elif kind in ('music/albums', 'music'): | |
75 | data = {'user': user, 'public_only': True, 'individual_limit': {'singles': 1, 'albums': 1, 'playlists': 1}} | |
76 | else: | |
77 | data = {'url_slug': display_id, 'children': 10, 'order': 'old2new'} | |
78 | ||
79 | method = 'getMusicOverview' if kind in ('music/albums', 'music') else 'getElements' | |
80 | json_data = self._call_api(method, display_id, data=data) | |
81 | if kind in ('music/albums', 'music'): | |
82 | json_data = json_data['singles']['list'] | |
83 | ||
84 | entites = [] | |
85 | for media in json_data: | |
86 | url = media.get('external_media_url') or media.get('link') | |
87 | if url.startswith('https://www.youtube.com'): | |
88 | entites.append({ | |
89 | '_type': 'url', | |
90 | 'url': url, | |
91 | 'ie_key': 'Youtube', | |
92 | }) | |
93 | continue | |
94 | is_audio = (media.get('type') or '').lower() == 'audio' | |
95 | entites.append({ | |
96 | 'url': url, | |
97 | 'id': media['id'], | |
98 | 'title': media['title'], | |
99 | 'duration': int_or_none(media.get('duration')), | |
100 | 'timestamp': int_or_none(media.get('timestamp')), | |
101 | 'album': try_get(media, lambda x: x['album']['title']), | |
102 | 'uploader': try_get(media, lambda x: x['creator']['display_name']), | |
103 | 'uploader_id': try_get(media, lambda x: x['creator']['id']), | |
104 | 'thumbnail': media.get('image_comment'), | |
105 | 'like_count': int_or_none(media.get('likes')), | |
106 | 'vcodec': 'none' if is_audio else None, | |
107 | 'ext': 'mp3' if is_audio else None, | |
108 | }) | |
109 | ||
110 | if len(entites) > 1: | |
111 | return self.playlist_result(entites, display_id) | |
112 | ||
113 | return entites[0] |