Handle NTFS's case insensitivity
This commit is contained in:
parent
12fdb5045c
commit
4c00b01c78
@ -2,6 +2,8 @@ import re
|
|||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
from karaokatalog.instructions.MoveInstruction import MoveInstruction
|
from karaokatalog.instructions.MoveInstruction import MoveInstruction
|
||||||
from karaokatalog.Song import Song
|
from karaokatalog.Song import Song
|
||||||
|
|
||||||
@ -26,30 +28,33 @@ def move(songs: Sequence[Song], base_dir: Path) -> Sequence[MoveInstruction]:
|
|||||||
Create move instructions to move every song into the proper song directory
|
Create move instructions to move every song into the proper song directory
|
||||||
within the given base_dir.
|
within the given base_dir.
|
||||||
"""
|
"""
|
||||||
song_dirs = set(song.dir.relative_to(base_dir) for song in songs)
|
song_dir_strs_lower = set(
|
||||||
|
str(song.dir.relative_to(base_dir)).lower() for song in songs
|
||||||
|
)
|
||||||
move_instructions = []
|
move_instructions = []
|
||||||
|
|
||||||
for song in songs:
|
for song in tqdm(songs, unit=" songs"):
|
||||||
absolute_song_dir = song.dir
|
absolute_song_dir = song.dir
|
||||||
song_dir = absolute_song_dir.relative_to(base_dir)
|
song_dir = absolute_song_dir.relative_to(base_dir)
|
||||||
|
song_dir_str_lower = str(song_dir).lower()
|
||||||
canonical_song_dir = _get_canonical_song_dir(song)
|
canonical_song_dir = _get_canonical_song_dir(song)
|
||||||
|
|
||||||
if song_dir not in song_dirs:
|
if song_dir_str_lower not in song_dir_strs_lower:
|
||||||
# A move instruction has already been generated for the dir this song is in
|
# A move instruction has already been generated for the dir this song is in
|
||||||
# (which is possible, because some dirs contain multiple (variants of) songs)
|
# (which is possible, because some dirs contain multiple (variants of) songs)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if song_dir != canonical_song_dir:
|
if song_dir != canonical_song_dir:
|
||||||
# song_dir is not a good name, we want to replace it, so this path will soon be free
|
# song_dir is not a good name, we want to replace it, so this path will soon be free
|
||||||
song_dirs.remove(song_dir)
|
song_dir_strs_lower.remove(song_dir_str_lower)
|
||||||
|
|
||||||
# Find a canonical song dir variant that does not yet exist
|
# Find a canonical song dir variant that does not yet exist
|
||||||
variant = 1
|
variant = 1
|
||||||
while canonical_song_dir in song_dirs:
|
while str(canonical_song_dir).lower() in song_dir_strs_lower:
|
||||||
canonical_song_dir = _get_canonical_song_dir(song, variant)
|
canonical_song_dir = _get_canonical_song_dir(song, variant)
|
||||||
variant += 1
|
variant += 1
|
||||||
|
|
||||||
song_dirs.add(canonical_song_dir)
|
song_dir_strs_lower.add(str(canonical_song_dir).lower())
|
||||||
move_instructions.append(
|
move_instructions.append(
|
||||||
MoveInstruction(absolute_song_dir, base_dir / canonical_song_dir)
|
MoveInstruction(absolute_song_dir, base_dir / canonical_song_dir)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user