57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
|
|
"""CD-Ripping via abcde."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
import subprocess
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
def rip_disc(
|
||
|
|
device: str,
|
||
|
|
output_dir: Path,
|
||
|
|
audio_format: str = "flac",
|
||
|
|
eject: bool = True,
|
||
|
|
) -> Path:
|
||
|
|
"""Rippt eine CD mit abcde in output_dir.
|
||
|
|
|
||
|
|
Args:
|
||
|
|
device: CD-Laufwerk, z.B. '/dev/cdrom'
|
||
|
|
output_dir: Zielverzeichnis für die gerippten Dateien
|
||
|
|
audio_format: Ausgabeformat (flac, mp3, ogg, opus)
|
||
|
|
eject: CD nach dem Rippen auswerfen
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
Pfad zum Verzeichnis mit den gerippten Dateien
|
||
|
|
"""
|
||
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
cmd = [
|
||
|
|
"abcde",
|
||
|
|
"-n", # kein CDDB-Lookup
|
||
|
|
"-N", # non-interaktiv
|
||
|
|
"-p", # führende Nullen bei Tracknummern
|
||
|
|
"-o", audio_format,
|
||
|
|
"-d", device,
|
||
|
|
"-D", # kein Debug
|
||
|
|
]
|
||
|
|
if eject:
|
||
|
|
cmd.append("-x")
|
||
|
|
|
||
|
|
logger.info("Starte Ripping: %s", " ".join(cmd))
|
||
|
|
|
||
|
|
result = subprocess.run(
|
||
|
|
cmd,
|
||
|
|
cwd=str(output_dir),
|
||
|
|
capture_output=True,
|
||
|
|
text=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
if result.returncode != 0:
|
||
|
|
logger.error("abcde Fehler: %s", result.stderr)
|
||
|
|
raise RuntimeError(f"abcde fehlgeschlagen (exit {result.returncode}): {result.stderr}")
|
||
|
|
|
||
|
|
logger.info("Ripping abgeschlossen: %s", output_dir)
|
||
|
|
return output_dir
|