Archived
Kod från /home/simon/Documents/Default Project/videovault (Python: yt-dlp + ffmpeg + SQLite FTS5 + Meilisearch + FastAPI). Runtime-data (.venv, data/, watch/, *.db, meili-data) exkluderad. Utökad .gitignore (secrets/cookies/media), referenskopior av systemd-user-units i deploy/systemd/, README-sektion Driftsläge: appen saknar auth och får inte exponeras utan auth. Ej deployad. Laptop-tjänsterna vv-web/vv-worker är avaktiverade. Co-Authored-By: Claude Opus 5 <[email protected]>
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
import traceback
|
|
|
|
from . import config, db
|
|
from . import downloader, transcode, categorize
|
|
from .search import engine
|
|
|
|
|
|
def process_job(vid_id):
|
|
try:
|
|
video = db.get(vid_id)
|
|
if not video or video["status"] == "ready":
|
|
return
|
|
download_path = video.get("download_path")
|
|
db.set_status(vid_id, "downloading")
|
|
meta = downloader.download(video["url"], vid_id)
|
|
db.update_meta(vid_id, **pick(meta))
|
|
if config.OPTIMIZE:
|
|
db.set_status(vid_id, "transcoding")
|
|
opt = transcode.transcode(video["url"], vid_id, meta["download_path"])
|
|
db.update_meta(vid_id, **pick(opt))
|
|
video = db.get(vid_id)
|
|
cats, tags = categorize.categorize(video, height=video.get("height"),
|
|
duration=video.get("duration"),
|
|
site=video.get("site"))
|
|
db.update_meta(vid_id, categories=",".join(cats), tags=",".join(tags))
|
|
db.set_status(vid_id, "ready")
|
|
index(vid_id)
|
|
except Exception as exc:
|
|
db.set_status(vid_id, "failed", error=_short(traceback.format_exc()))
|
|
raise
|
|
|
|
|
|
def pick(mapping):
|
|
allowed = {
|
|
"site", "title", "description", "uploader", "duration", "published_at",
|
|
"download_path", "size_bytes", "width", "height", "quality",
|
|
"optimized_path", "poster_path", "thumb_path", "preview_path",
|
|
}
|
|
return {k: v for k, v in mapping.items() if k in allowed and v is not None}
|
|
|
|
|
|
def _short(trace):
|
|
lines = [l for l in trace.strip().splitlines() if "Error" in l or "rror" in l]
|
|
return (lines[-1] if lines else trace).strip()[-500:]
|
|
|
|
|
|
def index(vid_id):
|
|
from . import db
|
|
|
|
v = db.get(vid_id)
|
|
if not v or v["status"] != "ready":
|
|
return
|
|
doc = {
|
|
"id": v["id"],
|
|
"title": v["title"] or "",
|
|
"description": v["description"] or "",
|
|
"uploader": v["uploader"] or "",
|
|
"tags": (v["tags"] or "").split(","),
|
|
"categories": (v["categories"] or "").split(","),
|
|
"site": v["site"] or "",
|
|
"duration": v["duration"],
|
|
"poster": v["poster_path"] or "",
|
|
"quality": v["quality"] or "",
|
|
"added_at": v["added_at"],
|
|
}
|
|
engine.index_video(doc)
|
|
|
|
|
|
def index_all():
|
|
from . import db
|
|
|
|
conn = db.connect()
|
|
rows = conn.execute("SELECT id FROM videos WHERE status='ready'").fetchall()
|
|
conn.close()
|
|
for r in rows:
|
|
index(r["id"])
|
|
|
|
|
|
def reprocess(vid_id):
|
|
try:
|
|
db.set_status(vid_id, "queued", error=None)
|
|
process_job(vid_id)
|
|
return True
|
|
except Exception:
|
|
return False |