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