Retry until error or downloaded

This commit is contained in:
Antonio J. Delgado 2025-08-10 11:52:14 +03:00
parent 50a252d3b7
commit 72f7072d1d

View file

@ -378,92 +378,54 @@ class GetYoutubeVideos:
if self.selected_proxy != '':
ydl_opts['proxy'] = self.selected_proxy
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
except yt_dlp.utils.DownloadError as error:
if 'Requested format is not available' in f"{error}":
self._log.warning(
"Requested format is not available, trying best format."
result = 'pending'
while result != 'downloaded' and result != 'error':
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best'
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
except yt_dlp.utils.DownloadError as sub_error:
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
sub_error
)
self.summary['videos_with_error'] += 1
break
elif 'Unable to download video subtitles for' in f"{error}":
subtitle_match = re.match(
r"Unable to download video subtitles for '([a-z]*)' ",
f"{error}"
result = 'downloaded'
self.summary['downloaded_videos_titles'].append(
video_info.get('title', '?')
)
if not subtitle_match:
self._log.error(
f"Error finding subtitle that failed in error string"
self.summary['downloaded_videos'] += 1
except yt_dlp.utils.DownloadError as error:
if 'Requested format is not available' in f"{error}":
self._log.warning(
"Requested format is not available, trying best format."
)
ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best'
result = 'retrying (format error)'
elif 'Unable to download video subtitles for' in f"{error}":
subtitle_match = re.match(
r"Unable to download video subtitles for '([a-z]*)' ",
f"{error}"
)
if not subtitle_match:
self._log.error(
f"Error finding subtitle that failed in error string"
)
else:
ydl_opts['subtitleslangs'].pop(subtitle_match.group(1))
result = 'retrying (subtitles error)'
else:
ydl_opts['subtitleslangs'].pop(subtitle_match.group(1))
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
except yt_dlp.utils.DownloadError as sub_error:
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
sub_error
)
self.summary['videos_with_error'] += 1
break
else:
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
error
)
self.summary['videos_with_error'] += 1
break
self.summary['downloaded_videos_titles'].append(
video_info.get('title', '?')
)
self.summary['downloaded_videos'] += 1
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
error
)
self.summary['videos_with_error'] += 1
result = error
continue
else:
self._log.debug(
"Video with ID '%s' has been already downloaded",