From 8eeee8cbff0d9b9ceabf3fa244572942c8f01ef3 Mon Sep 17 00:00:00 2001 From: localhost Date: Sun, 24 May 2026 18:51:01 +0200 Subject: [PATCH] update to match new metadata returned data --- src/router/video.ts | 11 ++++++----- src/router/websocket.ts | 24 ++++++++++++------------ src/utils/common.ts | 10 +++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/router/video.ts b/src/router/video.ts index 2acf9e3..3a3c0c5 100644 --- a/src/router/video.ts +++ b/src/router/video.ts @@ -3,7 +3,6 @@ import DOMPurify from 'isomorphic-dompurify' import { db } from '@/utils/database' import { getChannel, getChannelVideos } from '@/utils/metadata'; -import { convertRelativeToDate } from '@/utils/common'; import { m, eta, error } from '@/utils/html' import redis from '@/utils/redis'; @@ -189,10 +188,12 @@ app.get('/channel/:id', async ({ params: { id }, set }) => { .execute() const processedVideos: processedVideo[] = videos.map((video: any) => ({ // it would be impossible to set types for youtube output... they change it every day. - id: video.video_id, - title: video.title.text, - thumbnail: video.thumbnails[0].url, - published: video.upcoming?.slice(0, 10) || (video.published.text.endsWith('ago') ? convertRelativeToDate(video.published.text) : new Date(video.published.text)).toISOString().slice(0, 10) + id: video.videoId, + title: video.title, + thumbnail: video.thumbnails?.[0]?.url || video.videoThumbnails?.[0]?.url || '', + published: video.published + ? new Date(video.published).toISOString().slice(0, 10) + : video.publishedText || '' })) archived.forEach(v => { diff --git a/src/router/websocket.ts b/src/router/websocket.ts index cc6c693..b71caf6 100644 --- a/src/router/websocket.ts +++ b/src/router/websocket.ts @@ -280,11 +280,11 @@ app.ws('/savechannel', { } for (const video of videos.slice(0, 5)) { - if (!video || (await redis.get(saveKey(video.video_id))) || (await redis.get(`blacklist:${video.video_id}`))) continue; + if (!video || (await redis.get(saveKey(video.videoId))) || (await redis.get(`blacklist:${video.videoId}`))) continue; const already = await db.selectFrom('videos') .select('id') - .where('id', '=', video.video_id) + .where('id', '=', video.videoId) .executeTakeFirst() if (already) continue @@ -298,10 +298,10 @@ app.ws('/savechannel', { break; } - console.log(`saving (${subjects.map(subject => Bun.hash(subject).toString()).join(',')}) - ${ws.data.path} - ${video.video_id}`) + console.log(`saving (${subjects.map(subject => Bun.hash(subject).toString()).join(',')}) - ${ws.data.path} - ${video.videoId}`) - const isSlop = await parseSlop(video.video_id, video.title.text, - video.description_snippet?.text || '', channelId) + const isSlop = await parseSlop(video.videoId, video.title, + video.description || video.description_snippet?.text || '', channelId) if (isSlop) { sendError(ws, 'Filters can always be wrong. Is the rating wrong? Email me at admin@preservetube.com
', false); @@ -310,24 +310,24 @@ app.ws('/savechannel', { continue; } - ws.send(`DATA - Processing video: ${video.title.text}`); - await redis.set(saveKey(video.video_id), 'downloading', 'EX', 300); + ws.send(`DATA - Processing video: ${video.title}`); + await redis.set(saveKey(video.videoId), 'downloading', 'EX', 300); - const downloadResult = await downloadVideo(ws, video.video_id); + const downloadResult = await downloadVideo(ws, video.videoId); if (!downloadResult.fail) { const mbsUsed = Math.ceil(downloadResult.size / (1024 * 1024)) const limitStatus = await checkMbLimit(subjects, mbsUsed) if (limitStatus.isLimited) { - const file = fs.readdirSync('./videos/').find(f => f.includes(`${video.video_id}.`)) + const file = fs.readdirSync('./videos/').find(f => f.includes(`${video.videoId}.`)) if (file) fs.unlinkSync('./videos/' + file) sendError(ws, limitStatus.isNewVisitorLimited ? NEW_VISITOR_STORAGE_LIMIT_MESSAGE : DEFAULT_STORAGE_LIMIT_MESSAGE, false); break; } - await handleUpload(ws, video.video_id, true); + await handleUpload(ws, video.videoId, true); } - await redis.del(saveKey(video.video_id)); - ws.send(`DATA - Created video page for ${video.title.text}`) + await redis.del(saveKey(video.videoId)); + ws.send(`DATA - Created video page for ${video.title}`) } await cleanup(ws, channelId); diff --git a/src/utils/common.ts b/src/utils/common.ts index 47ea38f..534bf4e 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -59,7 +59,7 @@ async function createDatabaseVideo(id: string, videoUrl: string) { if (data.error) return data if (channelData.error) return channelData - const uploaderAvatar = await uploadImage(data.videoDetails.channelId, channelData.metadata.thumbnail[0].url) + const uploaderAvatar = await uploadImage(data.videoDetails.channelId, channelData.authorThumbnails[0].url) const thumbnailUrl = await uploadImage(id, data.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url) await db.insertInto('videos') @@ -72,9 +72,9 @@ async function createDatabaseVideo(id: string, videoUrl: string) { source: videoUrl, published: data.microformat.playerMicroformatRenderer.publishDate.slice(0, 10), archived: (new Date()).toISOString().slice(0, 10), - channel: channelData.metadata.title, - channelId: channelData.metadata.external_id, - channelVerified: channelData.header.author?.is_verified || false, + channel: channelData.author, + channelId: channelData.authorId, + channelVerified: channelData.authorVerified || false, channelAvatar: uploaderAvatar, disabled: false, hasBeenReported: false @@ -84,4 +84,4 @@ async function createDatabaseVideo(id: string, videoUrl: string) { return 'success' } -export { convertRelativeToDate, checkCaptcha, createDatabaseVideo } \ No newline at end of file +export { convertRelativeToDate, checkCaptcha, createDatabaseVideo }