drooble.py 4.1 KB

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