Add like count to videos

Same pattern as view_count: model column, yt-dlp extraction, SQL select,
VideoDetail field, startup migration, and display in Watch meta row.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mattias Tall
2026-05-26 11:25:44 +02:00
parent ffd46b5e08
commit 3f225e7647
5 changed files with 6 additions and 1 deletions

View File

@@ -84,6 +84,7 @@ def init_db():
try:
# Column migrations — safe to run on every startup
_add_column_if_missing(raw_conn, "videos", "view_count", "INTEGER")
_add_column_if_missing(raw_conn, "videos", "like_count", "INTEGER")
raw_conn.commit()
# executescript handles multi-statement SQL including trigger BEGIN...END blocks
raw_conn.executescript(FTS_SETUP_SQL)

View File

@@ -61,6 +61,7 @@ class Video(Base):
category = Column(String)
chapters = Column(Text) # JSON array of {start_time, end_time, title}
view_count = Column(Integer)
like_count = Column(Integer)
class UserVideo(Base):

View File

@@ -66,6 +66,7 @@ class VideoDetail(BaseModel):
local_file_url: Optional[str] = None
is_recommended: bool = False
view_count: Optional[int] = None
like_count: Optional[int] = None
model_config = {"from_attributes": True}
@@ -422,7 +423,7 @@ def surprise_me(
_VIDEO_SELECT = """
SELECT v.id, v.youtube_video_id, v.title, v.description, v.thumbnail_url,
v.duration_seconds, v.published_at, v.tags, v.category, v.view_count,
v.duration_seconds, v.published_at, v.tags, v.category, v.view_count, v.like_count,
c.id AS channel_id, c.name AS channel_name, c.youtube_channel_id AS channel_youtube_id,
COALESCE(uv.watched, 0) AS watched,
COALESCE(uv.watch_progress_seconds, 0) AS watch_progress_seconds,

View File

@@ -75,6 +75,7 @@ def _normalize_video(info: dict) -> dict:
"category": info.get("category") or (info.get("categories") or [None])[0],
"chapters": json.dumps(chapters) if chapters else None,
"view_count": info.get("view_count"),
"like_count": info.get("like_count"),
"channel": {
"youtube_channel_id": info.get("channel_id"),
"name": info.get("channel") or info.get("uploader", ""),

View File

@@ -894,6 +894,7 @@ export default function Watch() {
<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?.like_count > 0 && <><span>·</span><span>👍 {formatViews(video.like_count).replace(" views", "")}</span></>}
{video?.category && <><span>·</span><span>{video.category}</span></>}
{video?.duration_seconds && (
<><span>·</span>