]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/streetvoice.py
[thestar] Add new extractor(closes #5955)
[youtube-dl] / youtube_dl / extractor / streetvoice.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import unified_strdate
7
8
9 class StreetVoiceIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:.+?\.)?streetvoice\.com/[^/]+/songs/(?P<id>[0-9]+)'
11     _TESTS = [{
12         'url': 'http://streetvoice.com/skippylu/songs/94440/',
13         'md5': '15974627fc01a29e492c98593c2fd472',
14         'info_dict': {
15             'id': '94440',
16             'ext': 'mp3',
17             'filesize': 4167053,
18             'title': '輸',
19             'description': 'Crispy脆樂團 - 輸',
20             'thumbnail': 're:^https?://.*\.jpg$',
21             'duration': 260,
22             'upload_date': '20091018',
23             'uploader': 'Crispy脆樂團',
24             'uploader_id': '627810',
25         }
26     }, {
27         'url': 'http://tw.streetvoice.com/skippylu/songs/94440/',
28         'only_matching': True,
29     }]
30
31     def _real_extract(self, url):
32         song_id = self._match_id(url)
33
34         song = self._download_json(
35             'http://streetvoice.com/music/api/song/%s' % song_id, song_id)
36
37         title = song['name']
38         author = song['musician']['name']
39
40         return {
41             'id': song_id,
42             'url': song['file'],
43             'filesize': song.get('size'),
44             'title': title,
45             'description': '%s - %s' % (author, title),
46             'thumbnail': self._proto_relative_url(song.get('image'), 'http:'),
47             'duration': song.get('length'),
48             'upload_date': unified_strdate(song.get('created_at')),
49             'uploader': author,
50             'uploader_id': compat_str(song['musician']['id']),
51         }