Fix album_dir path after in-place directory rename
_rename_album_dir_inplace now returns the updated input_dir path (e.g. .../Golden_Oldies_Vol_11/CD1 instead of .../Album1/CD1). apply uses the return value so the final 'Fertig!' message and any subsequent operations reference the correct, post-rename path. Also fix CDDB header album name extraction (regex search between ---- markers instead of stripping leading/trailing dashes). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0c0311b00f
commit
984d8acc88
1 changed files with 9 additions and 4 deletions
|
|
@ -86,7 +86,7 @@ def _scan_to_album(
|
||||||
_CD_SUBDIR = re.compile(r"^CD\d+$", re.IGNORECASE)
|
_CD_SUBDIR = re.compile(r"^CD\d+$", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
def _rename_album_dir_inplace(input_dir: Path, album: Album) -> None:
|
def _rename_album_dir_inplace(input_dir: Path, album: Album) -> Path:
|
||||||
"""Benennt das Album-Wurzelverzeichnis nach den Metadaten um.
|
"""Benennt das Album-Wurzelverzeichnis nach den Metadaten um.
|
||||||
|
|
||||||
Muss als allerletzter Schritt aufgerufen werden, nachdem Tags,
|
Muss als allerletzter Schritt aufgerufen werden, nachdem Tags,
|
||||||
|
|
@ -97,6 +97,9 @@ def _rename_album_dir_inplace(input_dir: Path, album: Album) -> None:
|
||||||
Umbenennung erfolgt automatisch.
|
Umbenennung erfolgt automatisch.
|
||||||
- Sonst (input_dir ist selbst das Album-Wurzelverzeichnis) → nur Hinweis
|
- Sonst (input_dir ist selbst das Album-Wurzelverzeichnis) → nur Hinweis
|
||||||
ausgeben, da ein Umbenennen des aktiven Verzeichnisses vermieden wird.
|
ausgeben, da ein Umbenennen des aktiven Verzeichnisses vermieden wird.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Aktualisierter Pfad von input_dir nach dem Umbenennen.
|
||||||
"""
|
"""
|
||||||
abs_input = input_dir.resolve()
|
abs_input = input_dir.resolve()
|
||||||
desired = sanitize_filename(album.folder_name)
|
desired = sanitize_filename(album.folder_name)
|
||||||
|
|
@ -105,7 +108,7 @@ def _rename_album_dir_inplace(input_dir: Path, album: Album) -> None:
|
||||||
# CD-Unterverzeichnis übergeben → Elternverzeichnis umbenennen
|
# CD-Unterverzeichnis übergeben → Elternverzeichnis umbenennen
|
||||||
album_root = abs_input.parent
|
album_root = abs_input.parent
|
||||||
if album_root.name == desired:
|
if album_root.name == desired:
|
||||||
return # bereits korrekt
|
return input_dir # bereits korrekt
|
||||||
new_path = album_root.parent / desired
|
new_path = album_root.parent / desired
|
||||||
if new_path.exists():
|
if new_path.exists():
|
||||||
typer.echo(
|
typer.echo(
|
||||||
|
|
@ -113,9 +116,10 @@ def _rename_album_dir_inplace(input_dir: Path, album: Album) -> None:
|
||||||
"Verzeichnis nicht umbenannt.",
|
"Verzeichnis nicht umbenannt.",
|
||||||
err=True,
|
err=True,
|
||||||
)
|
)
|
||||||
return
|
return input_dir
|
||||||
album_root.rename(new_path)
|
album_root.rename(new_path)
|
||||||
typer.echo(f"Verzeichnis umbenannt: {album_root.name} → {desired}")
|
typer.echo(f"Verzeichnis umbenannt: {album_root.name} → {desired}")
|
||||||
|
return new_path / abs_input.name # z.B. .../Golden_Oldies_Vol_11/CD1
|
||||||
else:
|
else:
|
||||||
# Album-Wurzelverzeichnis direkt übergeben → nur Hinweis
|
# Album-Wurzelverzeichnis direkt übergeben → nur Hinweis
|
||||||
if abs_input.name != desired:
|
if abs_input.name != desired:
|
||||||
|
|
@ -123,6 +127,7 @@ def _rename_album_dir_inplace(input_dir: Path, album: Album) -> None:
|
||||||
f"Tipp: Verzeichnis manuell umbenennen:\n"
|
f"Tipp: Verzeichnis manuell umbenennen:\n"
|
||||||
f" mv '{abs_input.name}' '{desired}'"
|
f" mv '{abs_input.name}' '{desired}'"
|
||||||
)
|
)
|
||||||
|
return input_dir
|
||||||
|
|
||||||
|
|
||||||
def _check_disc_counts_or_exit(album: Album, input_dir: Path, album_json: Path) -> None:
|
def _check_disc_counts_or_exit(album: Album, input_dir: Path, album_json: Path) -> None:
|
||||||
|
|
@ -300,7 +305,7 @@ def apply(
|
||||||
generate_playlist(album, album_dir)
|
generate_playlist(album, album_dir)
|
||||||
|
|
||||||
if in_place:
|
if in_place:
|
||||||
_rename_album_dir_inplace(input_dir, album)
|
album_dir = _rename_album_dir_inplace(input_dir, album)
|
||||||
|
|
||||||
typer.echo(f"Fertig! Album liegt in: {album_dir}")
|
typer.echo(f"Fertig! Album liegt in: {album_dir}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue