mirror of https://github.com/yt-dlp/yt-dlp.git
Compare commits
9 Commits
0ce1e1fb71
...
0d7374ad80
Author | SHA1 | Date |
---|---|---|
Lev | 0d7374ad80 | |
sepro | 96da952504 | |
bashonly | bec9a59e8e | |
bashonly | 036e0d92c6 | |
Lev Plyusnin | a177349759 | |
Lev Plyusnin | e878873e7e | |
Lev Plyusnin | 32cd5baf18 | |
Lev Plyusnin | ec57f55b92 | |
Lev Plyusnin | 1a0deeecbc |
|
@ -785,6 +785,25 @@ class TestHTTPImpersonateRequestHandler(TestRequestHandlerBase):
|
|||
assert res.status == 200
|
||||
assert std_headers['user-agent'].lower() not in res.read().decode().lower()
|
||||
|
||||
def test_response_extensions(self, handler):
|
||||
with handler() as rh:
|
||||
for target in rh.supported_targets:
|
||||
request = Request(
|
||||
f'http://127.0.0.1:{self.http_port}/gen_200', extensions={'impersonate': target})
|
||||
res = validate_and_send(rh, request)
|
||||
assert res.extensions['impersonate'] == rh._get_request_target(request)
|
||||
|
||||
def test_http_error_response_extensions(self, handler):
|
||||
with handler() as rh:
|
||||
for target in rh.supported_targets:
|
||||
request = Request(
|
||||
f'http://127.0.0.1:{self.http_port}/gen_404', extensions={'impersonate': target})
|
||||
try:
|
||||
validate_and_send(rh, request)
|
||||
except HTTPError as e:
|
||||
res = e.response
|
||||
assert res.extensions['impersonate'] == rh._get_request_target(request)
|
||||
|
||||
|
||||
class TestRequestHandlerMisc:
|
||||
"""Misc generic tests for request handlers, not related to request or validation testing"""
|
||||
|
|
|
@ -2136,6 +2136,11 @@ class YoutubeDL:
|
|||
|
||||
def _check_formats(self, formats):
|
||||
for f in formats:
|
||||
working = f.get('__working')
|
||||
if working is not None:
|
||||
if working:
|
||||
yield f
|
||||
continue
|
||||
self.to_screen('[info] Testing format %s' % f['format_id'])
|
||||
path = self.get_output_path('temp')
|
||||
if not self._ensure_dir_exists(f'{path}/'):
|
||||
|
@ -2152,33 +2157,44 @@ class YoutubeDL:
|
|||
os.remove(temp_file.name)
|
||||
except OSError:
|
||||
self.report_warning('Unable to delete temporary file "%s"' % temp_file.name)
|
||||
f['__working'] = success
|
||||
if success:
|
||||
yield f
|
||||
else:
|
||||
self.to_screen('[info] Unable to download format %s. Skipping...' % f['format_id'])
|
||||
|
||||
def _select_formats(self, formats, selector):
|
||||
return list(selector({
|
||||
'formats': formats,
|
||||
'has_merged_format': any('none' not in (f.get('acodec'), f.get('vcodec')) for f in formats),
|
||||
'incomplete_formats': (all(f.get('vcodec') == 'none' for f in formats) # No formats with video
|
||||
or all(f.get('acodec') == 'none' for f in formats)), # OR, No formats with audio
|
||||
}))
|
||||
|
||||
def _default_format_spec(self, info_dict, download=True):
|
||||
download = download and not self.params.get('simulate')
|
||||
prefer_best = download and (
|
||||
self.params['outtmpl']['default'] == '-'
|
||||
or info_dict.get('is_live') and not self.params.get('live_from_start'))
|
||||
|
||||
def can_merge():
|
||||
merger = FFmpegMergerPP(self)
|
||||
return merger.available and merger.can_merge()
|
||||
|
||||
prefer_best = (
|
||||
not self.params.get('simulate')
|
||||
and download
|
||||
and (
|
||||
not can_merge()
|
||||
or info_dict.get('is_live') and not self.params.get('live_from_start')
|
||||
or self.params['outtmpl']['default'] == '-'))
|
||||
compat = (
|
||||
prefer_best
|
||||
or self.params.get('allow_multiple_audio_streams', False)
|
||||
or 'format-spec' in self.params['compat_opts'])
|
||||
if not prefer_best and download and not can_merge():
|
||||
prefer_best = True
|
||||
formats = self._get_formats(info_dict)
|
||||
evaluate_formats = lambda spec: self._select_formats(formats, self.build_format_selector(spec))
|
||||
if evaluate_formats('b/bv+ba') != evaluate_formats('bv*+ba/b'):
|
||||
self.report_warning('ffmpeg not found. The downloaded format may not be the best available. '
|
||||
'Installing ffmpeg is strongly recommended: https://github.com/yt-dlp/yt-dlp#dependencies')
|
||||
|
||||
return (
|
||||
'best/bestvideo+bestaudio' if prefer_best
|
||||
else 'bestvideo*+bestaudio/best' if not compat
|
||||
else 'bestvideo+bestaudio/best')
|
||||
compat = (self.params.get('allow_multiple_audio_streams')
|
||||
or 'format-spec' in self.params['compat_opts'])
|
||||
|
||||
return ('best/bestvideo+bestaudio' if prefer_best
|
||||
else 'bestvideo+bestaudio/best' if compat
|
||||
else 'bestvideo*+bestaudio/best')
|
||||
|
||||
def build_format_selector(self, format_spec):
|
||||
def syntax_error(note, start):
|
||||
|
@ -2928,12 +2944,7 @@ class YoutubeDL:
|
|||
self.write_debug(f'Default format spec: {req_format}')
|
||||
format_selector = self.build_format_selector(req_format)
|
||||
|
||||
formats_to_download = list(format_selector({
|
||||
'formats': formats,
|
||||
'has_merged_format': any('none' not in (f.get('acodec'), f.get('vcodec')) for f in formats),
|
||||
'incomplete_formats': (all(f.get('vcodec') == 'none' for f in formats) # No formats with video
|
||||
or all(f.get('acodec') == 'none' for f in formats)), # OR, No formats with audio
|
||||
}))
|
||||
formats_to_download = self._select_formats(formats, format_selector)
|
||||
if interactive_format_selection and not formats_to_download:
|
||||
self.report_error('Requested format is not available', tb=False, is_error=False)
|
||||
continue
|
||||
|
|
|
@ -219,7 +219,29 @@ class PatreonIE(PatreonBaseIE):
|
|||
'thumbnail': r're:^https?://.+',
|
||||
},
|
||||
'params': {'skip_download': 'm3u8'},
|
||||
}, {
|
||||
# multiple attachments/embeds
|
||||
'url': 'https://www.patreon.com/posts/holy-wars-solos-100601977',
|
||||
'playlist_count': 3,
|
||||
'info_dict': {
|
||||
'id': '100601977',
|
||||
'title': '"Holy Wars" (Megadeth) Solos Transcription & Lesson/Analysis',
|
||||
'description': 'md5:d099ab976edfce6de2a65c2b169a88d3',
|
||||
'uploader': 'Bradley Hall',
|
||||
'uploader_id': '24401883',
|
||||
'uploader_url': 'https://www.patreon.com/bradleyhallguitar',
|
||||
'channel_id': '3193932',
|
||||
'channel_url': 'https://www.patreon.com/bradleyhallguitar',
|
||||
'channel_follower_count': int,
|
||||
'timestamp': 1710777855,
|
||||
'upload_date': '20240318',
|
||||
'like_count': int,
|
||||
'comment_count': int,
|
||||
'thumbnail': r're:^https?://.+',
|
||||
},
|
||||
'skip': 'Patron-only content',
|
||||
}]
|
||||
_RETURN_TYPE = 'video'
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
|
@ -234,58 +256,54 @@ class PatreonIE(PatreonBaseIE):
|
|||
'include': 'audio,user,user_defined_tags,campaign,attachments_media',
|
||||
})
|
||||
attributes = post['data']['attributes']
|
||||
title = attributes['title'].strip()
|
||||
image = attributes.get('image') or {}
|
||||
info = {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': clean_html(attributes.get('content')),
|
||||
'thumbnail': image.get('large_url') or image.get('url'),
|
||||
'timestamp': parse_iso8601(attributes.get('published_at')),
|
||||
'like_count': int_or_none(attributes.get('like_count')),
|
||||
'comment_count': int_or_none(attributes.get('comment_count')),
|
||||
}
|
||||
can_view_post = traverse_obj(attributes, 'current_user_can_view')
|
||||
if can_view_post and info['comment_count']:
|
||||
info['__post_extractor'] = self.extract_comments(video_id)
|
||||
info = traverse_obj(attributes, {
|
||||
'title': ('title', {str.strip}),
|
||||
'description': ('content', {clean_html}),
|
||||
'thumbnail': ('image', ('large_url', 'url'), {url_or_none}, any),
|
||||
'timestamp': ('published_at', {parse_iso8601}),
|
||||
'like_count': ('like_count', {int_or_none}),
|
||||
'comment_count': ('comment_count', {int_or_none}),
|
||||
})
|
||||
|
||||
for i in post.get('included', []):
|
||||
i_type = i.get('type')
|
||||
if i_type == 'media':
|
||||
media_attributes = i.get('attributes') or {}
|
||||
download_url = media_attributes.get('download_url')
|
||||
entries = []
|
||||
idx = 0
|
||||
for include in traverse_obj(post, ('included', lambda _, v: v['type'])):
|
||||
include_type = include['type']
|
||||
if include_type == 'media':
|
||||
media_attributes = traverse_obj(include, ('attributes', {dict})) or {}
|
||||
download_url = url_or_none(media_attributes.get('download_url'))
|
||||
ext = mimetype2ext(media_attributes.get('mimetype'))
|
||||
|
||||
# if size_bytes is None, this media file is likely unavailable
|
||||
# See: https://github.com/yt-dlp/yt-dlp/issues/4608
|
||||
size_bytes = int_or_none(media_attributes.get('size_bytes'))
|
||||
if download_url and ext in KNOWN_EXTENSIONS and size_bytes is not None:
|
||||
# XXX: what happens if there are multiple attachments?
|
||||
return {
|
||||
**info,
|
||||
idx += 1
|
||||
entries.append({
|
||||
'id': f'{video_id}-{idx}',
|
||||
'ext': ext,
|
||||
'filesize': size_bytes,
|
||||
'url': download_url,
|
||||
}
|
||||
elif i_type == 'user':
|
||||
user_attributes = i.get('attributes')
|
||||
if user_attributes:
|
||||
info.update({
|
||||
'uploader': user_attributes.get('full_name'),
|
||||
'uploader_id': str_or_none(i.get('id')),
|
||||
'uploader_url': user_attributes.get('url'),
|
||||
})
|
||||
|
||||
elif i_type == 'post_tag':
|
||||
info.setdefault('tags', []).append(traverse_obj(i, ('attributes', 'value')))
|
||||
elif include_type == 'user':
|
||||
info.update(traverse_obj(include, {
|
||||
'uploader': ('attributes', 'full_name', {str}),
|
||||
'uploader_id': ('id', {str_or_none}),
|
||||
'uploader_url': ('attributes', 'url', {url_or_none}),
|
||||
}))
|
||||
|
||||
elif i_type == 'campaign':
|
||||
info.update({
|
||||
'channel': traverse_obj(i, ('attributes', 'title')),
|
||||
'channel_id': str_or_none(i.get('id')),
|
||||
'channel_url': traverse_obj(i, ('attributes', 'url')),
|
||||
'channel_follower_count': int_or_none(traverse_obj(i, ('attributes', 'patron_count'))),
|
||||
})
|
||||
elif include_type == 'post_tag':
|
||||
if post_tag := traverse_obj(include, ('attributes', 'value', {str})):
|
||||
info.setdefault('tags', []).append(post_tag)
|
||||
|
||||
elif include_type == 'campaign':
|
||||
info.update(traverse_obj(include, {
|
||||
'channel': ('attributes', 'title', {str}),
|
||||
'channel_id': ('id', {str_or_none}),
|
||||
'channel_url': ('attributes', 'url', {url_or_none}),
|
||||
'channel_follower_count': ('attributes', 'patron_count', {int_or_none}),
|
||||
}))
|
||||
|
||||
# handle Vimeo embeds
|
||||
if traverse_obj(attributes, ('embed', 'provider')) == 'Vimeo':
|
||||
|
@ -296,36 +314,50 @@ class PatreonIE(PatreonBaseIE):
|
|||
v_url, video_id, 'Checking Vimeo embed URL',
|
||||
headers={'Referer': 'https://patreon.com/'},
|
||||
fatal=False, errnote=False):
|
||||
return self.url_result(
|
||||
entries.append(self.url_result(
|
||||
VimeoIE._smuggle_referrer(v_url, 'https://patreon.com/'),
|
||||
VimeoIE, url_transparent=True, **info)
|
||||
VimeoIE, url_transparent=True))
|
||||
|
||||
embed_url = traverse_obj(attributes, ('embed', 'url', {url_or_none}))
|
||||
if embed_url and self._request_webpage(embed_url, video_id, 'Checking embed URL', fatal=False, errnote=False):
|
||||
return self.url_result(embed_url, **info)
|
||||
entries.append(self.url_result(embed_url))
|
||||
|
||||
post_file = traverse_obj(attributes, 'post_file')
|
||||
post_file = traverse_obj(attributes, ('post_file', {dict}))
|
||||
if post_file:
|
||||
name = post_file.get('name')
|
||||
ext = determine_ext(name)
|
||||
if ext in KNOWN_EXTENSIONS:
|
||||
return {
|
||||
**info,
|
||||
entries.append({
|
||||
'id': video_id,
|
||||
'ext': ext,
|
||||
'url': post_file['url'],
|
||||
}
|
||||
})
|
||||
elif name == 'video' or determine_ext(post_file.get('url')) == 'm3u8':
|
||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(post_file['url'], video_id)
|
||||
return {
|
||||
**info,
|
||||
entries.append({
|
||||
'id': video_id,
|
||||
'formats': formats,
|
||||
'subtitles': subtitles,
|
||||
}
|
||||
})
|
||||
|
||||
if can_view_post is False:
|
||||
can_view_post = traverse_obj(attributes, 'current_user_can_view')
|
||||
comments = None
|
||||
if can_view_post and info.get('comment_count'):
|
||||
comments = self.extract_comments(video_id)
|
||||
|
||||
if not entries and can_view_post is False:
|
||||
self.raise_no_formats('You do not have access to this post', video_id=video_id, expected=True)
|
||||
else:
|
||||
elif not entries:
|
||||
self.raise_no_formats('No supported media found in this post', video_id=video_id, expected=True)
|
||||
elif len(entries) == 1:
|
||||
info.update(entries[0])
|
||||
else:
|
||||
for entry in entries:
|
||||
entry.update(info)
|
||||
return self.playlist_result(entries, video_id, **info, __post_extractor=comments)
|
||||
|
||||
info['id'] = video_id
|
||||
info['__post_extractor'] = comments
|
||||
return info
|
||||
|
||||
def _get_comments(self, post_id):
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import hashlib
|
||||
import itertools
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import compat_str
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
int_or_none,
|
||||
float_or_none,
|
||||
int_or_none,
|
||||
traverse_obj,
|
||||
try_get,
|
||||
)
|
||||
|
||||
|
@ -57,6 +59,41 @@ class YandexMusicBaseIE(InfoExtractor):
|
|||
},
|
||||
query=query)
|
||||
|
||||
def _extract_timestamp(self, album):
|
||||
dt = None
|
||||
if release_date := album.get('releaseDate'):
|
||||
dt = datetime.fromisoformat(release_date)
|
||||
elif year := album.get('year'):
|
||||
dt = datetime(year, 1, 1, tzinfo=timezone.utc)
|
||||
if dt:
|
||||
return int(dt.timestamp())
|
||||
|
||||
def _extract_thumbnail(self, data):
|
||||
if cover_uri := data.get('ogImage'):
|
||||
thumbnail = cover_uri.replace('%%', 'orig')
|
||||
if not thumbnail.startswith('http'):
|
||||
thumbnail = 'https://' + thumbnail
|
||||
return thumbnail
|
||||
|
||||
def _extract_artists(self, data):
|
||||
def artist_name(artist):
|
||||
decomposed = artist.get('decomposed')
|
||||
if not isinstance(decomposed, list):
|
||||
return artist['name']
|
||||
parts = [artist['name']]
|
||||
for element in decomposed:
|
||||
if isinstance(element, dict) and element.get('name'):
|
||||
parts.append(element['name'])
|
||||
elif isinstance(element, compat_str):
|
||||
parts.append(element)
|
||||
return ''.join(parts)
|
||||
|
||||
artist_list = data.get('artists')
|
||||
if artist_list and isinstance(artist_list, list):
|
||||
artists_names = [artist_name(a) for a in artist_list if a.get('name')]
|
||||
if artists_names:
|
||||
return ', '.join(artists_names)
|
||||
|
||||
|
||||
class YandexMusicTrackIE(YandexMusicBaseIE):
|
||||
IE_NAME = 'yandexmusic:track'
|
||||
|
@ -76,29 +113,34 @@ class YandexMusicTrackIE(YandexMusicBaseIE):
|
|||
'album': 'md5:cd04fb13c4efeafdfa0a6a6aca36d01a',
|
||||
'album_artist': 'md5:5f54c35462c07952df33d97cfb5fc200',
|
||||
'artist': 'md5:e6fd86621825f14dc0b25db3acd68160',
|
||||
'release_year': 2009,
|
||||
'timestamp': 1241208000,
|
||||
'disc_number': 1,
|
||||
'track_number': 11,
|
||||
'thumbnail': 're:^https://.*$',
|
||||
'upload_date': str
|
||||
},
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}, {
|
||||
# multiple disks
|
||||
'url': 'http://music.yandex.ru/album/3840501/track/705105',
|
||||
'md5': '82a54e9e787301dd45aba093cf6e58c0',
|
||||
'url': 'https://music.yandex.ru/album/19235277/track/94721644',
|
||||
'md5': 'f239d4923c5fdbc2cc8f6c80b4fec721',
|
||||
'info_dict': {
|
||||
'id': '705105',
|
||||
'id': '94721644',
|
||||
'ext': 'mp3',
|
||||
'title': 'md5:f86d4a9188279860a83000277024c1a6',
|
||||
'title': 'Nirvana - Sliver',
|
||||
'filesize': int,
|
||||
'duration': 239.27,
|
||||
'track': 'md5:40f887f0666ba1aa10b835aca44807d1',
|
||||
'album': 'md5:624f5224b14f5c88a8e812fd7fbf1873',
|
||||
'album_artist': 'md5:dd35f2af4e8927100cbe6f5e62e1fb12',
|
||||
'artist': 'md5:dd35f2af4e8927100cbe6f5e62e1fb12',
|
||||
'release_year': 2016,
|
||||
'genre': 'pop',
|
||||
'duration': 133.49,
|
||||
'track': 'Sliver',
|
||||
'album': 'Nevermind',
|
||||
'album_artist': 'Nirvana',
|
||||
'artist': 'Nirvana',
|
||||
'timestamp': 685659600,
|
||||
'disc_number': 2,
|
||||
'track_number': 9,
|
||||
},
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
'upload_date': str,
|
||||
'genre': 'rock'
|
||||
}
|
||||
}, {
|
||||
'url': 'http://music.yandex.com/album/540508/track/4878838',
|
||||
'only_matching': True,
|
||||
|
@ -124,12 +166,8 @@ class YandexMusicTrackIE(YandexMusicBaseIE):
|
|||
key = hashlib.md5(('XGRlBW9FXlekgbPrRHuSiA' + fd_data['path'][1:] + fd_data['s']).encode('utf-8')).hexdigest()
|
||||
f_url = 'http://%s/get-mp3/%s/%s?track-id=%s ' % (fd_data['host'], key, fd_data['ts'] + fd_data['path'], track['id'])
|
||||
|
||||
thumbnail = None
|
||||
cover_uri = track.get('albums', [{}])[0].get('coverUri')
|
||||
if cover_uri:
|
||||
thumbnail = cover_uri.replace('%%', 'orig')
|
||||
if not thumbnail.startswith('http'):
|
||||
thumbnail = 'http://' + thumbnail
|
||||
album = traverse_obj(track, ('albums', 0), expected_type=dict)
|
||||
thumbnail = self._extract_thumbnail(track)
|
||||
|
||||
track_info = {
|
||||
'id': track_id,
|
||||
|
@ -143,43 +181,24 @@ class YandexMusicTrackIE(YandexMusicBaseIE):
|
|||
'abr': int_or_none(download_data.get('bitrate')),
|
||||
}
|
||||
|
||||
def extract_artist_name(artist):
|
||||
decomposed = artist.get('decomposed')
|
||||
if not isinstance(decomposed, list):
|
||||
return artist['name']
|
||||
parts = [artist['name']]
|
||||
for element in decomposed:
|
||||
if isinstance(element, dict) and element.get('name'):
|
||||
parts.append(element['name'])
|
||||
elif isinstance(element, compat_str):
|
||||
parts.append(element)
|
||||
return ''.join(parts)
|
||||
|
||||
def extract_artist(artist_list):
|
||||
if artist_list and isinstance(artist_list, list):
|
||||
artists_names = [extract_artist_name(a) for a in artist_list if a.get('name')]
|
||||
if artists_names:
|
||||
return ', '.join(artists_names)
|
||||
|
||||
albums = track.get('albums')
|
||||
if albums and isinstance(albums, list):
|
||||
album = albums[0]
|
||||
if isinstance(album, dict):
|
||||
year = album.get('year')
|
||||
disc_number = int_or_none(try_get(
|
||||
album, lambda x: x['trackPosition']['volume']))
|
||||
track_number = int_or_none(try_get(
|
||||
album, lambda x: x['trackPosition']['index']))
|
||||
track_info.update({
|
||||
'album': album.get('title'),
|
||||
'album_artist': extract_artist(album.get('artists')),
|
||||
'release_year': int_or_none(year),
|
||||
'album_artist': self._extract_artists(album),
|
||||
'timestamp': self._extract_timestamp(album),
|
||||
'genre': album.get('genre'),
|
||||
'disc_number': disc_number,
|
||||
'track_number': track_number,
|
||||
})
|
||||
|
||||
track_artist = extract_artist(track.get('artists'))
|
||||
track_artist = self._extract_artists(track)
|
||||
if track_artist:
|
||||
track_info.update({
|
||||
'artist': track_artist,
|
||||
|
@ -259,26 +278,23 @@ class YandexMusicAlbumIE(YandexMusicPlaylistBaseIE):
|
|||
'url': 'http://music.yandex.ru/album/540508',
|
||||
'info_dict': {
|
||||
'id': '540508',
|
||||
'title': 'md5:7ed1c3567f28d14be9f61179116f5571',
|
||||
'title': 'Gypsy Soul',
|
||||
'artist': 'Carlo Ambrosio',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
'timestamp': 1241208000,
|
||||
'upload_date': str
|
||||
},
|
||||
'playlist_count': 50,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}, {
|
||||
'url': 'https://music.yandex.ru/album/3840501',
|
||||
'info_dict': {
|
||||
'id': '3840501',
|
||||
'title': 'md5:36733472cdaa7dcb1fd9473f7da8e50f',
|
||||
},
|
||||
'playlist_count': 33,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}, {
|
||||
# empty artists
|
||||
}, { # empty artists
|
||||
'url': 'https://music.yandex.ru/album/9091882',
|
||||
'info_dict': {
|
||||
'id': '9091882',
|
||||
'title': 'ТЕД на русском',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
'artist': None,
|
||||
},
|
||||
'playlist_count': 187,
|
||||
'playlist_count': 166,
|
||||
}]
|
||||
|
||||
@classmethod
|
||||
|
@ -296,15 +312,11 @@ class YandexMusicAlbumIE(YandexMusicPlaylistBaseIE):
|
|||
|
||||
entries = self._build_playlist([track for volume in album['volumes'] for track in volume])
|
||||
|
||||
title = album['title']
|
||||
artist = try_get(album, lambda x: x['artists'][0]['name'], compat_str)
|
||||
if artist:
|
||||
title = '%s - %s' % (artist, title)
|
||||
year = album.get('year')
|
||||
if year:
|
||||
title += ' (%s)' % year
|
||||
|
||||
return self.playlist_result(entries, compat_str(album['id']), title)
|
||||
return self.playlist_result(entries, compat_str(album['id']),
|
||||
album.get('title'),
|
||||
thumbnail=self._extract_thumbnail(album),
|
||||
artist=self._extract_artists(album),
|
||||
timestamp=self._extract_timestamp(album))
|
||||
|
||||
|
||||
class YandexMusicPlaylistIE(YandexMusicPlaylistBaseIE):
|
||||
|
@ -318,6 +330,7 @@ class YandexMusicPlaylistIE(YandexMusicPlaylistBaseIE):
|
|||
'id': '1245',
|
||||
'title': 'md5:841559b3fe2b998eca88d0d2e22a3097',
|
||||
'description': 'md5:3b9f27b0efbe53f2ee1e844d07155cc9',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
},
|
||||
'playlist_count': 5,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
|
@ -331,8 +344,10 @@ class YandexMusicPlaylistIE(YandexMusicPlaylistBaseIE):
|
|||
'info_dict': {
|
||||
'id': '1364',
|
||||
'title': 'md5:b3b400f997d3f878a13ae0699653f7db',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
'description': ''
|
||||
},
|
||||
'playlist_mincount': 437,
|
||||
'playlist_mincount': 300,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}]
|
||||
|
||||
|
@ -357,7 +372,8 @@ class YandexMusicPlaylistIE(YandexMusicPlaylistBaseIE):
|
|||
return self.playlist_result(
|
||||
self._build_playlist(tracks),
|
||||
compat_str(playlist_id),
|
||||
playlist.get('title'), playlist.get('description'))
|
||||
playlist.get('title'), playlist.get('description'),
|
||||
thumbnail=self._extract_thumbnail(playlist))
|
||||
|
||||
|
||||
class YandexMusicArtistBaseIE(YandexMusicPlaylistBaseIE):
|
||||
|
@ -396,9 +412,20 @@ class YandexMusicArtistTracksIE(YandexMusicArtistBaseIE):
|
|||
'info_dict': {
|
||||
'id': '617526',
|
||||
'title': 'md5:131aef29d45fd5a965ca613e708c040b',
|
||||
'artist': 'Ringtone Hits',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
},
|
||||
'playlist_count': 507,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}, {
|
||||
'url': 'https://music.yandex.ru/artist/9262/tracks',
|
||||
'info_dict': {
|
||||
'id': '9262',
|
||||
'title': 'Nirvana - Треки',
|
||||
'artist': 'Nirvana',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
},
|
||||
'playlist_count': 101
|
||||
}]
|
||||
|
||||
_ARTIST_SORT = ''
|
||||
|
@ -410,10 +437,15 @@ class YandexMusicArtistTracksIE(YandexMusicArtistBaseIE):
|
|||
artist_id = mobj.group('id')
|
||||
data = self._call_artist(tld, url, artist_id)
|
||||
tracks = self._extract_tracks(data, artist_id, url, tld)
|
||||
artist = try_get(data, lambda x: x['artist']['name'], compat_str)
|
||||
title = '%s - %s' % (artist or artist_id, 'Треки')
|
||||
thumbnail = None
|
||||
artist_name = None
|
||||
if artist := data.get('artist'):
|
||||
artist_name = artist.get('name')
|
||||
thumbnail = self._extract_thumbnail(artist)
|
||||
title = '%s - %s' % (artist_name or artist_id, 'Треки')
|
||||
return self.playlist_result(
|
||||
self._build_playlist(tracks), artist_id, title)
|
||||
self._build_playlist(tracks), artist_id, title,
|
||||
thumbnail=thumbnail, artist=artist_name)
|
||||
|
||||
|
||||
class YandexMusicArtistAlbumsIE(YandexMusicArtistBaseIE):
|
||||
|
@ -426,9 +458,20 @@ class YandexMusicArtistAlbumsIE(YandexMusicArtistBaseIE):
|
|||
'info_dict': {
|
||||
'id': '617526',
|
||||
'title': 'md5:55dc58d5c85699b7fb41ee926700236c',
|
||||
'artist': 'Ringtone Hits',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
},
|
||||
'playlist_count': 8,
|
||||
# 'skip': 'Travis CI servers blocked by YandexMusic',
|
||||
}, { # artist with thumbnail
|
||||
'url': 'https://music.yandex.ru/artist/9262/albums',
|
||||
'info_dict': {
|
||||
'id': '9262',
|
||||
'title': 'Nirvana - Альбомы',
|
||||
'artist': 'Nirvana',
|
||||
'thumbnail': 're:^https://.*$',
|
||||
},
|
||||
'playlist_count': 15
|
||||
}]
|
||||
|
||||
_ARTIST_SORT = 'year'
|
||||
|
@ -449,6 +492,11 @@ class YandexMusicArtistAlbumsIE(YandexMusicArtistBaseIE):
|
|||
entries.append(self.url_result(
|
||||
'http://music.yandex.ru/album/%s' % album_id,
|
||||
ie=YandexMusicAlbumIE.ie_key(), video_id=album_id))
|
||||
artist = try_get(data, lambda x: x['artist']['name'], compat_str)
|
||||
title = '%s - %s' % (artist or artist_id, 'Альбомы')
|
||||
return self.playlist_result(entries, artist_id, title)
|
||||
thumbnail = None
|
||||
artist_name = None
|
||||
if artist := data.get('artist'):
|
||||
artist_name = artist.get('name')
|
||||
thumbnail = self._extract_thumbnail(artist)
|
||||
title = '%s - %s' % (artist_name or artist_id, 'Альбомы')
|
||||
return self.playlist_result(entries, artist_id, title,
|
||||
thumbnail=thumbnail, artist=artist_name)
|
||||
|
|
|
@ -132,6 +132,16 @@ class CurlCFFIRH(ImpersonateRequestHandler, InstanceStoreMixin):
|
|||
extensions.pop('cookiejar', None)
|
||||
extensions.pop('timeout', None)
|
||||
|
||||
def send(self, request: Request) -> Response:
|
||||
target = self._get_request_target(request)
|
||||
try:
|
||||
response = super().send(request)
|
||||
except HTTPError as e:
|
||||
e.response.extensions['impersonate'] = target
|
||||
raise
|
||||
response.extensions['impersonate'] = target
|
||||
return response
|
||||
|
||||
def _send(self, request: Request):
|
||||
max_redirects_exceeded = False
|
||||
session: curl_cffi.requests.Session = self._get_instance(
|
||||
|
|
|
@ -497,6 +497,7 @@ class Response(io.IOBase):
|
|||
@param headers: response headers.
|
||||
@param status: Response HTTP status code. Default is 200 OK.
|
||||
@param reason: HTTP status reason. Will use built-in reasons based on status code if not provided.
|
||||
@param extensions: Dictionary of handler-specific response extensions.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
@ -505,7 +506,9 @@ class Response(io.IOBase):
|
|||
url: str,
|
||||
headers: Mapping[str, str],
|
||||
status: int = 200,
|
||||
reason: str = None):
|
||||
reason: str = None,
|
||||
extensions: dict = None
|
||||
):
|
||||
|
||||
self.fp = fp
|
||||
self.headers = Message()
|
||||
|
@ -517,6 +520,7 @@ class Response(io.IOBase):
|
|||
self.reason = reason or HTTPStatus(status).phrase
|
||||
except ValueError:
|
||||
self.reason = None
|
||||
self.extensions = extensions or {}
|
||||
|
||||
def readable(self):
|
||||
return self.fp.readable()
|
||||
|
|
Loading…
Reference in New Issue