Cleanup code.

This commit is contained in:
ArabCoders 2024-03-13 22:41:39 +03:00
parent 8042f5ac45
commit d24a241579
2 changed files with 14 additions and 15 deletions

View file

@ -11,7 +11,8 @@ from ItemDTO import ItemDTO
from DataStore import DataStore from DataStore import DataStore
from Utils import Notifier, ObjectSerializer, calcDownloadPath, ExtractInfo, isDownloaded, mergeConfig from Utils import Notifier, ObjectSerializer, calcDownloadPath, ExtractInfo, isDownloaded, mergeConfig
from AsyncPool import AsyncPool from AsyncPool import AsyncPool
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor from concurrent.futures import ThreadPoolExecutor
LOG = logging.getLogger('DownloadQueue') LOG = logging.getLogger('DownloadQueue')
TYPE_DONE: str = 'done' TYPE_DONE: str = 'done'
TYPE_QUEUE: str = 'queue' TYPE_QUEUE: str = 'queue'
@ -228,15 +229,16 @@ class DownloadQueue:
started = time.perf_counter() started = time.perf_counter()
LOG.debug(f'extract_info: checking {url=}') LOG.debug(f'extract_info: checking {url=}')
entry = await asyncio.wait_for( with ThreadPoolExecutor as executor:
fut=asyncio.get_running_loop().run_in_executor( entry = await asyncio.wait_for(
None, fut=asyncio.get_running_loop().run_in_executor(
ExtractInfo, executor,
mergeConfig(self.config.ytdl_options, ytdlp_config), ExtractInfo,
url, mergeConfig(self.config.ytdl_options, ytdlp_config),
bool(self.config.ytdl_debug) url,
), bool(self.config.ytdl_debug)
timeout=self.config.extract_info_timeout) ),
timeout=self.config.extract_info_timeout)
if not entry: if not entry:
return {'status': 'error', 'msg': 'Unable to extract info check logs.'} return {'status': 'error', 'msg': 'Unable to extract info check logs.'}
@ -250,7 +252,7 @@ class DownloadQueue:
return {'status': 'error', 'msg': str(exc)} return {'status': 'error', 'msg': str(exc)}
except asyncio.exceptions.TimeoutError as exc: except asyncio.exceptions.TimeoutError as exc:
LOG.error(f'TimeoutError: Unable to extract info. {str(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( return await self.__add_entry(
entry=entry, entry=entry,

View file

@ -137,7 +137,7 @@ def calcDownloadPath(basePath: str, folder: str = None, createPath: bool = True)
return download_path 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 = { params: dict = {
'color': 'no_color', 'color': 'no_color',
'extract_flat': True, 'extract_flat': True,
@ -158,9 +158,6 @@ def ExtractInfo(config: dict, url: str, debug: bool = False, forceLookup: bool =
else: else:
params['quiet'] = True 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) return yt_dlp.YoutubeDL(params=params).extract_info(url, download=False)