diff --git a/cps/audio.py b/cps/audio.py index b17bc7bd..749b2bdc 100644 --- a/cps/audio.py +++ b/cps/audio.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os - import mutagen import base64 from . import cover, logger @@ -51,13 +49,12 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na if not pubdate: pubdate = str(audio_file.tags.get('TDOR').text[0]) if "TDOR" in audio_file.tags else None if cover_data and not no_cover_processing: - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') cover_info = cover_data[0] for dat in cover_data: if dat.type == mutagen.id3.PictureType.COVER_FRONT: cover_info = dat break - cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) + tmp_cover_name = cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) elif original_file_extension in [".ogg", ".flac", ".opus", ".ogv"]: title = audio_file.tags.get('TITLE')[0] if "TITLE" in audio_file else None author = audio_file.tags.get('ARTIST')[0] if "ARTIST" in audio_file else None @@ -70,17 +67,15 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na cover_data = audio_file.tags.get('METADATA_BLOCK_PICTURE') if not no_cover_processing: if cover_data: - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') cover_info = mutagen.flac.Picture(base64.b64decode(cover_data[0])) - cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) + tmp_cover_name = cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) if hasattr(audio_file, "pictures"): cover_info = audio_file.pictures[0] for dat in audio_file.pictures: if dat.type == mutagen.id3.PictureType.COVER_FRONT: cover_info = dat break - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') - cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) + tmp_cover_name = cover.cover_processing(tmp_file_path, cover_info.data, "." + cover_info.mime[-3:]) elif original_file_extension in [".aac"]: title = audio_file.tags.get('Title').value if "Title" in audio_file else None author = audio_file.tags.get('Artist').value if "Artist" in audio_file else None @@ -92,7 +87,7 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na pubdate = audio_file.tags.get('Year').value if "Year" in audio_file else None cover_data = audio_file.tags['Cover Art (Front)'] if cover_data and not no_cover_processing: - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') + tmp_cover_name = tmp_file_path + '.jpg' with open(tmp_cover_name, "wb") as cover_file: cover_file.write(cover_data.value.split(b"\x00",1)[1]) elif original_file_extension in [".asf"]: @@ -106,7 +101,7 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na pubdate = audio_file.tags.get('Year')[0].value if "Year" in audio_file else None cover_data = audio_file.tags.get('WM/Picture', None) if cover_data and not no_cover_processing: - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') + tmp_cover_name = tmp_file_path + '.jpg' with open(tmp_cover_name, "wb") as cover_file: cover_file.write(cover_data[0].value) elif original_file_extension in [".mp4", ".m4a", ".m4b"]: @@ -120,7 +115,6 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na pubdate = audio_file.tags.get('©day')[0] if "©day" in audio_file.tags else None cover_data = audio_file.tags.get('covr', None) if cover_data and not no_cover_processing: - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_path), 'cover.jpg') cover_type = None for c in cover_data: if c.imageformat == mutagen.mp4.AtomDataType.JPEG: @@ -132,7 +126,7 @@ def get_audio_file_info(tmp_file_path, original_file_extension, original_file_na cover_bin = c break if cover_type: - cover.cover_processing(tmp_file_path, cover_bin, cover_type) + tmp_cover_name = cover.cover_processing(tmp_file_path, cover_bin, cover_type) else: logger.error("Unknown covertype in file {} ".format(original_file_name)) diff --git a/cps/comic.py b/cps/comic.py index a4a4f136..271b1b45 100644 --- a/cps/comic.py +++ b/cps/comic.py @@ -90,7 +90,7 @@ def _extract_cover_from_archive(original_file_extension, tmp_file_name, rar_exec if len(ext) > 1: extension = ext[1].lower() if extension in cover.COVER_EXTENSIONS: - cover_data = cf.read([name]) + cover_data = cf.read(name) break except Exception as ex: log.error('Rarfile failed with error: {}'.format(ex)) @@ -109,13 +109,13 @@ def _extract_cover_from_archive(original_file_extension, tmp_file_name, rar_exec return cover_data, extension -def _extract_cover(tmp_file_name, original_file_extension, rar_executable): +def _extract_cover(tmp_file_path, original_file_extension, rar_executable): cover_data = extension = None if use_comic_meta: try: - archive = ComicArchive(tmp_file_name, rar_exe_path=rar_executable) + archive = ComicArchive(tmp_file_path, rar_exe_path=rar_executable) except TypeError: - archive = ComicArchive(tmp_file_name) + archive = ComicArchive(tmp_file_path) 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) @@ -126,8 +126,8 @@ def _extract_cover(tmp_file_name, original_file_extension, rar_executable): cover_data = get_page(index) break else: - cover_data, extension = _extract_cover_from_archive(original_file_extension, tmp_file_name, rar_executable) - return cover.cover_processing(tmp_file_name, cover_data, extension) + cover_data, extension = _extract_cover_from_archive(original_file_extension, tmp_file_path, rar_executable) + return cover.cover_processing(tmp_file_path, cover_data, extension) def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rar_executable, no_cover_processing): diff --git a/cps/cover.py b/cps/cover.py index 5dd29534..89fa4770 100644 --- a/cps/cover.py +++ b/cps/cover.py @@ -29,8 +29,9 @@ NO_JPEG_EXTENSIONS = ['.png', '.webp', '.bmp'] COVER_EXTENSIONS = ['.png', '.webp', '.bmp', '.jpg', '.jpeg'] -def cover_processing(tmp_file_name, img, extension): - tmp_cover_name = os.path.join(os.path.dirname(tmp_file_name), 'cover.jpg') +def cover_processing(tmp_file_path, img, extension): + # tmp_cover_name = os.path.join(os.path.dirname(tmp_file_name), 'cover.jpg') + tmp_cover_name = tmp_file_path + '.jpg' if extension in NO_JPEG_EXTENSIONS: if use_IM: with Image(blob=img) as imgc: diff --git a/cps/uploader.py b/cps/uploader.py index 79016e49..b991049b 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -237,7 +237,7 @@ def pdf_preview(tmp_file_path, tmp_dir): if use_generic_pdf_cover: return None try: - cover_file_name = os.path.join(os.path.dirname(tmp_file_path), "cover.jpg") + cover_file_name = tmp_file_path + ".jpg" with Image() as img: img.options["pdf:use-cropbox"] = "true" img.read(filename=tmp_file_path + '[0]', resolution=150) @@ -245,7 +245,7 @@ def pdf_preview(tmp_file_path, tmp_dir): if img.alpha_channel: img.alpha_channel = 'remove' img.background_color = Color('white') - img.save(filename=os.path.join(tmp_dir, cover_file_name)) + img.save(filename=cover_file_name) return cover_file_name except PolicyError as ex: log.warning('Pdf extraction forbidden by Imagemagick policy: %s', ex) diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index ec9f87ce..039f2e7e 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2024-11-27 21:25:16

