You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

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