0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-29 03:23:02 +00:00

[ie/soundcloud] Support retries for API rate-limit (#9585)

Authored by: bashonly
This commit is contained in:
bashonly 2024-04-01 11:21:46 -05:00 committed by GitHub
parent 32abfb00bd
commit 246571ae1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,12 +19,12 @@
mimetype2ext, mimetype2ext,
parse_qs, parse_qs,
str_or_none, str_or_none,
try_get,
unified_timestamp, unified_timestamp,
update_url_query, update_url_query,
url_or_none, url_or_none,
urlhandle_detect_ext, urlhandle_detect_ext,
) )
from ..utils.traversal import traverse_obj
class SoundcloudEmbedIE(InfoExtractor): class SoundcloudEmbedIE(InfoExtractor):
@ -261,16 +261,25 @@ def add_format(f, protocol, is_preview=False):
formats.append(f) formats.append(f)
# New API # New API
transcodings = try_get( for t in traverse_obj(info, ('media', 'transcodings', lambda _, v: url_or_none(v['url']))):
info, lambda x: x['media']['transcodings'], list) or [] if extract_flat:
for t in transcodings: break
if not isinstance(t, dict): format_url = t['url']
continue stream = None
format_url = url_or_none(t.get('url'))
if not format_url: for retry in self.RetryManager(fatal=False):
continue try:
stream = None if extract_flat else self._download_json( stream = self._download_json(format_url, track_id, query=query, headers=self._HEADERS)
format_url, track_id, query=query, fatal=False, headers=self._HEADERS) except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 429:
self.report_warning(
'You have reached the API rate limit, which is ~600 requests per '
'10 minutes. Use the --extractor-retries and --retry-sleep options '
'to configure an appropriate retry count and wait time', only_once=True)
retry.error = e.cause
else:
self.report_warning(e.msg)
if not isinstance(stream, dict): if not isinstance(stream, dict):
continue continue
stream_url = url_or_none(stream.get('url')) stream_url = url_or_none(stream.get('url'))