reverbnation.py 1.5 KB

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