reverbnation.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. qualities,
  4. str_or_none,
  5. )
  6. class ReverbNationIE(InfoExtractor):
  7. _VALID_URL = r'^https?://(?:www\.)?reverbnation\.com/.*?/song/(?P<id>\d+).*?$'
  8. _TESTS = [{
  9. 'url': 'http://www.reverbnation.com/alkilados/song/16965047-mona-lisa',
  10. 'md5': 'c0aaf339bcee189495fdf5a8c8ba8645',
  11. 'info_dict': {
  12. 'id': '16965047',
  13. 'ext': 'mp3',
  14. 'title': 'MONA LISA',
  15. 'uploader': 'ALKILADOS',
  16. 'uploader_id': '216429',
  17. 'thumbnail': r're:^https?://.*\.jpg',
  18. },
  19. }]
  20. def _real_extract(self, url):
  21. song_id = self._match_id(url)
  22. api_res = self._download_json(
  23. f'https://api.reverbnation.com/song/{song_id}',
  24. song_id,
  25. note=f'Downloading information of song {song_id}',
  26. )
  27. THUMBNAILS = ('thumbnail', 'image')
  28. quality = qualities(THUMBNAILS)
  29. thumbnails = []
  30. for thumb_key in THUMBNAILS:
  31. if api_res.get(thumb_key):
  32. thumbnails.append({
  33. 'url': api_res[thumb_key],
  34. 'preference': quality(thumb_key),
  35. })
  36. return {
  37. 'id': song_id,
  38. 'title': api_res['name'],
  39. 'url': api_res['url'],
  40. 'uploader': api_res.get('artist', {}).get('name'),
  41. 'uploader_id': str_or_none(api_res.get('artist', {}).get('id')),
  42. 'thumbnails': thumbnails,
  43. 'ext': 'mp3',
  44. 'vcodec': 'none',
  45. }