From 5717b806b44bb647b2e5e64a5ff860a40cdf527d Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Sat, 20 Jan 2024 11:24:26 +0300 Subject: [PATCH] Added clearer message for failing to add video due to it being in archive --- app/DownloadQueue.py | 22 ++++++++++++++++++++++ app/Utils.py | 21 ++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/DownloadQueue.py b/app/DownloadQueue.py index 475ebc48..15bb2d7e 100644 --- a/app/DownloadQueue.py +++ b/app/DownloadQueue.py @@ -238,7 +238,29 @@ class DownloadQueue: url, bool(self.config.ytdl_debug) ) + if not entry: + if self.config.keep_archive: + entry = await asyncio.get_running_loop().run_in_executor( + None, + ExtractInfo, + mergeConfig(self.config.ytdl_options, ytdlp_config), + url, + bool(self.config.ytdl_debug), + True + ) + + if not entry: + return {'status': 'error', 'msg': 'Unable to extract info check logs.'} + + if self.isDownloaded(entry): + log.info( + f'[{entry.get("id")}: {entry.get("title")}]: has been downloaded already.') + return { + 'status': 'error', + 'msg': f'[{entry.get("id")}: {entry.get("title")}]: has been downloaded already.' + } + return { 'status': 'error', 'msg': 'No metadata, most likely video has been downloaded before.' if self.config.keep_archive else 'Unable to extract info check logs.' diff --git a/app/Utils.py b/app/Utils.py index f5737e2b..85b05e0b 100644 --- a/app/Utils.py +++ b/app/Utils.py @@ -164,7 +164,7 @@ def calcDownloadPath(basePath: str, folder: str = None, createPath: bool = True) return download_path -def ExtractInfo(config: dict, url: str, debug: bool = False) -> dict: +def ExtractInfo(config: dict, url: str, debug: bool = False, forceLookup: bool = False) -> dict: params: dict = { 'color': 'no_color', 'extract_flat': True, @@ -177,7 +177,7 @@ def ExtractInfo(config: dict, url: str, debug: bool = False) -> dict: # Remove keys that are not needed for info extraction as those keys generate files when used with extract_info. for key in ('writeinfojson', 'writethumbnail', 'writedescription', 'writeautomaticsub',): if key in params: - del params[key] + params.pop(key) if debug: params['verbose'] = True @@ -185,6 +185,9 @@ def ExtractInfo(config: dict, url: str, debug: bool = False) -> dict: 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) @@ -230,12 +233,20 @@ def isDownloaded(archive_file: str, info: dict) -> bool: if not info or not archive_file or not os.path.exists(archive_file): return False - id = yt_dlp.YoutubeDL()._make_archive_id(info) - if not id: + try: + id = yt_dlp.YoutubeDL()._make_archive_id(info) + if not id: + return False + except Exception as e: + log.error(f'Error generating archive id: {e}') return False with open(archive_file, 'r') as f: - return id in f.read() + for line in f.readlines(): + if id in line: + return True + + return False def jsonCookie(cookies: dict[dict[str, any]]) -> str | None: