[reverbnation] Modernize test
[youtube-dl] / youtube_dl / extractor / reverbnation.py
1 from __future__ import unicode_literals
2
3 import re
4 import time
5
6 from .common import InfoExtractor
7 from ..utils import strip_jsonp
8
9
10 class ReverbNationIE(InfoExtractor):
11     _VALID_URL = r'^https?://(?:www\.)?reverbnation\.com/.*?/song/(?P<id>\d+).*?$'
12     _TESTS = [{
13         'url': 'http://www.reverbnation.com/alkilados/song/16965047-mona-lisa',
14         'md5': '3da12ebca28c67c111a7f8b262d3f7a7',
15         'info_dict': {
16             "id": "16965047",
17             "ext": "mp3",
18             "title": "MONA LISA",
19             "uploader": "ALKILADOS",
20             "uploader_id": 216429,
21             "thumbnail": "re:^https://gp1\.wac\.edgecastcdn\.net/.*?\.jpg$"
22         },
23     }]
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         song_id = mobj.group('id')
28
29         api_res = self._download_json(
30             'https://api.reverbnation.com/song/%s?callback=api_response_5&_=%d'
31                 % (song_id, int(time.time() * 1000)),
32             song_id,
33             transform_source=strip_jsonp,
34             note='Downloading information of song %s' % song_id
35         )
36
37         return {
38             'id': song_id,
39             'title': api_res.get('name'),
40             'url': api_res.get('url'),
41             'uploader': api_res.get('artist', {}).get('name'),
42             'uploader_id': api_res.get('artist', {}).get('id'),
43             'thumbnail': self._proto_relative_url(
44                 api_res.get('image', api_res.get('thumbnail'))),
45             'ext': 'mp3',
46             'vcodec': 'none',
47         }