Fix filename: omit empty artist suffix, sanitize single quotes
Regular (non-compilation) tracks had an empty artist producing trailing '_-_.flac'. Now artist suffix is only appended when non-empty. Also added single quote to _sanitize_name's removed characters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
12bf67e977
commit
cf836b4528
2 changed files with 17 additions and 5 deletions
|
|
@ -63,7 +63,7 @@ def _sanitize_name(name: str) -> str:
|
|||
Cleaned name (spaces -> underscores)
|
||||
"""
|
||||
name = name.replace(" ", "_")
|
||||
name = re.sub(r'[<>:"/\\|?*]', "", name)
|
||||
name = re.sub(r'[<>:"\'/\\|?*]', "", name)
|
||||
name = name.strip("_")
|
||||
return name
|
||||
|
||||
|
|
@ -323,10 +323,14 @@ def _rename_files(
|
|||
num = int(m.group(1))
|
||||
track = by_num.get(num)
|
||||
if track:
|
||||
safe_title = _sanitize_name(track.title)
|
||||
if track.artist:
|
||||
new_name = (
|
||||
f"{num:02d}_-_{_sanitize_name(track.title)}_-_"
|
||||
f"{num:02d}_-_{safe_title}_-_"
|
||||
f"{_sanitize_name(track.artist)}{audio_format.extension}"
|
||||
)
|
||||
else:
|
||||
new_name = f"{num:02d}_-_{safe_title}{audio_format.extension}"
|
||||
else:
|
||||
new_name = f"{num:02d}{audio_format.extension}"
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class TestSanitizeName:
|
|||
assert _sanitize_name("Test/Track:Name") == "TestTrackName"
|
||||
assert _sanitize_name('Test<Track>"Name') == "TestTrackName"
|
||||
assert _sanitize_name("Test|Track?Name*") == "TestTrackName"
|
||||
assert _sanitize_name("It's_a_Test") == "Its_a_Test"
|
||||
|
||||
def test_keep_umlauts(self) -> None:
|
||||
assert _sanitize_name("Grüße aus Österreich") == "Grüße_aus_Österreich"
|
||||
|
|
@ -282,6 +283,13 @@ class TestRenameFiles:
|
|||
_rename_files(tmp_path, tracks, AudioFormat.FLAC)
|
||||
assert (tmp_path / "01_-_My_Title_-_Art_ist.flac").exists()
|
||||
|
||||
def test_regular_track_without_artist(self, tmp_path: Path) -> None:
|
||||
"""Reguläre Tracks (artist='') → kein '_-_Artist'-Suffix."""
|
||||
(tmp_path / "track01.flac").touch()
|
||||
tracks = [TrackInfo(1, "", "Allegro con brio")]
|
||||
_rename_files(tmp_path, tracks, AudioFormat.FLAC)
|
||||
assert (tmp_path / "01_-_Allegro_con_brio.flac").exists()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# interactive_rip – EAN/Barcode-Integration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue