Add view count to videos

- Video model: view_count column (Integer, nullable)
- ytdlp._normalize_video: extract view_count from yt-dlp info
- _VIDEO_SELECT: include v.view_count in all queries
- VideoDetail schema: view_count field
- Watch page: formatViews() helper, show "X.XM views" in meta row
  alongside date and category

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mattias Tall
2026-05-26 11:18:53 +02:00
parent cdf6520fd8
commit 8221177615
4 changed files with 13 additions and 1 deletions

View File

@@ -27,6 +27,14 @@ function formatDate(s) {
return new Date(s).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" });
}
function formatViews(n) {
if (!n) return null;
if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(1)}B views`;
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 100_000_000 ? 0 : 1)}M views`;
if (n >= 1_000) return `${Math.round(n / 1_000)}K views`;
return `${n} views`;
}
function formatSubs(n) {
if (!n) return null;
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`;
@@ -885,6 +893,7 @@ export default function Watch() {
<div className="flex items-center justify-between flex-wrap gap-3">
<div className="flex items-center gap-2 text-sm text-zinc-500 flex-wrap">
{date && <span>{date}</span>}
{video?.view_count > 0 && <><span>·</span><span>{formatViews(video.view_count)}</span></>}
{video?.category && <><span>·</span><span>{video.category}</span></>}
{video?.duration_seconds && (
<><span>·</span>