[reverbnation] Modernize
[youtube-dl] / youtube_dl / extractor / reverbnation.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import str_or_none
5
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': 're:^https?://.*\.jpg',
19         },
20     }]
21
22     def _real_extract(self, url):
23         song_id = self._match_id(url)
24
25         api_res = self._download_json(
26             'https://api.reverbnation.com/song/%s' % song_id,
27             song_id,
28             note='Downloading information of song %s' % song_id
29         )
30
31         thumbnails = []
32         if api_res.get('image'):
33             thumbnails.append({
34                 'url': api_res.get('image'),
35             })
36         if api_res.get('thumbnail'):
37             thumbnails.append({
38                 'url': api_res.get('thumbnail'),
39                 'preference': -2,
40             })
41
42         return {
43             'id': song_id,
44             'title': api_res['name'],
45             'url': api_res['url'],
46             'uploader': api_res.get('artist', {}).get('name'),
47             'uploader_id': str_or_none(api_res.get('artist', {}).get('id')),
48             'thumbnails': thumbnails,
49             'ext': 'mp3',
50             'vcodec': 'none',
51         }