Switching to metube for downloads

This commit is contained in:
2025-09-07 13:21:36 +02:00
parent cb46334901
commit 0d22dd1794
3 changed files with 162 additions and 0 deletions

View File

@@ -231,6 +231,32 @@ def publish_to_openwebui(paths):
except Exception as e:
log({"status": "owui_error", "error": str(e)})
from pathlib import Path
def handle_local_file(path_str: str):
"""Transcribe & index a local media file that already exists in /library.
Safe to call repeatedly; it skips if transcript JSON already exists.
"""
try:
p = Path(path_str)
if not p.exists():
log({"url": path_str, "status": "error", "error": "file_not_found"})
return
title = p.stem
base_json = TRN / f"{title}.json"
if base_json.exists():
log({"url": path_str, "status": "skip", "reason": "already_transcribed"})
return
info = {"url": path_str, "status": "transcribing", "title": title, "uploader": p.parent.name, "date": "", "path": str(p)}
log(info)
base = transcribe(p)
index_meili(base.with_suffix(".json"))
publish_to_openwebui([base.with_suffix(".txt")])
log({**info, **{"status": "done"}})
except Exception as e:
log({"url": path_str, "status": "error", "error": str(e)})
raise
def handle_web(url: str):
info = {"url": url, "status":"web-downloading", "title":"", "uploader":"", "date":"", "path":""}
log(info)
@@ -244,6 +270,12 @@ def handle_web(url: str):
def handle_url(url: str):
try:
# If a local file path (or file:// URL) is provided, process it directly
if url.startswith("file://"):
return handle_local_file(url[7:])
if url.startswith("/") and Path(url).exists():
return handle_local_file(url)
if not is_media_url(url):
handle_web(url)
return