mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-27 06:36:49 +01:00
parent
ecaa535cf4
commit
2da9a86399
@ -2,25 +2,40 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_str
|
from ..utils import (
|
||||||
from ..utils import unified_strdate
|
int_or_none,
|
||||||
|
parse_iso8601,
|
||||||
|
str_or_none,
|
||||||
|
strip_or_none,
|
||||||
|
try_get,
|
||||||
|
urljoin,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StreetVoiceIE(InfoExtractor):
|
class StreetVoiceIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:.+?\.)?streetvoice\.com/[^/]+/songs/(?P<id>[0-9]+)'
|
_VALID_URL = r'https?://(?:.+?\.)?streetvoice\.com/[^/]+/songs/(?P<id>[0-9]+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://streetvoice.com/skippylu/songs/94440/',
|
'url': 'https://streetvoice.com/skippylu/songs/123688/',
|
||||||
'md5': '15974627fc01a29e492c98593c2fd472',
|
'md5': '0eb535970629a5195685355f3ed60bfd',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '94440',
|
'id': '123688',
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
'title': '輸',
|
'title': '流浪',
|
||||||
'description': 'Crispy脆樂團 - 輸',
|
'description': 'md5:8eb0bfcc9dcd8aa82bd6efca66e3fea6',
|
||||||
'thumbnail': r're:^https?://.*\.jpg$',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'duration': 260,
|
'duration': 270,
|
||||||
'upload_date': '20091018',
|
'upload_date': '20100923',
|
||||||
'uploader': 'Crispy脆樂團',
|
'uploader': 'Crispy脆樂團',
|
||||||
'uploader_id': '627810',
|
'uploader_id': '627810',
|
||||||
|
'uploader_url': 're:^https?://streetvoice.com/skippylu/',
|
||||||
|
'timestamp': 1285261661,
|
||||||
|
'view_count': int,
|
||||||
|
'like_count': int,
|
||||||
|
'comment_count': int,
|
||||||
|
'repost_count': int,
|
||||||
|
'track': '流浪',
|
||||||
|
'track_id': '123688',
|
||||||
|
'album': '2010',
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://tw.streetvoice.com/skippylu/songs/94440/',
|
'url': 'http://tw.streetvoice.com/skippylu/songs/94440/',
|
||||||
@ -29,21 +44,57 @@ class StreetVoiceIE(InfoExtractor):
|
|||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
song_id = self._match_id(url)
|
song_id = self._match_id(url)
|
||||||
|
base_url = 'https://streetvoice.com/api/v4/song/%s/' % song_id
|
||||||
song = self._download_json(
|
song = self._download_json(base_url, song_id, query={
|
||||||
'https://streetvoice.com/api/v1/public/song/%s/' % song_id, song_id, data=b'')
|
'fields': 'album,comments_count,created_at,id,image,length,likes_count,name,nickname,plays_count,profile,share_count,synopsis,user,username',
|
||||||
|
})
|
||||||
title = song['name']
|
title = song['name']
|
||||||
author = song['user']['nickname']
|
|
||||||
|
formats = []
|
||||||
|
for suffix, format_id in [('hls/file', 'hls'), ('file', 'http'), ('file/original', 'original')]:
|
||||||
|
f_url = (self._download_json(
|
||||||
|
base_url + suffix + '/', song_id,
|
||||||
|
'Downloading %s format URL' % format_id,
|
||||||
|
data=b'', fatal=False) or {}).get('file')
|
||||||
|
if not f_url:
|
||||||
|
continue
|
||||||
|
f = {
|
||||||
|
'ext': 'mp3',
|
||||||
|
'format_id': format_id,
|
||||||
|
'url': f_url,
|
||||||
|
'vcodec': 'none',
|
||||||
|
}
|
||||||
|
if format_id == 'hls':
|
||||||
|
f['protocol'] = 'm3u8_native'
|
||||||
|
abr = self._search_regex(r'\.mp3\.(\d+)k', f_url, 'bitrate', default=None)
|
||||||
|
if abr:
|
||||||
|
abr = int(abr)
|
||||||
|
f.update({
|
||||||
|
'abr': abr,
|
||||||
|
'tbr': abr,
|
||||||
|
})
|
||||||
|
formats.append(f)
|
||||||
|
|
||||||
|
user = song.get('user') or {}
|
||||||
|
username = user.get('username')
|
||||||
|
get_count = lambda x: int_or_none(song.get(x + '_count'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': song_id,
|
'id': song_id,
|
||||||
'url': song['file'],
|
'formats': formats,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': '%s - %s' % (author, title),
|
'description': strip_or_none(song.get('synopsis')),
|
||||||
'thumbnail': self._proto_relative_url(song.get('image'), 'http:'),
|
'thumbnail': song.get('image'),
|
||||||
'duration': song.get('length'),
|
'duration': int_or_none(song.get('length')),
|
||||||
'upload_date': unified_strdate(song.get('created_at')),
|
'timestamp': parse_iso8601(song.get('created_at')),
|
||||||
'uploader': author,
|
'uploader': try_get(user, lambda x: x['profile']['nickname']),
|
||||||
'uploader_id': compat_str(song['user']['id']),
|
'uploader_id': str_or_none(user.get('id')),
|
||||||
|
'uploader_url': urljoin(url, '/%s/' % username) if username else None,
|
||||||
|
'view_count': get_count('plays'),
|
||||||
|
'like_count': get_count('likes'),
|
||||||
|
'comment_count': get_count('comments'),
|
||||||
|
'repost_count': get_count('share'),
|
||||||
|
'track': title,
|
||||||
|
'track_id': song_id,
|
||||||
|
'album': try_get(song, lambda x: x['album']['name']),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user