yt-dlc/youtube_dl/extractor/reverbnation.py

52 lines
1.5 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import str_or_none
class ReverbNationIE(InfoExtractor):
_VALID_URL = r'^https?://(?:www\.)?reverbnation\.com/.*?/song/(?P<id>\d+).*?$'
_TESTS = [{
'url': 'http://www.reverbnation.com/alkilados/song/16965047-mona-lisa',
2016-09-30 17:54:12 +00:00
'md5': 'c0aaf339bcee189495fdf5a8c8ba8645',
'info_dict': {
2016-02-14 09:37:17 +00:00
'id': '16965047',
'ext': 'mp3',
'title': 'MONA LISA',
'uploader': 'ALKILADOS',
'uploader_id': '216429',
2016-09-30 17:54:12 +00:00
'thumbnail': 're:^https?://.*\.jpg',
},
}]
def _real_extract(self, url):
2016-09-30 17:54:12 +00:00
song_id = self._match_id(url)
api_res = self._download_json(
'https://api.reverbnation.com/song/%s' % song_id,
song_id,
note='Downloading information of song %s' % song_id
)
2016-09-30 17:54:12 +00:00
thumbnails = []
if api_res.get('image'):
thumbnails.append({
'url': api_res.get('image'),
})
if api_res.get('thumbnail'):
thumbnails.append({
'url': api_res.get('thumbnail'),
'preference': -2,
})
return {
'id': song_id,
2016-09-30 17:54:12 +00:00
'title': api_res['name'],
'url': api_res['url'],
'uploader': api_res.get('artist', {}).get('name'),
'uploader_id': str_or_none(api_res.get('artist', {}).get('id')),
2016-09-30 17:54:12 +00:00
'thumbnails': thumbnails,
'ext': 'mp3',
'vcodec': 'none',
}