46
46
import settings as settings_file
47
47
48
48
# Version of the script
49
- script_version = (2 , 5 , 15 )
49
+ script_version = (2 , 5 , 16 )
50
50
script_version_text = "v{}.{}.{}" .format (* script_version )
51
51
52
52
# Paths = existing library
@@ -2180,6 +2180,37 @@ def get_extensionless_name(file):
2180
2180
return os .path .splitext (file )[0 ]
2181
2181
2182
2182
2183
+ # Retrives the series name from matching the folder name and the file names
2184
+ def get_series_name_from_contents (
2185
+ folder_name , file_names , required_matching_percent = 100
2186
+ ):
2187
+ if not file_names :
2188
+ return ""
2189
+
2190
+ min_matching_count = (
2191
+ required_matching_percent * len (file_names ) / 100
2192
+ ) # Minimum number of file names to match
2193
+ series_name = ""
2194
+
2195
+ for i , char in enumerate (folder_name ):
2196
+ # Loop through characters of the folder name
2197
+ matching_count = sum (
2198
+ 1
2199
+ for file_name in file_names
2200
+ if i < len (file_name ) and file_name [i ].lower () == char .lower ()
2201
+ )
2202
+ if matching_count >= min_matching_count :
2203
+ series_name += char
2204
+ else :
2205
+ break
2206
+
2207
+ # Check if series_name is at least three characters
2208
+ if len (series_name ) < 3 :
2209
+ series_name = ""
2210
+
2211
+ return series_name .strip ()
2212
+
2213
+
2183
2214
# Creates and returns file objects from the passed files and root
2184
2215
def upgrade_to_file_class (
2185
2216
files ,
@@ -2518,38 +2549,6 @@ def move_images(
2518
2549
remove_file (cover_image_file_path , silent = True )
2519
2550
2520
2551
2521
- # Retrives the series name from matching the folder name and the file names
2522
- def get_series_name_from_contents (
2523
- folder_name , file_names , required_matching_percent = 100
2524
- ):
2525
- # Check if there are fewer than 2 items in the file names array
2526
- if len (file_names ) <= 1 :
2527
- return ""
2528
-
2529
- min_matching_count = (
2530
- required_matching_percent * len (file_names ) / 100
2531
- ) # Minimum number of file names to match
2532
- series_name = ""
2533
-
2534
- for i , char in enumerate (folder_name ):
2535
- # Loop through characters of the folder name
2536
- matching_count = sum (
2537
- 1
2538
- for file_name in file_names
2539
- if i < len (file_name ) and file_name [i ].lower () == char .lower ()
2540
- )
2541
- if matching_count >= min_matching_count :
2542
- series_name += char
2543
- else :
2544
- break
2545
-
2546
- # Check if series_name is at least three characters
2547
- if len (series_name ) < 3 :
2548
- series_name = ""
2549
-
2550
- return series_name .strip ()
2551
-
2552
-
2553
2552
# Checks if the file string contains a chapter/volume keyword
2554
2553
def contains_keyword (file_string , chapter = False ):
2555
2554
return re .search (
@@ -4733,7 +4732,7 @@ def remove_s(s):
4733
4732
4734
4733
4735
4734
# Precompiled
4736
- punctuation_pattern = re .compile (r"[^\w\s]" )
4735
+ punctuation_pattern = re .compile (r"[^\w\s+ ]" )
4737
4736
4738
4737
4739
4738
# Determines if the string contains punctuation
@@ -4744,7 +4743,7 @@ def contains_punctuation(s):
4744
4743
# Returns a string without punctuation.
4745
4744
@lru_cache (maxsize = None )
4746
4745
def remove_punctuation (s ):
4747
- return re .sub (r"[^\w\s]" , " " , s ).strip ()
4746
+ return re .sub (r"[^\w\s+ ]" , " " , s ).strip ()
4748
4747
4749
4748
4750
4749
# Cleans the string by removing punctuation, bracketed info, and replacing underscores with periods.
@@ -5761,7 +5760,7 @@ def get_identifiers(zip_comment):
5761
5760
identifiers = ((zip_comment .split ("Identifiers:" )[1 ]).strip ()).split ("," )
5762
5761
5763
5762
# remove any whitespace
5764
- identifiers = [x .strip () for x in identifiers ]
5763
+ metadata = [x .strip () for x in identifiers ]
5765
5764
return metadata
5766
5765
5767
5766
@@ -5826,6 +5825,14 @@ def move_strings_to_top(target_item, item_array):
5826
5825
== target_words [:3 ]
5827
5826
]
5828
5827
5828
+ # sort items_to_move by the basename matching the target_item
5829
+ items_to_move = sorted (
5830
+ items_to_move ,
5831
+ key = lambda x : os .path .basename (x .lower ().strip ())
5832
+ == target_item .lower ().strip (),
5833
+ reverse = True ,
5834
+ )
5835
+
5829
5836
# Remove items_to_move from item_array
5830
5837
item_array = [item for item in item_array if item not in items_to_move ]
5831
5838
@@ -7240,7 +7247,7 @@ def remove_patterns(items, patterns):
7240
7247
results = remove_patterns (results , patterns )
7241
7248
7242
7249
# Remove any possible dupcliates
7243
- results = list ( dict . fromkeys ( results ) )
7250
+ results = remove_duplicates ( results )
7244
7251
7245
7252
# Generate file extension modifiers for keywords
7246
7253
modifiers = {
0 commit comments