+

Start Time: 2024-11-29 20:17:45

-

Stop Time: 2024-11-28 03:32:55

+

Stop Time: 2024-11-30 03:36:53

-

Duration: 5h 7 min

+

Duration: 6h 12 min

@@ -462,11 +462,11 @@ - + TestCli 13 - 11 - 2 + 13 + 0 0 0 @@ -566,31 +566,11 @@ - +
TestCli - test_no_database
- -
- FAIL -
- - - - + PASS @@ -604,42 +584,22 @@ AssertionError: False is not true - +
TestCli - test_writeonly_static_files
- -
- FAIL -
- - - - + PASS - + TestCliGdrivedb 4 - 3 + 4 + 0 0 - 1 0 Detail @@ -675,33 +635,11 @@ AssertionError: False is not true - +
TestCliGdrivedb - test_no_database
- -
- ERROR -
- - - - + PASS @@ -914,1276 +852,79 @@ AttributeError: 'bool' object has no attribute 'click' - + TestEbookConvertCalibreGDrive - 14 + 7 + 7 + 0 0 - 1 - 13 0 - Detail + Detail - +
TestEbookConvertCalibreGDrive - test_convert_email
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_convert_email
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_convert_failed_and_email
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_convert_failed_and_email
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_convert_only
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_convert_only
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_convert_parameter
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_convert_parameter
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_email_failed
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_email_failed
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_email_only
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertCalibreGDrive - test_email_only
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertCalibreGDrive - test_thumbnail_cache
- -
- FAIL -
- - - - - - - - - - -
TestEbookConvertCalibreGDrive - test_thumbnail_cache
- - -
- ERROR -
- - - - + PASS @@ -2240,606 +981,57 @@ urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', p - + TestEbookConvertGDriveKepubify - 6 + 3 + 3 0 0 - 6 0 - Detail + Detail - +
TestEbookConvertGDriveKepubify - test_convert_deactivate
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertGDriveKepubify - test_convert_deactivate
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertGDriveKepubify - test_convert_only
- -
- ERROR -
- - - - + PASS - - -
TestEbookConvertGDriveKepubify - test_convert_only
- - -
- ERROR -
- - - - - - - - - +
TestEbookConvertGDriveKepubify - test_convert_wrong_excecutable
- -
- ERROR -
- - - - - - - - - - -
TestEbookConvertGDriveKepubify - test_convert_wrong_excecutable
- - -
- ERROR -
- - - - + PASS - + TestEditAdditionalBooks - 20 - 15 + 18 + 17 0 - 3 - 2 + 0 + 1 - Detail + Detail @@ -2980,62 +1172,7 @@ urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', p - - -
TestEditAdditionalBooks - test_writeonly_calibre_database
- - -
- SKIP -
- - - - - - - - - - -
TestEditAdditionalBooks - test_writeonly_path
- - -
- ERROR -
- - - - - - - - - +
TestEditAdditionalBooks - test_xss_author_edit
@@ -3044,248 +1181,20 @@ AttributeError: 'bool' object has no attribute 'click' - +
TestEditAdditionalBooks - test_xss_comment_edit
- -
- ERROR -
- - - - + PASS - +
TestEditAdditionalBooks - test_xss_custom_comment_edit
- -
- ERROR -
- - - - - - - - - - - _ErrorHolder - 3 - 0 - 0 - 3 - 0 - - Detail - - - - - - - -
tearDownClass (test_edit_additional_books)
- - -
- ERROR -
- - - - - - - - - - -
tearDownClass (test_edit_books_author_gdrive)
- - -
- ERROR -
- - - - - - - - - - -
tearDownClass (test_readonly_db)
- - -
- ERROR -
- - - - + PASS @@ -3299,13 +1208,13 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 0 1 - Detail + Detail - +
TestEditBooks - test_download_book
@@ -3314,7 +1223,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_author
@@ -3323,7 +1232,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_category
@@ -3332,7 +1241,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_comments
@@ -3341,7 +1250,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_bool
@@ -3350,7 +1259,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_categories
@@ -3359,7 +1268,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_comment
@@ -3368,7 +1277,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_date
@@ -3377,7 +1286,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_float
@@ -3386,7 +1295,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_int
@@ -3395,7 +1304,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_rating
@@ -3404,7 +1313,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_single_select
@@ -3413,7 +1322,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_custom_text
@@ -3422,7 +1331,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_language
@@ -3431,7 +1340,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_publisher
@@ -3440,7 +1349,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_publishing_date
@@ -3449,7 +1358,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_rating
@@ -3458,7 +1367,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_series
@@ -3467,7 +1376,7 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_edit_title
@@ -3476,19 +1385,19 @@ dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16 - +
TestEditBooks - test_rename_upper_lowercase
- SKIP + SKIP
-