1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-14 04:05:16 +00:00

chore: replace hard-coded limit with command line option

This commit is contained in:
Adam Miller
2025-01-22 16:17:40 -08:00
parent 050b6c1f29
commit 148b36a039
3 changed files with 17 additions and 10 deletions

View File

@@ -1822,17 +1822,17 @@ class YoutubeDL:
result_type = ie_result.get('_type', 'video')
if result_type in ('url', 'url_transparent'):
if 'extraction_depth' in extra_info:
extra_info['extraction_depth'] = 1 + extra_info.get('extraction_depth', 0)
else:
extra_info['extraction_depth'] = 0
if self.params.get('max_extraction_depth', -1) > 0:
if 'extraction_depth' in extra_info:
extra_info['extraction_depth'] = 1 + extra_info.get('extraction_depth', 0)
else:
extra_info['extraction_depth'] = 0
# TODO: make command line arg with large or infinite default
if extra_info['extraction_depth'] >= 20:
raise ExtractorError(
f"Too many hops for URL: {ie_result['url']}",
expected=True,
)
if extra_info['extraction_depth'] >= self.params.get('max_extraction_depth'):
raise ExtractorError(
f"Reached maximum extraction depth for URL: {ie_result['url']}",
expected=True,
)
ie_result['url'] = sanitize_url(
ie_result['url'], scheme='http' if self.params.get('prefer_insecure') else 'https')