From 708e058b01493d392188447f6d05fbed3c3e0bf0 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Mon, 11 Mar 2024 19:39:32 +0300 Subject: [PATCH] Added socket_timeout. --- app/Config.py | 7 ++++++- app/Download.py | 3 +++ app/DownloadQueue.py | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Config.py b/app/Config.py index 0847dc70..7d905d06 100644 --- a/app/Config.py +++ b/app/Config.py @@ -8,6 +8,7 @@ from version import APP_VERSION from dotenv import load_dotenv from yt_dlp.version import __version__ as YTDLP_VERSION + class Config: __instance = None config_path: str = '.' @@ -47,9 +48,11 @@ class Config: extract_info_timeout: int = 70 + socket_timeout: int = 30 + ytdlp_version: str = YTDLP_VERSION - _int_vars: tuple = ('port', 'max_workers',) + _int_vars: tuple = ('port', 'max_workers', 'socket_timeout', 'extract_info_timeout',) _immutable: tuple = ('version', '__instance', 'ytdl_options', 'new_version_available', 'ytdlp_version',) _boolean_vars: tuple = ('keep_archive', 'ytdl_debug', 'debug', 'temp_keep', 'allow_manifestless',) @@ -153,6 +156,8 @@ class Config: else: LOG.info(f'No custom yt-dlp options found in "{self.config_path}"') + self.ytdl_options['socket_timeout'] = self.socket_timeout + if self.keep_archive: LOG.info(f'keep archive: {self.keep_archive}') self.ytdl_options['download_archive'] = os.path.join( diff --git a/app/Download.py b/app/Download.py index cd10785a..1da4a8fd 100644 --- a/app/Download.py +++ b/app/Download.py @@ -261,6 +261,9 @@ class Download: if 'filename' in status: self.info.filename = os.path.relpath(status.get('filename'), self.download_dir) + if os.path.exists(status.get('filename')): + self.info.file_size = os.path.getsize(status.get('filename')) + # Set correct file extension for thumbnails if self.info.format == 'thumbnail': self.info.filename = re.sub(r'\.webm$', '.jpg', self.info.filename) diff --git a/app/DownloadQueue.py b/app/DownloadQueue.py index 46e6619e..4d89ae29 100644 --- a/app/DownloadQueue.py +++ b/app/DownloadQueue.py @@ -242,11 +242,14 @@ class DownloadQueue: return {'status': 'error', 'msg': 'Unable to extract info check logs.'} LOG.debug(f'extract_info: for [{url=}] is done in {time.perf_counter() - started}. Length: {len(entry)}') - except yt_dlp.utils.ExistingVideoReached: + except yt_dlp.utils.ExistingVideoReached as exc: + LOG.error(f'Video has been downloaded already and recorded in archive.log file. {str(exc)}') return {'status': 'error', 'msg': 'Video has been downloaded already and recorded in archive.log file.'} except yt_dlp.utils.YoutubeDLError as exc: + LOG.error(f'YoutubeDLError: Unable to extract info. {str(exc)}') return {'status': 'error', 'msg': str(exc)} except asyncio.exceptions.TimeoutError as exc: + LOG.error(f'TimeoutError: Unable to extract info. {str(exc)}') return {'status': 'error', 'msg': 'TimeoutError: Unable to extract info.'} return await self.__add_entry(