[ie/dropbox] Fix password-protected video extraction (#11636)
[yt-dlp3.git] / yt_dlp / extractor / streetvoice.py
blob60056f7cbfeddc94496e1a6a7d410ae871524e13
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_iso8601,
5 str_or_none,
6 strip_or_none,
7 try_get,
8 urljoin,
12 class StreetVoiceIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:.+?\.)?streetvoice\.com/[^/]+/songs/(?P<id>[0-9]+)'
14 _TESTS = [{
15 'url': 'https://streetvoice.com/skippylu/songs/123688/',
16 'md5': '0eb535970629a5195685355f3ed60bfd',
17 'info_dict': {
18 'id': '123688',
19 'ext': 'mp3',
20 'title': '流浪',
21 'description': 'md5:8eb0bfcc9dcd8aa82bd6efca66e3fea6',
22 'thumbnail': r're:^https?://.*\.jpg',
23 'duration': 270,
24 'upload_date': '20100923',
25 'uploader': 'Crispy脆樂團',
26 'uploader_id': '627810',
27 'uploader_url': 're:^https?://streetvoice.com/skippylu/',
28 'timestamp': 1285261661,
29 'view_count': int,
30 'like_count': int,
31 'comment_count': int,
32 'repost_count': int,
33 'track': '流浪',
34 'track_id': '123688',
35 'album': '2010',
37 }, {
38 'url': 'http://tw.streetvoice.com/skippylu/songs/94440/',
39 'only_matching': True,
42 def _real_extract(self, url):
43 song_id = self._match_id(url)
44 base_url = f'https://streetvoice.com/api/v4/song/{song_id}/'
45 song = self._download_json(base_url, song_id, query={
46 'fields': 'album,comments_count,created_at,id,image,length,likes_count,name,nickname,plays_count,profile,share_count,synopsis,user,username',
48 title = song['name']
50 formats = []
51 for suffix, format_id in [('hls/file', 'hls'), ('file', 'http'), ('file/original', 'original')]:
52 f_url = (self._download_json(
53 base_url + suffix + '/', song_id,
54 f'Downloading {format_id} format URL',
55 data=b'', fatal=False) or {}).get('file')
56 if not f_url:
57 continue
58 f = {
59 'ext': 'mp3',
60 'format_id': format_id,
61 'url': f_url,
62 'vcodec': 'none',
64 if format_id == 'hls':
65 f['protocol'] = 'm3u8_native'
66 abr = self._search_regex(r'\.mp3\.(\d+)k', f_url, 'bitrate', default=None)
67 if abr:
68 abr = int(abr)
69 f.update({
70 'abr': abr,
71 'tbr': abr,
73 formats.append(f)
75 user = song.get('user') or {}
76 username = user.get('username')
77 get_count = lambda x: int_or_none(song.get(x + '_count'))
79 return {
80 'id': song_id,
81 'formats': formats,
82 'title': title,
83 'description': strip_or_none(song.get('synopsis')),
84 'thumbnail': song.get('image'),
85 'duration': int_or_none(song.get('length')),
86 'timestamp': parse_iso8601(song.get('created_at')),
87 'uploader': try_get(user, lambda x: x['profile']['nickname']),
88 'uploader_id': str_or_none(user.get('id')),
89 'uploader_url': urljoin(url, f'/{username}/') if username else None,
90 'view_count': get_count('plays'),
91 'like_count': get_count('likes'),
92 'comment_count': get_count('comments'),
93 'repost_count': get_count('share'),
94 'track': title,
95 'track_id': song_id,
96 'album': try_get(song, lambda x: x['album']['name']),