Skip to content

Commit 21c2878

Browse files
authored
v2.5.30
1 parent c9d4414 commit 21c2878

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Diff for: komga_cover_extractor.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import settings as settings_file
4747

4848
# Version of the script
49-
script_version = (2, 5, 29)
49+
script_version = (2, 5, 30)
5050
script_version_text = "v{}.{}.{}".format(*script_version)
5151

5252
# Paths = existing library
@@ -163,6 +163,7 @@
163163
".epub",
164164
]
165165

166+
# Rar extensions
166167
rar_extensions = [".rar", ".cbr"]
167168

168169
# Accepted file extensions for novels
@@ -323,7 +324,7 @@ def __str__(self):
323324
r"Tail -",
324325
r"꞉",
325326
r":",
326-
r"\d\."
327+
r"\d\.",
327328
]
328329

329330
subtitle_exclusion_keywords = [r"-(\s)", r"-", r"-\s[A-Za-z]+\s"]
@@ -349,13 +350,13 @@ def __str__(self):
349350

350351
### EXTENION REGEX ###
351352
# File extensions regex to be used throughout the script
352-
file_extensions_regex = "|".join(file_extensions).replace(".", "\.")
353+
file_extensions_regex = "|".join(file_extensions).replace(".", r"\.")
353354
# Manga extensions regex to be used throughout the script
354-
manga_extensions_regex = "|".join(manga_extensions).replace(".", "\.")
355+
manga_extensions_regex = "|".join(manga_extensions).replace(".", r"\.")
355356
# Novel extensions regex to be used throughout the script
356-
novel_extensions_regex = "|".join(novel_extensions).replace(".", "\.")
357+
novel_extensions_regex = "|".join(novel_extensions).replace(".", r"\.")
357358
# Image extensions regex to be used throughout the script
358-
image_extensions_regex = "|".join(image_extensions).replace(".", "\.")
359+
image_extensions_regex = "|".join(image_extensions).replace(".", r"\.")
359360

360361
# REMINDER: ORDER IS IMPORTANT, Top to bottom is the order it will be checked in.
361362
# Once a match is found, it will stop checking the rest.
@@ -2595,7 +2596,7 @@ def get_series_name_from_volume(name, root, test_mode=False, second=False):
25952596
if is_one_shot(name, root, test_mode=test_mode):
25962597
name = re.sub(
25972598
r"([-_ ]+|)(((\[|\(|\{).*(\]|\)|\}))|LN)([-_. ]+|)(%s|).*"
2598-
% file_extensions_regex.replace("\.", ""),
2599+
% file_extensions_regex.replace(r"\.", ""),
25992600
"",
26002601
name,
26012602
flags=re.IGNORECASE,
@@ -3345,8 +3346,12 @@ def is_first_image_black_and_white(zip_path):
33453346
# Return the number of image files in the .cbz archive.
33463347
def count_images_in_cbz(file_path):
33473348
try:
3348-
with zipfile.ZipFile(file_path, 'r') as archive:
3349-
images = [f for f in archive.namelist() if f.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.webp'))]
3349+
with zipfile.ZipFile(file_path, "r") as archive:
3350+
images = [
3351+
f
3352+
for f in archive.namelist()
3353+
if f.lower().endswith(tuple(image_extensions))
3354+
]
33503355
return len(images)
33513356
except zipfile.BadZipFile:
33523357
send_message(f"Skipping corrupted file: {file_path}", error=True)
@@ -3471,13 +3476,18 @@ def upgrade_to_volume_class(
34713476
and file_obj.extension in manga_extensions
34723477
and file_obj.file_type != "chapter"
34733478
and (not file_obj.volume_number or file_obj.is_one_shot)
3474-
and (check_for_exception_keywords(file_obj.name, exception_keywords) or file_obj.is_one_shot)
3479+
and (
3480+
check_for_exception_keywords(file_obj.name, exception_keywords)
3481+
or file_obj.is_one_shot
3482+
)
34753483
):
3476-
if is_first_image_black_and_white(file_obj.path) or count_images_in_cbz(file_obj.path) <= average_chapter_image_count:
3484+
if (
3485+
is_first_image_black_and_white(file_obj.path)
3486+
or count_images_in_cbz(file_obj.path) <= average_chapter_image_count
3487+
):
34773488
file_obj.file_type = "chapter"
34783489
file_obj.is_one_shot = True
34793490

3480-
34813491
if file_obj.is_one_shot:
34823492
file_obj.volume_number = 1
34833493

@@ -4880,19 +4890,19 @@ def normalize_str(
48804890
"kara",
48814891
"to",
48824892
"ya",
4883-
"no(?!\.)",
4893+
r"no(?!\.)",
48844894
"ne",
48854895
"yo",
48864896
]
48874897
words_to_remove.extend(japanese_particles)
48884898

48894899
if not skip_misc_words:
4890-
misc_words = ["((\d+)([-_. ]+)?th)", "x", "×", "HD"]
4900+
misc_words = [r"((\d+)([-_. ]+)?th)", "x", "×", "HD"]
48914901
words_to_remove.extend(misc_words)
48924902

48934903
if not skip_storefront_keywords:
48944904
storefront_keywords = [
4895-
"Book(\s+)?walker",
4905+
r"Book(\s+)?walker",
48964906
]
48974907
words_to_remove.extend(storefront_keywords)
48984908

@@ -11754,11 +11764,11 @@ def move_series_to_correct_library(paths_to_search=paths_with_types):
1175411764
# Normalize path separators and remove Windows drive letters if present.
1175511765
def normalize_path(path):
1175611766
path = os.path.normpath(path)
11757-
11767+
1175811768
# Remove Windows drive letters (e.g., "Z:\example\path" -> "\example\path")
1175911769
if ":" in path:
1176011770
path = re.sub(r"^[A-Za-z]:", "", path)
11761-
11771+
1176211772
# Convert backslashes to forward slashes for uniform comparison
1176311773
return path.replace("\\", "/")
1176411774

@@ -11767,7 +11777,7 @@ def normalize_path(path):
1176711777
def is_root_present(root_path, target_path):
1176811778
root_path = normalize_path(root_path)
1176911779
target_path = normalize_path(target_path)
11770-
11780+
1177111781
return root_path in target_path
1177211782

1177311783

0 commit comments

Comments
 (0)