From 63b7d70f335cc509408ba8098004eebb5ec74879 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 25 Jun 2023 14:39:45 +0200 Subject: [PATCH] Update optional requirements Update to be compatible with comicapi 3.2 --- cps/comic.py | 17 +++++++++++++++-- cps/uploader.py | 8 ++++---- optional-requirements.txt | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cps/comic.py b/cps/comic.py index 907614c9..13774756 100644 --- a/cps/comic.py +++ b/cps/comic.py @@ -36,6 +36,12 @@ try: from comicapi import __version__ as comic_version except ImportError: comic_version = '' + try: + from comicapi.comicarchive import load_archive_plugins + import comicapi.utils + comicapi.utils.add_rar_paths() + except ImportError: + load_archive_plugins = None except (ImportError, LookupError) as e: log.debug('Cannot import comicapi, extracting comic metadata will not work: %s', e) import zipfile @@ -88,7 +94,10 @@ def _extract_cover_from_archive(original_file_extension, tmp_file_name, rar_exec def _extract_cover(tmp_file_name, original_file_extension, rar_executable): cover_data = extension = None if use_comic_meta: - archive = ComicArchive(tmp_file_name, rar_exe_path=rar_executable) + try: + archive = ComicArchive(tmp_file_name, rar_exe_path=rar_executable) + except TypeError: + archive = ComicArchive(tmp_file_name) name_list = archive.getPageNameList if hasattr(archive, "getPageNameList") else archive.get_page_name_list for index, name in enumerate(name_list()): ext = os.path.splitext(name) @@ -105,7 +114,11 @@ def _extract_cover(tmp_file_name, original_file_extension, rar_executable): def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rar_executable): if use_comic_meta: - archive = ComicArchive(tmp_file_path, rar_exe_path=rar_executable) + try: + archive = ComicArchive(tmp_file_path, rar_exe_path=rar_executable) + except TypeError: + load_archive_plugins(force=True, rar=rar_executable) + archive = ComicArchive(tmp_file_path) if hasattr(archive, "seemsToBeAComicArchive"): seems_archive = archive.seemsToBeAComicArchive else: diff --git a/cps/uploader.py b/cps/uploader.py index 3cd7b21a..42b776aa 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -69,7 +69,7 @@ except ImportError as e: use_fb2_meta = False -def process(tmp_file_path, original_file_name, original_file_extension, rarExecutable): +def process(tmp_file_path, original_file_name, original_file_extension, rar_executable): meta = default_meta(tmp_file_path, original_file_name, original_file_extension) extension_upper = original_file_extension.upper() try: @@ -83,7 +83,7 @@ def process(tmp_file_path, original_file_name, original_file_extension, rarExecu meta = comic.get_comic_info(tmp_file_path, original_file_name, original_file_extension, - rarExecutable) + rar_executable) except Exception as ex: log.warning('cannot parse metadata, using default: %s', ex) @@ -248,7 +248,7 @@ def get_magick_version(): return ret -def upload(uploadfile, rarExcecutable): +def upload(uploadfile, rar_excecutable): tmp_dir = os.path.join(gettempdir(), 'calibre_web') if not os.path.isdir(tmp_dir): @@ -260,4 +260,4 @@ def upload(uploadfile, rarExcecutable): tmp_file_path = os.path.join(tmp_dir, md5) log.debug("Temporary file: %s", tmp_file_path) uploadfile.save(tmp_file_path) - return process(tmp_file_path, filename_root, file_extension, rarExcecutable) + return process(tmp_file_path, filename_root, file_extension, rar_excecutable) diff --git a/optional-requirements.txt b/optional-requirements.txt index 5714ac88..ff02d04f 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -38,7 +38,7 @@ faust-cchardet>=2.1.18 # Comics natsort>=2.2.0,<8.4.0 -comicapi>=2.2.0,<2.3.0 +comicapi>=2.2.0,<3.3.0 # Kobo integration jsonschema>=3.2.0,<4.18.0