feat(patches): reclip history cards match UI design; thumbnails persisted
History section now renders reclip's own card components (thumbnail, serif title, meta line with date/size, Save/Transcript pill buttons). Frontend passes the video thumbnail to /api/download so history cards show real artwork; pre-thumbnail entries keep the placeholder icon.
This commit is contained in:
1 parent
b8773b8fc2
commit
10f5811d7f
3 files changed
+162
-97
No files matched your search
+42
-1
@@ -3,6 +3,7 @@ import uuid
|
||||
import glob
|
||||
import json
|
||||
import re
|
||||
import hashlib
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
@@ -56,6 +57,7 @@ def record_history(job):
|
||||
"job_id": job.get("job_id"),
|
||||
"url": job.get("url", ""),
|
||||
"title": job.get("title", ""),
|
||||
"thumbnail": job.get("thumbnail", ""),
|
||||
"filename": job.get("filename", ""),
|
||||
"file": job.get("file", ""),
|
||||
"transcript": job.get("transcript") or "",
|
||||
@@ -67,6 +69,44 @@ def record_history(job):
|
||||
save_history(history[:200])
|
||||
|
||||
|
||||
MEDIA_EXTS = (".mp4", ".mkv", ".webm", ".m4a", ".mp3", ".flac", ".mov", ".avi", ".wav", ".ts")
|
||||
|
||||
|
||||
def backfill_history():
|
||||
"""Add on-disk downloads that predate history.json (or were dropped into
|
||||
the downloads dir manually) so the whole library shows up on the page.
|
||||
The transcript flag is resolved live at read time, so backfilled entries
|
||||
pick up manual yt-transcribe sidecars automatically."""
|
||||
for name in sorted(os.listdir(DOWNLOAD_DIR)):
|
||||
path = os.path.join(DOWNLOAD_DIR, name)
|
||||
if not os.path.isfile(path) or not name.lower().endswith(MEDIA_EXTS):
|
||||
continue
|
||||
with _history_lock:
|
||||
history = load_history()
|
||||
if any(h.get("file") == path for h in history):
|
||||
continue
|
||||
stem = os.path.splitext(name)[0]
|
||||
# a 10-hex stem is a reclip job id — the real title wasn't kept
|
||||
title = "" if re.fullmatch(r"[0-9a-f]{10}", stem) else stem
|
||||
history.insert(0, {
|
||||
"job_id": hashlib.sha1(path.encode()).hexdigest()[:10],
|
||||
"url": "",
|
||||
"title": title,
|
||||
"filename": name,
|
||||
"file": path,
|
||||
"transcript": "",
|
||||
"transcript_name": "",
|
||||
"has_transcript": False,
|
||||
"size": os.path.getsize(path),
|
||||
"date": time.strftime("%Y-%m-%d %H:%M:%S",
|
||||
time.localtime(os.path.getmtime(path))),
|
||||
})
|
||||
save_history(history[:200])
|
||||
|
||||
|
||||
backfill_history()
|
||||
|
||||
|
||||
def parse_ytdlp_json(stdout):
|
||||
"""Parse yt-dlp JSON output.
|
||||
|
||||
@@ -282,7 +322,8 @@ def start_download():
|
||||
return jsonify({"error": "No URL provided"}), 400
|
||||
|
||||
job_id = uuid.uuid4().hex[:10]
|
||||
jobs[job_id] = {"job_id": job_id, "status": "downloading", "url": url, "title": title}
|
||||
jobs[job_id] = {"job_id": job_id, "status": "downloading", "url": url, "title": title,
|
||||
"thumbnail": (data.get("thumbnail") or "")[:500]}
|
||||
|
||||
thread = threading.Thread(target=run_download, args=(job_id, url, format_choice, format_id))
|
||||
thread.daemon = True
|
||||
|
||||
Reference in new issue
Block a user