Skip to content

Commit 38ed3fc

Browse files
authored
v2.5.17
1 parent e0a95d5 commit 38ed3fc

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

Diff for: komga_cover_extractor.py

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

5252
# Paths = existing library
@@ -5815,30 +5815,52 @@ def count_words(strings_list):
58155815

58165816
# Moves strings in item_array that match the first three words of target_item to the top of the array.
58175817
def move_strings_to_top(target_item, item_array):
5818-
target_words = parse_words(unidecode(target_item.lower().strip()))
5818+
# Convert to lower and strip
5819+
target_words = target_item.lower().strip()
5820+
5821+
# Unidecode if applicable
5822+
target_words = (
5823+
unidecode(target_words) if contains_unicode(target_words) else target_words
5824+
)
5825+
5826+
# Parse into words
5827+
target_words = parse_words(target_words)
5828+
5829+
if not target_words:
5830+
return item_array
58195831

58205832
# Find items in item_array that match the first three words of target_item
58215833
items_to_move = [
58225834
item
58235835
for item in item_array
5824-
if parse_words(os.path.basename(unidecode(item.lower().strip())))[:3]
5836+
if parse_words(
5837+
os.path.basename(
5838+
unidecode(item).lower().strip()
5839+
if contains_unicode(item)
5840+
else item.lower().strip()
5841+
)
5842+
)[:3]
58255843
== target_words[:3]
58265844
]
58275845

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-
)
5846+
if not items_to_move:
5847+
return item_array
58355848

5836-
# Remove items_to_move from item_array
5837-
item_array = [item for item in item_array if item not in items_to_move]
5849+
clean_target_item = clean_str(target_item)
5850+
5851+
# Sort items_to_move by the basename matching the target_item
5852+
if len(items_to_move) >= 2:
5853+
items_to_move = sorted(
5854+
items_to_move,
5855+
key=lambda x: clean_str(os.path.basename(x)) != clean_target_item,
5856+
)
58385857

58395858
# Insert items_to_move at the beginning of item_array
58405859
item_array = items_to_move + item_array
58415860

5861+
# Remove duplicates
5862+
item_array = remove_duplicates(item_array)
5863+
58425864
return item_array
58435865

58445866

0 commit comments

Comments
 (0)