ripping.py: HandBrakeCLI-Check + Typ-Erkennung
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import shutil
|
||||
from celery_app import celery_app
|
||||
|
||||
|
||||
def check_handbrake_installed() -> bool:
|
||||
"""Prüft, ob HandBrakeCLI installiert ist."""
|
||||
return shutil.which("HandBrakeCLI") is not None
|
||||
|
||||
|
||||
def get_progress_from_line(line: str) -> int:
|
||||
"""Extrahiert Fortschritt in Prozent aus HandBrake-Ausgabe."""
|
||||
match = re.search(r'(\d+\.\d+)%', line)
|
||||
@@ -14,6 +20,12 @@ def get_progress_from_line(line: str) -> int:
|
||||
|
||||
def run_handbrake(device_path: str, output_path: str) -> dict:
|
||||
"""Rippt eine DVD/Blu-ray mit HandBrakeCLI."""
|
||||
if not check_handbrake_installed():
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "HandBrakeCLI ist nicht installiert"
|
||||
}
|
||||
|
||||
try:
|
||||
cmd = [
|
||||
"HandBrakeCLI",
|
||||
@@ -66,9 +78,40 @@ def run_handbrake(device_path: str, output_path: str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
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"
|
||||
|
||||
except Exception:
|
||||
return "unknown"
|
||||
|
||||
|
||||
@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."""
|
||||
if not check_handbrake_installed():
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "HandBrakeCLI ist nicht installiert"
|
||||
}
|
||||
|
||||
output_dir = f"/output/dvd/{disc_id}"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = f"{output_dir}/dvd_{disc_id}.mkv"
|
||||
@@ -79,6 +122,12 @@ def rip_dvd(self, device_path: str, disc_id: str) -> dict:
|
||||
@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."""
|
||||
if not check_handbrake_installed():
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "HandBrakeCLI ist nicht installiert"
|
||||
}
|
||||
|
||||
output_dir = f"/output/bluray/{disc_id}"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = f"{output_dir}/bluray_{disc_id}.mkv"
|
||||
|
||||
Reference in New Issue
Block a user