Skip to content

Commit e0a95d5

Browse files
authored
v2.5.16
1 parent f241871 commit e0a95d5

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

Diff for: komga_cover_extractor.py

+44-37
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, 15)
49+
script_version = (2, 5, 16)
5050
script_version_text = "v{}.{}.{}".format(*script_version)
5151

5252
# Paths = existing library
@@ -2180,6 +2180,37 @@ def get_extensionless_name(file):
21802180
return os.path.splitext(file)[0]
21812181

21822182

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+
21832214
# Creates and returns file objects from the passed files and root
21842215
def upgrade_to_file_class(
21852216
files,
@@ -2518,38 +2549,6 @@ def move_images(
25182549
remove_file(cover_image_file_path, silent=True)
25192550

25202551

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-
25532552
# Checks if the file string contains a chapter/volume keyword
25542553
def contains_keyword(file_string, chapter=False):
25552554
return re.search(
@@ -4733,7 +4732,7 @@ def remove_s(s):
47334732

47344733

47354734
# Precompiled
4736-
punctuation_pattern = re.compile(r"[^\w\s]")
4735+
punctuation_pattern = re.compile(r"[^\w\s+]")
47374736

47384737

47394738
# Determines if the string contains punctuation
@@ -4744,7 +4743,7 @@ def contains_punctuation(s):
47444743
# Returns a string without punctuation.
47454744
@lru_cache(maxsize=None)
47464745
def remove_punctuation(s):
4747-
return re.sub(r"[^\w\s]", " ", s).strip()
4746+
return re.sub(r"[^\w\s+]", " ", s).strip()
47484747

47494748

47504749
# Cleans the string by removing punctuation, bracketed info, and replacing underscores with periods.
@@ -5761,7 +5760,7 @@ def get_identifiers(zip_comment):
57615760
identifiers = ((zip_comment.split("Identifiers:")[1]).strip()).split(",")
57625761

57635762
# remove any whitespace
5764-
identifiers = [x.strip() for x in identifiers]
5763+
metadata = [x.strip() for x in identifiers]
57655764
return metadata
57665765

57675766

@@ -5826,6 +5825,14 @@ def move_strings_to_top(target_item, item_array):
58265825
== target_words[:3]
58275826
]
58285827

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+
58295836
# Remove items_to_move from item_array
58305837
item_array = [item for item in item_array if item not in items_to_move]
58315838

@@ -7240,7 +7247,7 @@ def remove_patterns(items, patterns):
72407247
results = remove_patterns(results, patterns)
72417248

72427249
# Remove any possible dupcliates
7243-
results = list(dict.fromkeys(results))
7250+
results = remove_duplicates(results)
72447251

72457252
# Generate file extension modifiers for keywords
72467253
modifiers = {

0 commit comments

Comments
 (0)