46
46
import settings as settings_file
47
47
48
48
# Version of the script
49
- script_version = (2 , 5 , 17 )
49
+ script_version = (2 , 5 , 18 )
50
50
script_version_text = "v{}.{}.{}" .format (* script_version )
51
51
52
52
# Paths = existing library
@@ -3063,6 +3063,11 @@ def clean_series_name(name):
3063
3063
)
3064
3064
if len (multi_numbers ) == 1 :
3065
3065
is_multi_volume = False
3066
+ results = (
3067
+ int (results [0 ])
3068
+ if float (results [0 ]).is_integer ()
3069
+ else float (results [0 ])
3070
+ )
3066
3071
else :
3067
3072
# Remove trailing ".0" so conversion doesn't fail
3068
3073
if file .endswith ("0" ) and ".0" in file :
@@ -3113,7 +3118,7 @@ def get_release_year(name, metadata=None):
3113
3118
3114
3119
if release_year_from_file and release_year_from_file .isdigit ():
3115
3120
result = int (release_year_from_file )
3116
- if result < 1000 :
3121
+ if result < 1950 :
3117
3122
result = None
3118
3123
3119
3124
return result
@@ -3132,7 +3137,9 @@ def get_release_year(name, metadata=None):
3132
3137
3133
3138
3134
3139
# Retrieves the release_group on the file name
3135
- def get_extra_from_group (name , groups , publisher_m = False , release_group_m = False ):
3140
+ def get_extra_from_group (
3141
+ name , groups , publisher_m = False , release_group_m = False , series_name = None
3142
+ ):
3136
3143
if (
3137
3144
not groups
3138
3145
or (publisher_m and not publishers_joined )
@@ -3148,7 +3155,18 @@ def get_extra_from_group(name, groups, publisher_m=False, release_group_m=False)
3148
3155
search = search .group ()
3149
3156
3150
3157
elif release_group_m :
3151
- search = release_group_end_regex .search (name ) if "-" in name else ""
3158
+ # remove series name from the file name, re.escape it
3159
+ series_free_name = ""
3160
+ if series_name :
3161
+ series_free_name = re .sub (
3162
+ re .escape (series_name ), "" , name , flags = re .IGNORECASE
3163
+ ).strip ()
3164
+
3165
+ search = (
3166
+ release_group_end_regex .search (series_free_name or name )
3167
+ if "-" in name
3168
+ else ""
3169
+ )
3152
3170
3153
3171
if search :
3154
3172
search = search .group (1 )
@@ -3294,7 +3312,12 @@ def upgrade_to_volume_class(
3294
3312
"" ,
3295
3313
"" ,
3296
3314
(
3297
- get_extra_from_group (file .name , release_groups , release_group_m = True )
3315
+ get_extra_from_group (
3316
+ file .name ,
3317
+ release_groups ,
3318
+ release_group_m = True ,
3319
+ series_name = file .basename ,
3320
+ )
3298
3321
if not skip_release_group
3299
3322
else ""
3300
3323
),
@@ -10823,6 +10846,47 @@ def __init__(self, ssim_score, image_source):
10823
10846
self .image_source = image_source
10824
10847
10825
10848
10849
+ # Preps the image for comparison
10850
+ def preprocess_image (image ):
10851
+ # Check if the image is already grayscale
10852
+ if len (image .shape ) == 2 or (len (image .shape ) == 3 and image .shape [2 ] == 1 ):
10853
+ gray_image = image
10854
+ else :
10855
+ # Convert to grayscale if it's a color image
10856
+ gray_image = cv2 .cvtColor (image , cv2 .COLOR_BGR2GRAY )
10857
+
10858
+ # Apply histogram equalization
10859
+ gray_image = cv2 .equalizeHist (gray_image )
10860
+
10861
+ # Normalize the image
10862
+ gray_image = gray_image / 255.0
10863
+
10864
+ return gray_image
10865
+
10866
+
10867
+ # Comapres two images using SSIM
10868
+ def compare_images (imageA , imageB , silent = False ):
10869
+ try :
10870
+ if not silent :
10871
+ print (f"\t \t \t Blank Image Size: { imageA .shape } " )
10872
+ print (f"\t \t \t Internal Cover Size: { imageB .shape } " )
10873
+
10874
+ # Preprocess images
10875
+ grayA = preprocess_image (imageA )
10876
+ grayB = preprocess_image (imageB )
10877
+
10878
+ # Compute SSIM between the two images
10879
+ ssim_score = ssim (grayA , grayB , data_range = 1.0 )
10880
+
10881
+ if not silent :
10882
+ print (f"\t \t \t \t SSIM: { ssim_score } " )
10883
+
10884
+ return ssim_score
10885
+ except Exception as e :
10886
+ send_message (str (e ), error = True )
10887
+ return 0
10888
+
10889
+
10826
10890
# Compares two images and returns the ssim score of the two images similarity.
10827
10891
def prep_images_for_similarity (
10828
10892
blank_image_path , internal_cover_data , both_cover_data = False , silent = False
@@ -10871,33 +10935,19 @@ def prep_images_for_similarity(
10871
10935
elif len (blank_image .shape ) == 2 and len (internal_cover .shape ) == 3 :
10872
10936
internal_cover = internal_cover [:, :, 0 ]
10873
10937
10938
+ # Ensure both images are in the same format (grayscale or color)
10939
+ if len (blank_image .shape ) != len (internal_cover .shape ):
10940
+ if len (blank_image .shape ) == 3 :
10941
+ blank_image = cv2 .cvtColor (blank_image , cv2 .COLOR_BGR2GRAY )
10942
+ else :
10943
+ internal_cover = cv2 .cvtColor (internal_cover , cv2 .COLOR_BGR2GRAY )
10944
+
10874
10945
# Compare images and return similarity score
10875
10946
score = compare_images (blank_image , internal_cover , silent = silent )
10876
10947
10877
10948
return score
10878
10949
10879
10950
10880
- # compares our two images likness and returns the ssim score
10881
- def compare_images (imageA , imageB , silent = False ):
10882
- ssim_score = None
10883
- try :
10884
- if not silent :
10885
- print (f"\t \t \t Blank Image Size: { imageA .shape } " )
10886
- print (f"\t \t \t Internal Cover Size: { imageB .shape } " )
10887
-
10888
- if len (imageA .shape ) == 3 and len (imageB .shape ) == 3 :
10889
- grayA = cv2 .cvtColor (imageA , cv2 .COLOR_BGR2GRAY )
10890
- grayB = cv2 .cvtColor (imageB , cv2 .COLOR_BGR2GRAY )
10891
- ssim_score = ssim (grayA , grayB )
10892
- else :
10893
- ssim_score = ssim (imageA , imageB )
10894
- if not silent :
10895
- print (f"\t \t \t \t SSIM: { ssim_score } " )
10896
- except Exception as e :
10897
- send_message (str (e ), error = True )
10898
- return ssim_score
10899
-
10900
-
10901
10951
# Extracts a supported archive to a temporary directory.
10902
10952
def extract (file_path , temp_dir , extension ):
10903
10953
successfull = False
0 commit comments