46
46
import settings as settings_file
47
47
48
48
# Version of the script
49
- script_version = (2 , 5 , 26 )
49
+ script_version = (2 , 5 , 27 )
50
50
script_version_text = "v{}.{}.{}" .format (* script_version )
51
51
52
52
# Paths = existing library
@@ -492,6 +492,10 @@ def __str__(self):
492
492
493
493
series_cover_path = ""
494
494
495
+ # The cutoff image count limit for a file to be
496
+ # considered a chapter.
497
+ average_chapter_image_count = 85
498
+
495
499
496
500
# Folder Class
497
501
class Folder :
@@ -1865,9 +1869,6 @@ def contains_chapter_keywords(file_name):
1865
1869
else file_name_clean
1866
1870
)
1867
1871
1868
- # Remove "c1fi7"
1869
- file_name_clean = file_name_clean .replace ("c1fi7" , "" )
1870
-
1871
1872
# Remove dual spaces
1872
1873
file_name_clean = remove_dual_space (file_name_clean ).strip ()
1873
1874
@@ -3277,15 +3278,14 @@ def clean_publisher_name(name):
3277
3278
3278
3279
3279
3280
# 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 ):
3281
3282
"""
3282
3283
Determines if an image is black and white by verifying that
3283
3284
most pixels are grayscale (R == G == B) and fall within the black or white range.
3284
3285
3285
3286
Args:
3286
3287
image (PIL.Image): The image to check.
3287
3288
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.
3289
3289
3290
3290
Returns:
3291
3291
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):
3339
3339
return False
3340
3340
3341
3341
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
+
3342
3353
# Trades out our regular files for file objects
3343
3354
def upgrade_to_volume_class (
3344
3355
files ,
@@ -3458,7 +3469,7 @@ def upgrade_to_volume_class(
3458
3469
and file_obj .file_type != "chapter"
3459
3470
and not file_obj .volume_number
3460
3471
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 )
3462
3473
):
3463
3474
file_obj .file_type = "chapter"
3464
3475
file_obj .is_one_shot = True
@@ -11673,15 +11684,13 @@ def move_series_to_correct_library(paths_to_search=paths_with_types):
11673
11684
11674
11685
if not moved_folder_status :
11675
11686
send_message (
11676
- f"\t \t \t Failed to move { root } to { matching_path . path } " ,
11687
+ f"\t \t \t Failed to move { root } to { new_location } " ,
11677
11688
error = True ,
11678
11689
)
11679
11690
check_and_delete_empty_folder (new_location )
11680
11691
continue
11681
11692
11682
- send_message (
11683
- f"\t \t \t Moved { root } to { matching_path .path } " , discord = False
11684
- )
11693
+ send_message (f"\t \t \t Moved { root } to { new_location } " , discord = False )
11685
11694
11686
11695
if new_location not in moved_folders :
11687
11696
moved_folders .append (new_location )
@@ -11705,7 +11714,7 @@ def move_series_to_correct_library(paths_to_search=paths_with_types):
11705
11714
},
11706
11715
{
11707
11716
"name" : "To" ,
11708
- "value" : f"```{ matching_path . path } ```" ,
11717
+ "value" : f"```{ new_location } ```" ,
11709
11718
"inline" : False ,
11710
11719
},
11711
11720
],
0 commit comments