added timeout limit to extract_info

This commit is contained in:
ArabCoders 2024-03-05 14:45:22 +03:00
parent abe5971f8c
commit 9ff44f3234
2 changed files with 10 additions and 2 deletions

View file

@ -44,6 +44,8 @@ class Config:
debug: bool = False
new_version_available: bool = False
extract_info_timeout: int = 70
_int_vars: tuple = ('port', 'max_workers',)
_immutable: tuple = ('version', '__instance', 'ytdl_options', 'new_version_available')

View file

@ -218,7 +218,7 @@ class DownloadQueue:
already.add(url)
try:
LOG.debug(f'extracting info from {url=}')
entry = await asyncio.get_running_loop().run_in_executor(
data = asyncio.get_running_loop().run_in_executor(
None,
ExtractInfo,
mergeConfig(self.config.ytdl_options, ytdlp_config),
@ -226,6 +226,8 @@ class DownloadQueue:
bool(self.config.ytdl_debug)
)
entry = await asyncio.wait_for(data, timeout=self.config.extract_info_timeout)
if not entry:
if not self.config.keep_archive:
return {
@ -234,7 +236,7 @@ class DownloadQueue:
}
LOG.debug(f'No metadata, Rechecking with archive disabled. {url=}')
entry = await asyncio.get_running_loop().run_in_executor(
data = await asyncio.get_running_loop().run_in_executor(
None,
ExtractInfo,
mergeConfig(self.config.ytdl_options, ytdlp_config),
@ -242,6 +244,8 @@ class DownloadQueue:
bool(self.config.ytdl_debug),
True
)
entry = await asyncio.wait_for(data, timeout=self.config.extract_info_timeout)
if not entry:
return {'status': 'error', 'msg': 'Unable to extract info check logs.'}
@ -261,6 +265,8 @@ class DownloadQueue:
return {'status': 'error', 'msg': 'Video has been downloaded already and recorded in archive.log file.'}
except yt_dlp.utils.YoutubeDLError as exc:
return {'status': 'error', 'msg': str(exc)}
except asyncio.exceptions.TimeoutError as exc:
return {'status': 'error', 'msg': 'TimeoutError: Unable to extract info.'}
return await self.__add_entry(
entry=entry,