|
46 | 46 | import settings as settings_file
|
47 | 47 |
|
48 | 48 | # Version of the script
|
49 |
| -script_version = (2, 5, 16) |
| 49 | +script_version = (2, 5, 17) |
50 | 50 | script_version_text = "v{}.{}.{}".format(*script_version)
|
51 | 51 |
|
52 | 52 | # Paths = existing library
|
@@ -5815,30 +5815,52 @@ def count_words(strings_list):
|
5815 | 5815 |
|
5816 | 5816 | # Moves strings in item_array that match the first three words of target_item to the top of the array.
|
5817 | 5817 | 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 |
5819 | 5831 |
|
5820 | 5832 | # Find items in item_array that match the first three words of target_item
|
5821 | 5833 | items_to_move = [
|
5822 | 5834 | item
|
5823 | 5835 | 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] |
5825 | 5843 | == target_words[:3]
|
5826 | 5844 | ]
|
5827 | 5845 |
|
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 |
5835 | 5848 |
|
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 | + ) |
5838 | 5857 |
|
5839 | 5858 | # Insert items_to_move at the beginning of item_array
|
5840 | 5859 | item_array = items_to_move + item_array
|
5841 | 5860 |
|
| 5861 | + # Remove duplicates |
| 5862 | + item_array = remove_duplicates(item_array) |
| 5863 | + |
5842 | 5864 | return item_array
|
5843 | 5865 |
|
5844 | 5866 |
|
|
0 commit comments