Metadaten-Fallback OMDb + Pre-Scan repariert + Eject-Endpoint
- clients/omdb.py: OMDb als zweite Quelle (Fallback-Kette: TMDB exakt ->
OMDb -> bester TMDB-Vorschlag mit niedriger Confidence -> unknown)
- Pre-Scan-Reparatur: Titel kam nie an — makemkvcon existiert nur im
Worker, isosize war nirgends installiert (fiel still auf "DVD" zurueck).
Jetzt: ISO-9660-Volume-Label direkt vom Medium + Label-Normalisierung
(PULP_FICTION -> Pulp Fiction), Disc-Typ ueber zentrale detection.py
- POST /devices/{name}/eject (CDROMEJECT-ioctl) mit Job-Schutz (409 wenn
auf dem Laufwerk gerade gerippt wird)
- OMDB_API_KEY in compose/.env.example; .env.example komplett ehrlich
dokumentiert (JWT-Pflicht, MakeMKV-Beta-Key-Rhythmus)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,16 +5,51 @@ WIEDERHERGESTELLT 22.07.2026: Beim SoC-Refactoring wurde die echte Implementieru
|
||||
lieferte seitdem immer „Unknown Disc". Dies ist die echte Logik, bereinigt.
|
||||
"""
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import Dict, List
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import detection
|
||||
from clients.tmdb import TMDBClient
|
||||
from clients.musicbrainz import MusicBrainzClient
|
||||
from clients.omdb import OMDbClient
|
||||
from clients.thetvdb import TheTVDBClient
|
||||
from cache import get, set as cache_set
|
||||
from cache.keys import generate_prescan_key
|
||||
|
||||
|
||||
def normalize_disc_label(label: str) -> str:
|
||||
"""Disc-Labels wie 'PULP_FICTION_DE' → 'Pulp Fiction De' (pure Funktion).
|
||||
|
||||
Volume-Labels sind fast immer GROSS_MIT_UNTERSTRICHEN — so findet keine
|
||||
Metadaten-API etwas. Unterstriche zu Leerzeichen, Titel-Schreibung.
|
||||
"""
|
||||
if not label:
|
||||
return ""
|
||||
bereinigt = " ".join(label.replace("_", " ").replace(".", " ").split())
|
||||
if bereinigt.isupper():
|
||||
bereinigt = bereinigt.title()
|
||||
return bereinigt
|
||||
|
||||
|
||||
def read_iso_volume_label(device_path: str) -> Optional[str]:
|
||||
"""Liest das Volume-Label aus dem ISO-9660 Primary Volume Descriptor.
|
||||
|
||||
Sektor 16 (Offset 32768), Bytes 40-71 = Volume Identifier. Funktioniert für
|
||||
DVDs und die meisten Blu-rays (UDF-Bridge) — ganz ohne Zusatzwerkzeuge.
|
||||
"""
|
||||
try:
|
||||
with open(device_path, "rb") as f:
|
||||
f.seek(32768)
|
||||
pvd = f.read(2048)
|
||||
if len(pvd) < 72 or pvd[1:6] != b"CD001":
|
||||
return None
|
||||
label = pvd[40:72].decode("ascii", errors="replace").strip()
|
||||
return label or None
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
class PreScanResult:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -48,6 +83,7 @@ class PreScan:
|
||||
self.tmdb = TMDBClient()
|
||||
self.musicbrainz = MusicBrainzClient()
|
||||
self.thetvdb = TheTVDBClient()
|
||||
self.omdb = OMDbClient()
|
||||
|
||||
def scan(self, device_path: str) -> PreScanResult:
|
||||
"""Führe Pre-Scan durch."""
|
||||
@@ -59,25 +95,13 @@ class PreScan:
|
||||
return self._scan_video(device_path, toc)
|
||||
|
||||
def _detect_disc_type(self, device_path: str) -> str:
|
||||
"""Erkenne Disc-Typ (CD/DVD/Blu-ray) über die Medien-Größe."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["isosize", "-x", device_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
if result.returncode == 0:
|
||||
size = int(result.stdout.strip())
|
||||
if size < 700 * 1024 * 1024:
|
||||
return "CD"
|
||||
elif size < 15 * 1024 * 1024 * 1024:
|
||||
return "DVD"
|
||||
else:
|
||||
return "Blu-ray"
|
||||
except Exception:
|
||||
pass
|
||||
return "DVD"
|
||||
"""Erkenne Disc-Typ über die zentrale ioctl-Erkennung (detection.py).
|
||||
|
||||
Vorher lief hier `isosize` — das Werkzeug war im Container nicht
|
||||
installiert, die Erkennung fiel still immer auf "DVD" zurück.
|
||||
"""
|
||||
typ = detection.detect_disc_type(device_path)
|
||||
return {"cd": "CD", "dvd": "DVD", "bluray": "Blu-ray"}.get(typ, "DVD")
|
||||
|
||||
def _read_toc(self, device_path: str, disc_type: str) -> Dict:
|
||||
"""Lese TOC (Table of Contents)."""
|
||||
@@ -105,25 +129,30 @@ class PreScan:
|
||||
"duration": 0
|
||||
})
|
||||
else:
|
||||
# makemkvcon liest nur den TOC — KEIN Ripping
|
||||
result = subprocess.run(
|
||||
["makemkvcon", "--minlength=300", "--progress=off", "info", device_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
for line in result.stdout.split('\n'):
|
||||
if line.startswith('DRV:'):
|
||||
parts = line.split(',')
|
||||
if len(parts) >= 4:
|
||||
toc["title"] = parts[3].strip().strip('"')
|
||||
elif line.startswith('TINFO:'):
|
||||
parts = line.split(',')
|
||||
if len(parts) >= 5:
|
||||
toc["tracks"].append({
|
||||
"title": parts[4].strip().strip('"') if len(parts) > 4 else "Title",
|
||||
"duration": int(parts[2]) if len(parts) > 2 else 0
|
||||
})
|
||||
# Titel-Quelle 1: ISO-Volume-Label direkt vom Medium — läuft
|
||||
# überall. (makemkvcon gibt es NUR im Worker-Container; der
|
||||
# alte Aufruf hier scheiterte in der API still und der Titel
|
||||
# blieb ewig "Unknown Title".)
|
||||
label = read_iso_volume_label(device_path)
|
||||
if label:
|
||||
toc["title"] = normalize_disc_label(label)
|
||||
|
||||
# Titel-Quelle 2 (optional, falls makemkvcon doch da ist):
|
||||
if shutil.which("makemkvcon"):
|
||||
result = subprocess.run(
|
||||
["makemkvcon", "-r", "--minlength=300", "info", f"dev:{device_path}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=120
|
||||
)
|
||||
for line in result.stdout.split('\n'):
|
||||
if line.startswith('TINFO:'):
|
||||
parts = line.split(',')
|
||||
if len(parts) >= 5:
|
||||
toc["tracks"].append({
|
||||
"title": parts[4].strip().strip('"') if len(parts) > 4 else "Title",
|
||||
"duration": int(parts[2]) if len(parts) > 2 else 0
|
||||
})
|
||||
except Exception as e:
|
||||
print(f"Pre-Scan TOC Error: {e}")
|
||||
return toc
|
||||
@@ -188,7 +217,7 @@ class PreScan:
|
||||
if cached:
|
||||
return PreScanResult(**cached)
|
||||
|
||||
title = toc["title"] or "Unknown Title"
|
||||
title = normalize_disc_label(toc["title"] or "") or "Unknown Title"
|
||||
confidence = 0.0
|
||||
metadata = {}
|
||||
matched = False
|
||||
@@ -235,6 +264,35 @@ class PreScan:
|
||||
matched = True
|
||||
break
|
||||
|
||||
# Fallback 1: OMDb (eigene Datenbasis — findet oft, was TMDB nicht
|
||||
# exakt trifft; braucht OMDB_API_KEY, sonst überspringt es sich selbst)
|
||||
if not matched:
|
||||
omdb_treffer = self.omdb.lookup(title)
|
||||
if omdb_treffer:
|
||||
confidence = 0.8
|
||||
metadata = omdb_treffer
|
||||
title = omdb_treffer.get("title", title)
|
||||
matched = True
|
||||
|
||||
# Fallback 2: bester TMDB-Vorschlag ohne exakten Treffer — als
|
||||
# VORSCHLAG gekennzeichnet (niedrige Confidence, Nutzer korrigiert)
|
||||
if not matched and movies:
|
||||
vorschlag = self.tmdb.get_movie_details(movies[0]["id"])
|
||||
if vorschlag:
|
||||
confidence = 0.6
|
||||
metadata = {
|
||||
"type": "movie",
|
||||
"id": movies[0]["id"],
|
||||
"title": vorschlag.get("title", title),
|
||||
"year": int(vorschlag.get("release_date", "0")[:4]) if vorschlag.get("release_date") else None,
|
||||
"overview": vorschlag.get("overview", ""),
|
||||
"poster_path": vorschlag.get("poster_path", ""),
|
||||
"backdrop_path": vorschlag.get("backdrop_path", ""),
|
||||
"runtime": vorschlag.get("runtime", 0),
|
||||
"genres": [g["name"] for g in vorschlag.get("genres", [])]
|
||||
}
|
||||
matched = True
|
||||
|
||||
if not matched:
|
||||
confidence = 0.3
|
||||
metadata = {
|
||||
|
||||
Reference in New Issue
Block a user