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:
Lap Tran committed 2026-10-25 20:41:31 -04:00
1 parent b8773b8fc2
commit 10f5811d7f
3 files changed
+162 -97

No files matched your search

+42 -1
View File
@@ -3,6 +3,7 @@ import uuid
import glob import glob
import json import json
import re import re
import hashlib
import subprocess import subprocess
import threading import threading
import time import time
@@ -56,6 +57,7 @@ def record_history(job):
"job_id": job.get("job_id"), "job_id": job.get("job_id"),
"url": job.get("url", ""), "url": job.get("url", ""),
"title": job.get("title", ""), "title": job.get("title", ""),
"thumbnail": job.get("thumbnail", ""),
"filename": job.get("filename", ""), "filename": job.get("filename", ""),
"file": job.get("file", ""), "file": job.get("file", ""),
"transcript": job.get("transcript") or "", "transcript": job.get("transcript") or "",
@@ -67,6 +69,44 @@ def record_history(job):
save_history(history[:200]) 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): def parse_ytdlp_json(stdout):
"""Parse yt-dlp JSON output. """Parse yt-dlp JSON output.
@@ -282,7 +322,8 @@ def start_download():
return jsonify({"error": "No URL provided"}), 400 return jsonify({"error": "No URL provided"}), 400
job_id = uuid.uuid4().hex[:10] 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 = threading.Thread(target=run_download, args=(job_id, url, format_choice, format_id))
thread.daemon = True thread.daemon = True
+28 -40
View File
@@ -343,41 +343,16 @@
.dl-all-btn:hover { background: #2d2d2a; } .dl-all-btn:hover { background: #2d2d2a; }
.dl-all-btn:disabled { opacity: 0.4; cursor: not-allowed; } .dl-all-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* History */ /* History — same card language as the fetch results */
.hist-h { .hist-h {
font-family: 'Instrument Serif', serif; font-family: 'Instrument Serif', serif;
font-size: 1.4rem; font-size: 1.9rem;
font-weight: 400; font-weight: 400;
margin: 32px 0 10px; letter-spacing: -0.02em;
margin: 44px 0 14px;
color: var(--fg); color: var(--fg);
} }
.hist-row { #history .card { animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
display: flex;
gap: 10px;
align-items: center;
border: 1.5px solid var(--card-border);
border-radius: 10px;
background: var(--card);
padding: 10px 12px;
margin-bottom: 6px;
}
.hist-main { flex: 1; min-width: 0; }
.hist-title {
font-size: 0.8rem;
color: var(--fg);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.hist-meta {
font-size: 0.65rem;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.03em;
margin-top: 2px;
}
.hist-meta .t-flag { color: var(--success); }
.hist-actions { display: flex; gap: 6px; }
a.card-dl-btn { text-decoration: none; display: inline-block; } a.card-dl-btn { text-decoration: none; display: inline-block; }
.spin { .spin {
@@ -673,6 +648,7 @@
format: currentFormat, format: currentFormat,
format_id: c.selectedFormatId, format_id: c.selectedFormatId,
title: c.title || '', title: c.title || '',
thumbnail: c.thumbnail || '',
}), }),
}); });
const data = await res.json(); const data = await res.json();
@@ -763,17 +739,29 @@
const rows = await res.json(); const rows = await res.json();
const box = document.getElementById('history'); const box = document.getElementById('history');
if (!Array.isArray(rows) || !rows.length) return; if (!Array.isArray(rows) || !rows.length) return;
const items = rows.map(r => ` const items = rows.map(r => {
<div class="hist-row"> let thumbHtml;
<div class="hist-main"> if (r.thumbnail) {
<div class="hist-title">${esc(r.title || r.filename || r.url || '')}</div> thumbHtml = `<img src="${r.thumbnail}" alt="">`;
<div class="hist-meta">${esc(r.date || '')}${r.size ? ' · ' + fmtSize(r.size) : ''} · ${r.has_transcript ? '<span class="t-flag">transcript ✓</span>' : 'no transcript'}</div> } else {
thumbHtml = `<div class="no-thumb"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="2" width="20" height="20" rx="2"/><circle cx="8" cy="8" r="1.5"/><path d="m21 15-5-5L5 21"/></svg></div>`;
}
const flag = r.has_transcript
? `<span class="card-status done">transcript ✓</span>`
: `<span class="card-status">no transcript</span>`;
return `
<div class="card">
<div class="card-thumb">${thumbHtml}</div>
<div class="card-body">
<div class="card-title">${esc(r.title || r.filename || r.url || 'Untitled')}</div>
<div class="card-meta">${esc(r.date || '')}${r.size ? ' · ' + fmtSize(r.size) : ''} · <span class="${r.has_transcript ? 'card-status done' : ''}">${r.has_transcript ? 'transcript ✓' : 'no transcript'}</span></div>
<div class="card-actions">
<a class="card-dl-btn" href="/api/file/${r.job_id}" download>Save</a>
${r.has_transcript ? `<a class="card-dl-btn" href="/api/transcript/${r.job_id}" download>Transcript</a>` : ''}
</div>
</div> </div>
<div class="hist-actions"> </div>`;
<a class="card-dl-btn" href="/api/file/${r.job_id}" download>${esc(r.filename || 'Save').replace(/\.[^.]+$/, '')}</a> }).join('');
${r.has_transcript ? `<a class="card-dl-btn" href="/api/transcript/${r.job_id}" download>Transcript</a>` : ''}
</div>
</div>`).join('');
box.innerHTML = `<h2 class="hist-h">History</h2>${items}`; box.innerHTML = `<h2 class="hist-h">History</h2>${items}`;
} catch { /* history unavailable */ } } catch { /* history unavailable */ }
} }
+92 -56
View File
@@ -1,19 +1,20 @@
diff --git a/app.py b/app.py diff --git a/app.py b/app.py
index 2b5eaa5..3c3c9c8 100644 index 2b5eaa5..1dfbbd0 100644
--- a/app.py --- a/app.py
+++ b/app.py +++ b/app.py
@@ -2,8 +2,10 @@ import os @@ -2,8 +2,11 @@ import os
import uuid import uuid
import glob import glob
import json import json
+import re +import re
+import hashlib
import subprocess import subprocess
import threading import threading
+import time +import time
from flask import Flask, request, jsonify, send_file, render_template from flask import Flask, request, jsonify, send_file, render_template
app = Flask(__name__) app = Flask(__name__)
@@ -12,6 +14,58 @@ os.makedirs(DOWNLOAD_DIR, exist_ok=True) @@ -12,6 +15,97 @@ os.makedirs(DOWNLOAD_DIR, exist_ok=True)
jobs = {} jobs = {}
@@ -59,6 +60,7 @@ index 2b5eaa5..3c3c9c8 100644
+ "job_id": job.get("job_id"), + "job_id": job.get("job_id"),
+ "url": job.get("url", ""), + "url": job.get("url", ""),
+ "title": job.get("title", ""), + "title": job.get("title", ""),
+ "thumbnail": job.get("thumbnail", ""),
+ "filename": job.get("filename", ""), + "filename": job.get("filename", ""),
+ "file": job.get("file", ""), + "file": job.get("file", ""),
+ "transcript": job.get("transcript") or "", + "transcript": job.get("transcript") or "",
@@ -68,11 +70,49 @@ index 2b5eaa5..3c3c9c8 100644
+ "date": time.strftime("%Y-%m-%d %H:%M:%S"), + "date": time.strftime("%Y-%m-%d %H:%M:%S"),
+ }) + })
+ save_history(history[:200]) + 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): def parse_ytdlp_json(stdout):
"""Parse yt-dlp JSON output. """Parse yt-dlp JSON output.
@@ -29,6 +83,53 @@ def parse_ytdlp_json(stdout): @@ -29,6 +123,53 @@ def parse_ytdlp_json(stdout):
raise ValueError("yt-dlp returned no data") raise ValueError("yt-dlp returned no data")
@@ -126,7 +166,7 @@ index 2b5eaa5..3c3c9c8 100644
def run_download(job_id, url, format_choice, format_id): def run_download(job_id, url, format_choice, format_id):
job = jobs[job_id] job = jobs[job_id]
out_template = os.path.join(DOWNLOAD_DIR, f"{job_id}.%(ext)s") out_template = os.path.join(DOWNLOAD_DIR, f"{job_id}.%(ext)s")
@@ -81,6 +182,12 @@ def run_download(job_id, url, format_choice, format_id): @@ -81,6 +222,12 @@ def run_download(job_id, url, format_choice, format_id):
job["filename"] = f"{safe_title}{ext}" if safe_title else os.path.basename(chosen) job["filename"] = f"{safe_title}{ext}" if safe_title else os.path.basename(chosen)
else: else:
job["filename"] = os.path.basename(chosen) job["filename"] = os.path.basename(chosen)
@@ -139,16 +179,17 @@ index 2b5eaa5..3c3c9c8 100644
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
job["status"] = "error" job["status"] = "error"
job["error"] = "Download timed out (5 min limit)" job["error"] = "Download timed out (5 min limit)"
@@ -175,7 +282,7 @@ def start_download(): @@ -175,7 +322,8 @@ def start_download():
return jsonify({"error": "No URL provided"}), 400 return jsonify({"error": "No URL provided"}), 400
job_id = uuid.uuid4().hex[:10] job_id = uuid.uuid4().hex[:10]
- jobs[job_id] = {"status": "downloading", "url": url, "title": title} - jobs[job_id] = {"status": "downloading", "url": url, "title": title}
+ 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 = threading.Thread(target=run_download, args=(job_id, url, format_choice, format_id))
thread.daemon = True thread.daemon = True
@@ -184,6 +291,18 @@ def start_download(): @@ -184,6 +332,18 @@ def start_download():
return jsonify({"job_id": job_id}) return jsonify({"job_id": job_id})
@@ -167,7 +208,7 @@ index 2b5eaa5..3c3c9c8 100644
@app.route("/api/status/<job_id>") @app.route("/api/status/<job_id>")
def check_status(job_id): def check_status(job_id):
job = jobs.get(job_id) job = jobs.get(job_id)
@@ -193,15 +312,48 @@ def check_status(job_id): @@ -193,15 +353,48 @@ def check_status(job_id):
"status": job["status"], "status": job["status"],
"error": job.get("error"), "error": job.get("error"),
"filename": job.get("filename"), "filename": job.get("filename"),
@@ -221,54 +262,29 @@ index 2b5eaa5..3c3c9c8 100644
if __name__ == "__main__": if __name__ == "__main__":
diff --git a/templates/index.html b/templates/index.html diff --git a/templates/index.html b/templates/index.html
index 1f566d1..9017db6 100644 index 1f566d1..4807aa1 100644
--- a/templates/index.html --- a/templates/index.html
+++ b/templates/index.html +++ b/templates/index.html
@@ -343,6 +343,43 @@ @@ -343,6 +343,18 @@
.dl-all-btn:hover { background: #2d2d2a; } .dl-all-btn:hover { background: #2d2d2a; }
.dl-all-btn:disabled { opacity: 0.4; cursor: not-allowed; } .dl-all-btn:disabled { opacity: 0.4; cursor: not-allowed; }
+ /* History */ + /* History — same card language as the fetch results */
+ .hist-h { + .hist-h {
+ font-family: 'Instrument Serif', serif; + font-family: 'Instrument Serif', serif;
+ font-size: 1.4rem; + font-size: 1.9rem;
+ font-weight: 400; + font-weight: 400;
+ margin: 32px 0 10px; + letter-spacing: -0.02em;
+ margin: 44px 0 14px;
+ color: var(--fg); + color: var(--fg);
+ } + }
+ .hist-row { + #history .card { animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
+ display: flex;
+ gap: 10px;
+ align-items: center;
+ border: 1.5px solid var(--card-border);
+ border-radius: 10px;
+ background: var(--card);
+ padding: 10px 12px;
+ margin-bottom: 6px;
+ }
+ .hist-main { flex: 1; min-width: 0; }
+ .hist-title {
+ font-size: 0.8rem;
+ color: var(--fg);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+ .hist-meta {
+ font-size: 0.65rem;
+ color: var(--muted);
+ text-transform: uppercase;
+ letter-spacing: 0.03em;
+ margin-top: 2px;
+ }
+ .hist-meta .t-flag { color: var(--success); }
+ .hist-actions { display: flex; gap: 6px; }
+ a.card-dl-btn { text-decoration: none; display: inline-block; } + a.card-dl-btn { text-decoration: none; display: inline-block; }
+ +
.spin { .spin {
display: inline-block; display: inline-block;
width: 10px; height: 10px; width: 10px; height: 10px;
@@ -399,6 +436,7 @@ @@ -399,6 +411,7 @@
</div> </div>
<div id="cards" class="cards"></div> <div id="cards" class="cards"></div>
@@ -276,7 +292,7 @@ index 1f566d1..9017db6 100644
<div class="footer"> <div class="footer">
YouTube &middot; TikTok &middot; Instagram &middot; Twitter/X &middot; Reddit &middot; Facebook<br> YouTube &middot; TikTok &middot; Instagram &middot; Twitter/X &middot; Reddit &middot; Facebook<br>
@@ -586,8 +624,9 @@ @@ -586,8 +599,9 @@
} else if (c.status === 'downloading') { } else if (c.status === 'downloading') {
actionHtml = `<span class="card-status downloading"><span class="spin"></span> Downloading...</span>`; actionHtml = `<span class="card-status downloading"><span class="spin"></span> Downloading...</span>`;
} else if (c.status === 'done') { } else if (c.status === 'done') {
@@ -288,7 +304,15 @@ index 1f566d1..9017db6 100644
} else if (c.status === 'error') { } else if (c.status === 'error') {
actionHtml = `<button class="card-dl-btn" onclick="dlCard(${idx})">Retry</button> actionHtml = `<button class="card-dl-btn" onclick="dlCard(${idx})">Retry</button>
<span class="card-status error">${esc(friendlyError(c.error || 'Download failed'))}</span>`; <span class="card-status error">${esc(friendlyError(c.error || 'Download failed'))}</span>`;
@@ -662,8 +701,10 @@ @@ -634,6 +648,7 @@
format: currentFormat,
format_id: c.selectedFormatId,
title: c.title || '',
+ thumbnail: c.thumbnail || '',
}),
});
const data = await res.json();
@@ -662,8 +677,10 @@
clearInterval(iv); clearInterval(iv);
c.status = 'done'; c.status = 'done';
c.filename = data.filename; c.filename = data.filename;
@@ -299,7 +323,7 @@ index 1f566d1..9017db6 100644
} else if (data.status === 'error') { } else if (data.status === 'error') {
clearInterval(iv); clearInterval(iv);
c.status = 'error'; c.status = 'error';
@@ -688,6 +729,15 @@ @@ -688,6 +705,15 @@
a.click(); a.click();
} }
@@ -315,7 +339,7 @@ index 1f566d1..9017db6 100644
async function dlAll() { async function dlAll() {
const btn = document.querySelector('.dl-all-btn'); const btn = document.querySelector('.dl-all-btn');
if (btn) { btn.disabled = true; btn.textContent = 'Downloading...'; } if (btn) { btn.disabled = true; btn.textContent = 'Downloading...'; }
@@ -700,6 +750,35 @@ @@ -700,6 +726,47 @@
if (btn) { btn.disabled = false; btn.textContent = 'Download All'; } if (btn) { btn.disabled = false; btn.textContent = 'Download All'; }
} }
@@ -332,17 +356,29 @@ index 1f566d1..9017db6 100644
+ const rows = await res.json(); + const rows = await res.json();
+ const box = document.getElementById('history'); + const box = document.getElementById('history');
+ if (!Array.isArray(rows) || !rows.length) return; + if (!Array.isArray(rows) || !rows.length) return;
+ const items = rows.map(r => ` + const items = rows.map(r => {
+ <div class="hist-row"> + let thumbHtml;
+ <div class="hist-main"> + if (r.thumbnail) {
+ <div class="hist-title">${esc(r.title || r.filename || r.url || '')}</div> + thumbHtml = `<img src="${r.thumbnail}" alt="">`;
+ <div class="hist-meta">${esc(r.date || '')}${r.size ? ' · ' + fmtSize(r.size) : ''} · ${r.has_transcript ? '<span class="t-flag">transcript ✓</span>' : 'no transcript'}</div> + } else {
+ thumbHtml = `<div class="no-thumb"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="2" width="20" height="20" rx="2"/><circle cx="8" cy="8" r="1.5"/><path d="m21 15-5-5L5 21"/></svg></div>`;
+ }
+ const flag = r.has_transcript
+ ? `<span class="card-status done">transcript ✓</span>`
+ : `<span class="card-status">no transcript</span>`;
+ return `
+ <div class="card">
+ <div class="card-thumb">${thumbHtml}</div>
+ <div class="card-body">
+ <div class="card-title">${esc(r.title || r.filename || r.url || 'Untitled')}</div>
+ <div class="card-meta">${esc(r.date || '')}${r.size ? ' · ' + fmtSize(r.size) : ''} · <span class="${r.has_transcript ? 'card-status done' : ''}">${r.has_transcript ? 'transcript ✓' : 'no transcript'}</span></div>
+ <div class="card-actions">
+ <a class="card-dl-btn" href="/api/file/${r.job_id}" download>Save</a>
+ ${r.has_transcript ? `<a class="card-dl-btn" href="/api/transcript/${r.job_id}" download>Transcript</a>` : ''}
+ </div>
+ </div> + </div>
+ <div class="hist-actions"> + </div>`;
+ <a class="card-dl-btn" href="/api/file/${r.job_id}" download>${esc(r.filename || 'Save').replace(/\.[^.]+$/, '')}</a> + }).join('');
+ ${r.has_transcript ? `<a class="card-dl-btn" href="/api/transcript/${r.job_id}" download>Transcript</a>` : ''}
+ </div>
+ </div>`).join('');
+ box.innerHTML = `<h2 class="hist-h">History</h2>${items}`; + box.innerHTML = `<h2 class="hist-h">History</h2>${items}`;
+ } catch { /* history unavailable */ } + } catch { /* history unavailable */ }
+ } + }