feat: auto-rename album directory after in-place apply
After all file operations (rename, tag, cover, playlist), apply now renames the album root directory to match album.json metadata: - input_dir = CD1/CD2 etc.: parent directory is renamed automatically e.g. Kärntner_Doppelsextett/ → Du_Berührst_Mi_20_Jahre_Kärntner_Doppelsextett/ - input_dir = album root: a hint with the mv command is printed instead (avoids renaming an actively used path) - Existing directory with target name: warning, no rename Also: _sanitize_filename() in organizer.py made public (sanitize_filename), used consistently across organizer, playlist and cli modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c0e4d2aa85
commit
7554cade50
5 changed files with 148 additions and 20 deletions
|
|
@ -210,3 +210,80 @@ class TestScanCommand:
|
|||
def test_scan_no_args_fails(self) -> None:
|
||||
result = runner.invoke(app, ["scan"])
|
||||
assert result.exit_code == 1
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _rename_album_dir_inplace (via apply --in-place)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestRenameAlbumDir:
|
||||
"""Tests für automatisches Umbenennen des Album-Verzeichnisses."""
|
||||
|
||||
def test_cd_subdir_renames_parent(self, tmp_path: Path) -> None:
|
||||
"""input_dir = CD1 → Elternverzeichnis wird umbenannt."""
|
||||
album_root = tmp_path / "Falscher_Name"
|
||||
cd1 = album_root / "CD1"
|
||||
cd1.mkdir(parents=True)
|
||||
|
||||
_make_album_json(album_root / "album.json", n_tracks=1)
|
||||
_make_flac(cd1 / "track01.flac")
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"apply", str(cd1), str(album_root / "album.json"), "--in-place",
|
||||
])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
expected = tmp_path / "TestAlbum_2024"
|
||||
assert expected.exists(), f"Verzeichnis nicht umbenannt; output: {result.output}"
|
||||
assert not album_root.exists()
|
||||
|
||||
def test_album_root_as_input_prints_hint(self, tmp_path: Path) -> None:
|
||||
"""input_dir = AlbumRoot → kein auto-rename, stattdessen Hinweis."""
|
||||
album = _make_album_json(tmp_path / "album.json", n_tracks=2)
|
||||
_make_disc_files(tmp_path, album)
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"apply", str(tmp_path), str(tmp_path / "album.json"), "--in-place",
|
||||
])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
# Verzeichnis nicht umbenannt
|
||||
assert tmp_path.exists()
|
||||
# Aber Hinweis ausgegeben
|
||||
assert "Tipp" in result.output or "mv" in result.output
|
||||
|
||||
def test_already_correct_name_no_rename(self, tmp_path: Path) -> None:
|
||||
"""CD1 als input_dir, Elternverzeichnis heißt bereits korrekt → keine Ausgabe."""
|
||||
album_root = tmp_path / "TestAlbum_2024"
|
||||
cd1 = album_root / "CD1"
|
||||
cd1.mkdir(parents=True)
|
||||
|
||||
_make_album_json(album_root / "album.json", n_tracks=1)
|
||||
_make_flac(cd1 / "track01.flac")
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"apply", str(cd1), str(album_root / "album.json"), "--in-place",
|
||||
])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert album_root.exists()
|
||||
assert "umbenannt" not in result.output
|
||||
|
||||
def test_target_exists_prints_warning(self, tmp_path: Path) -> None:
|
||||
"""Zielverzeichnis existiert bereits → Warnung, kein Umbenennen."""
|
||||
album_root = tmp_path / "Falscher_Name"
|
||||
cd1 = album_root / "CD1"
|
||||
cd1.mkdir(parents=True)
|
||||
# Ziel existiert bereits
|
||||
(tmp_path / "TestAlbum_2024").mkdir()
|
||||
|
||||
_make_album_json(album_root / "album.json", n_tracks=1)
|
||||
_make_flac(cd1 / "track01.flac")
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"apply", str(cd1), str(album_root / "album.json"), "--in-place",
|
||||
])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert album_root.exists() # nicht umbenannt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue