Etappe 2: Ripping-Pipeline — Erste Implementierung
- DockerfileWorker: abcde, flac, ffmpeg, handbrake-cli installiert - ripping.py: Ripping-Module für DVD/Blu-ray mit HandBrake - tasks.py: Disc-Typ-Erkennung + passendes Ripping-Modul - docker-compose.yml: Output-Verzeichnis /output hinzugefügt - output/ Verzeichnis erstellt WIP: CD-Ripping mit abcde noch nicht implementiert
This commit is contained in:
@@ -4,6 +4,10 @@ WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
abcde \
|
||||
flac \
|
||||
ffmpeg \
|
||||
handbrake-cli \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --no-cache-dir \
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
from celery_app import celery_app
|
||||
|
||||
|
||||
def get_progress_from_line(line: str) -> int:
|
||||
"""Extrahiert Fortschritt in Prozent aus HandBrake-Ausgabe."""
|
||||
match = re.search(r'(\d+\.\d+)%', line)
|
||||
if match:
|
||||
return int(float(match.group(1)))
|
||||
return 0
|
||||
|
||||
|
||||
def run_handbrake(device_path: str, output_path: str) -> dict:
|
||||
"""Rippt eine DVD/Blu-ray mit HandBrakeCLI."""
|
||||
try:
|
||||
cmd = [
|
||||
"HandBrakeCLI",
|
||||
"--input", device_path,
|
||||
"--output", output_path,
|
||||
"--all",
|
||||
"--progress",
|
||||
"--preset", "Fast 1080p30"
|
||||
]
|
||||
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1
|
||||
)
|
||||
|
||||
for line in process.stdout:
|
||||
progress = get_progress_from_line(line)
|
||||
if progress > 0:
|
||||
celery_app.send_task(
|
||||
"worker.ripping.update_progress",
|
||||
kwargs={
|
||||
"progress": progress,
|
||||
"status": "ripping",
|
||||
"message": f"Rippe Titel {progress}%"
|
||||
}
|
||||
)
|
||||
|
||||
process.wait()
|
||||
|
||||
if process.returncode == 0:
|
||||
return {
|
||||
"status": "success",
|
||||
"output_path": output_path,
|
||||
"return_code": process.returncode
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"HandBrake failed with code {process.returncode}",
|
||||
"return_code": process.returncode
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="worker.ripping.rip_dvd")
|
||||
def rip_dvd(self, device_path: str, disc_id: str) -> dict:
|
||||
"""Rippt eine DVD mit HandBrake."""
|
||||
output_dir = f"/output/dvd/{disc_id}"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = f"{output_dir}/dvd_{disc_id}.mkv"
|
||||
|
||||
return run_handbrake(device_path, output_path)
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="worker.ripping.rip_bluray")
|
||||
def rip_bluray(self, device_path: str, disc_id: str) -> dict:
|
||||
"""Rippt eine Blu-ray mit HandBrake."""
|
||||
output_dir = f"/output/bluray/{disc_id}"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = f"{output_dir}/bluray_{disc_id}.mkv"
|
||||
|
||||
return run_handbrake(device_path, output_path)
|
||||
+50
-10
@@ -1,15 +1,55 @@
|
||||
import os
|
||||
import subprocess
|
||||
from celery_app import celery_app
|
||||
from ripping import rip_dvd, rip_bluray
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="worker.tasks.detect_disc")
|
||||
def detect_disc(self, device_path: str, disc_type: str):
|
||||
"""Dummy-Disk-Erkennungstask."""
|
||||
print(f"Disc erkannt: {disc_type}, Device: {device_path}")
|
||||
def detect_disc_type(device_path: str) -> str:
|
||||
"""Erkennt den Disc-Typ anhand des Gerätepfads."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["file", "-L", device_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
output = result.stdout.lower()
|
||||
|
||||
if "dvd" in output or "video_ts" in output:
|
||||
return "dvd"
|
||||
elif "bluray" in output or "bdmv" in output:
|
||||
return "bluray"
|
||||
elif "audio" in output or "cda" in output:
|
||||
return "cd"
|
||||
else:
|
||||
return "unknown"
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Disc erkannt: {disc_type}",
|
||||
"device_path": device_path,
|
||||
"disc_type": disc_type
|
||||
}
|
||||
except Exception:
|
||||
return "unknown"
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="worker.tasks.rip_disc")
|
||||
def rip_disc(self, device_path: str, disc_id: str = None):
|
||||
"""Rippt eine Disc basierend auf ihrem Typ."""
|
||||
disc_type = detect_disc_type(device_path)
|
||||
|
||||
if not disc_id:
|
||||
disc_id = device_path.replace("/", "_")
|
||||
|
||||
if disc_type == "cd":
|
||||
return {
|
||||
"status": "not_implemented",
|
||||
"message": "CD-Ripping mit abcde noch nicht implementiert",
|
||||
"disc_type": disc_type
|
||||
}
|
||||
elif disc_type == "dvd":
|
||||
return rip_dvd(device_path, disc_id)
|
||||
elif disc_type == "bluray":
|
||||
return rip_bluray(device_path, disc_id)
|
||||
else:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Unbekannter Disc-Typ: {disc_type}",
|
||||
"disc_type": disc_type
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user