From d24a24157982292db7f17b55e667dbe8a16d087a Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Wed, 13 Mar 2024 22:41:39 +0300 Subject: [PATCH] Cleanup code. --- app/DownloadQueue.py | 24 +++++++++++++----------- app/Utils.py | 5 +---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/DownloadQueue.py b/app/DownloadQueue.py index 4d89ae29..2799a063 100644 --- a/app/DownloadQueue.py +++ b/app/DownloadQueue.py @@ -11,7 +11,8 @@ from ItemDTO import ItemDTO from DataStore import DataStore from Utils import Notifier, ObjectSerializer, calcDownloadPath, ExtractInfo, isDownloaded, mergeConfig from AsyncPool import AsyncPool -from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor +from concurrent.futures import ThreadPoolExecutor + LOG = logging.getLogger('DownloadQueue') TYPE_DONE: str = 'done' TYPE_QUEUE: str = 'queue' @@ -228,15 +229,16 @@ class DownloadQueue: started = time.perf_counter() LOG.debug(f'extract_info: checking {url=}') - entry = await asyncio.wait_for( - fut=asyncio.get_running_loop().run_in_executor( - None, - ExtractInfo, - mergeConfig(self.config.ytdl_options, ytdlp_config), - url, - bool(self.config.ytdl_debug) - ), - timeout=self.config.extract_info_timeout) + with ThreadPoolExecutor as executor: + entry = await asyncio.wait_for( + fut=asyncio.get_running_loop().run_in_executor( + executor, + ExtractInfo, + mergeConfig(self.config.ytdl_options, ytdlp_config), + url, + bool(self.config.ytdl_debug) + ), + timeout=self.config.extract_info_timeout) if not entry: return {'status': 'error', 'msg': 'Unable to extract info check logs.'} @@ -250,7 +252,7 @@ class DownloadQueue: 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 {'status': 'error', 'msg': f'TimeoutError: {self.config.extract_info_timeout}s reached Unable to extract info.'} return await self.__add_entry( entry=entry, diff --git a/app/Utils.py b/app/Utils.py index 8111807b..2794ec30 100644 --- a/app/Utils.py +++ b/app/Utils.py @@ -137,7 +137,7 @@ def calcDownloadPath(basePath: str, folder: str = None, createPath: bool = True) return download_path -def ExtractInfo(config: dict, url: str, debug: bool = False, forceLookup: bool = False) -> dict: +def ExtractInfo(config: dict, url: str, debug: bool = False) -> dict: params: dict = { 'color': 'no_color', 'extract_flat': True, @@ -158,9 +158,6 @@ def ExtractInfo(config: dict, url: str, debug: bool = False, forceLookup: bool = else: params['quiet'] = True - if forceLookup and 'download_archive' in params: - params.pop('download_archive') - return yt_dlp.YoutubeDL(params=params).extract_info(url, download=False)