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:
@@ -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)
|
||||
Reference in New Issue
Block a user