Skip to content

Commit 2bdab04

Browse files
authored
v2.5.27
1 parent ce27d3b commit 2bdab04

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

Diff for: komga_cover_extractor.py

+21-12
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, 26)
49+
script_version = (2, 5, 27)
5050
script_version_text = "v{}.{}.{}".format(*script_version)
5151

5252
# Paths = existing library
@@ -492,6 +492,10 @@ def __str__(self):
492492

493493
series_cover_path = ""
494494

495+
# The cutoff image count limit for a file to be
496+
# considered a chapter.
497+
average_chapter_image_count = 85
498+
495499

496500
# Folder Class
497501
class Folder:
@@ -1865,9 +1869,6 @@ def contains_chapter_keywords(file_name):
18651869
else file_name_clean
18661870
)
18671871

1868-
# Remove "c1fi7"
1869-
file_name_clean = file_name_clean.replace("c1fi7", "")
1870-
18711872
# Remove dual spaces
18721873
file_name_clean = remove_dual_space(file_name_clean).strip()
18731874

@@ -3277,15 +3278,14 @@ def clean_publisher_name(name):
32773278

32783279

32793280
# Function to determine if an image is black and white with better handling for halftones
3280-
def is_image_black_and_white(image, tolerance=15, threshold=200):
3281+
def is_image_black_and_white(image, tolerance=15):
32813282
"""
32823283
Determines if an image is black and white by verifying that
32833284
most pixels are grayscale (R == G == B) and fall within the black or white range.
32843285
32853286
Args:
32863287
image (PIL.Image): The image to check.
32873288
tolerance (int): The allowed difference between R, G, and B for a pixel to be considered grayscale.
3288-
threshold (int): The number of pixels that need to be grayscale or black/white to count as a valid black-and-white image.
32893289
32903290
Returns:
32913291
bool: True if the image is black and white or grayscale, False otherwise.
@@ -3339,6 +3339,17 @@ def is_first_image_black_and_white(zip_path):
33393339
return False
33403340

33413341

3342+
# Return the number of image files in the .cbz archive.
3343+
def count_images_in_cbz(file_path):
3344+
try:
3345+
with zipfile.ZipFile(file_path, 'r') as archive:
3346+
images = [f for f in archive.namelist() if f.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.webp'))]
3347+
return len(images)
3348+
except zipfile.BadZipFile:
3349+
send_message(f"Skipping corrupted file: {file_path}", error=True)
3350+
return 0
3351+
3352+
33423353
# Trades out our regular files for file objects
33433354
def upgrade_to_volume_class(
33443355
files,
@@ -3458,7 +3469,7 @@ def upgrade_to_volume_class(
34583469
and file_obj.file_type != "chapter"
34593470
and not file_obj.volume_number
34603471
and check_for_exception_keywords(file_obj.name, exception_keywords)
3461-
and is_first_image_black_and_white(file_obj.path)
3472+
and (is_first_image_black_and_white(file_obj.path) or count_images_in_cbz(file.path) <= average_chapter_image_count)
34623473
):
34633474
file_obj.file_type = "chapter"
34643475
file_obj.is_one_shot = True
@@ -11673,15 +11684,13 @@ def move_series_to_correct_library(paths_to_search=paths_with_types):
1167311684

1167411685
if not moved_folder_status:
1167511686
send_message(
11676-
f"\t\t\tFailed to move {root} to {matching_path.path}",
11687+
f"\t\t\tFailed to move {root} to {new_location}",
1167711688
error=True,
1167811689
)
1167911690
check_and_delete_empty_folder(new_location)
1168011691
continue
1168111692

11682-
send_message(
11683-
f"\t\t\tMoved {root} to {matching_path.path}", discord=False
11684-
)
11693+
send_message(f"\t\t\tMoved {root} to {new_location}", discord=False)
1168511694

1168611695
if new_location not in moved_folders:
1168711696
moved_folders.append(new_location)
@@ -11705,7 +11714,7 @@ def move_series_to_correct_library(paths_to_search=paths_with_types):
1170511714
},
1170611715
{
1170711716
"name": "To",
11708-
"value": f"```{matching_path.path}```",
11717+
"value": f"```{new_location}```",
1170911718
"inline": False,
1171011719
},
1171111720
],

0 commit comments

Comments
 (0)