From 5b0e27465b212a6c8a6c9d79923020035c33c0fe Mon Sep 17 00:00:00 2001 From: alikia2x Date: Sun, 2 Mar 2025 02:54:30 +0800 Subject: [PATCH] update: author_info in classification --- lib/db/allData.ts | 19 +++++++++++++++---- lib/db/schema.d.ts | 11 +++++++++++ lib/mq/exec/classifyVideo.ts | 2 +- lib/mq/task/getVideoInfo.ts | 6 ++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/db/allData.ts b/lib/db/allData.ts index 701c112..4cbdeb0 100644 --- a/lib/db/allData.ts +++ b/lib/db/allData.ts @@ -1,6 +1,6 @@ -import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts"; -import { AllDataType } from "lib/db/schema.d.ts"; -import { modelVersion } from "lib/ml/filter_inference.ts"; +import {Client} from "https://deno.land/x/postgres@v0.19.3/mod.ts"; +import {AllDataType, BiliUserType} from "lib/db/schema.d.ts"; +import {modelVersion} from "lib/ml/filter_inference.ts"; export async function videoExistsInAllData(client: Client, aid: number) { return await client.queryObject<{ exists: boolean }>(`SELECT EXISTS(SELECT 1 FROM all_data WHERE aid = $1)`, [aid]) @@ -30,5 +30,16 @@ export async function getVideoInfoFromAllData(client: Client, aid: number) { `SELECT * FROM all_data WHERE aid = $1`, [aid], ); - return queryResult.rows[0]; + const row = queryResult.rows[0]; + const q = await client.queryObject( + `SELECT * FROM bili_user WHERE uid = $1`, + [row.uid], + ) + const userRow = q.rows[0]; + return { + title: row.title, + description: row.description, + tags: row.tags, + author_info: userRow.desc + }; } diff --git a/lib/db/schema.d.ts b/lib/db/schema.d.ts index 068f084..3c02c3f 100644 --- a/lib/db/schema.d.ts +++ b/lib/db/schema.d.ts @@ -1,4 +1,5 @@ export interface AllDataType { + id: number; aid: number; bvid: string | null; description: string | null; @@ -6,4 +7,14 @@ export interface AllDataType { tags: string | null; title: string | null; published_at: string | null; + duration: number; + created_at: string | null; +} + +export interface BiliUserType { + id: number; + uid: number; + username: string; + desc: string; + fans: number; } diff --git a/lib/mq/exec/classifyVideo.ts b/lib/mq/exec/classifyVideo.ts index bc7f362..fd29e8e 100644 --- a/lib/mq/exec/classifyVideo.ts +++ b/lib/mq/exec/classifyVideo.ts @@ -17,7 +17,7 @@ export const classifyVideoWorker = async (job: Job) => { const title = videoInfo.title?.trim() || "untitled"; const description = videoInfo.description?.trim() || "N/A"; const tags = videoInfo.tags?.trim() || "empty"; - const authorInfo = "No"; + const authorInfo = videoInfo.author_info; const label = await classifyVideo(title, description, tags, authorInfo, aid); if (label == -1) { logger.warn(`Failed to classify video ${aid}`, "ml"); diff --git a/lib/mq/task/getVideoInfo.ts b/lib/mq/task/getVideoInfo.ts index 4d1c615..3a49628 100644 --- a/lib/mq/task/getVideoInfo.ts +++ b/lib/mq/task/getVideoInfo.ts @@ -35,6 +35,12 @@ export async function insertVideoInfo(client: Client, aid: number) { [uid, data.View.owner.name, data.Card.card.sign, data.Card.follower], ); } + else { + await client.queryObject( + `UPDATE bili_user SET fans = $1 WHERE uid = $2`, + [data.Card.follower, uid], + ); + } logger.log(`Inserted video metadata for aid: ${aid}`, "mq"); await ClassifyVideoQueue.add("classifyVideo", { aid }); }