update to match new metadata returned data

This commit is contained in:
localhost 2026-05-24 18:51:01 +02:00
parent 642ee484ae
commit 8eeee8cbff
3 changed files with 23 additions and 22 deletions

View File

@ -3,7 +3,6 @@ import DOMPurify from 'isomorphic-dompurify'
import { db } from '@/utils/database' import { db } from '@/utils/database'
import { getChannel, getChannelVideos } from '@/utils/metadata'; import { getChannel, getChannelVideos } from '@/utils/metadata';
import { convertRelativeToDate } from '@/utils/common';
import { m, eta, error } from '@/utils/html' import { m, eta, error } from '@/utils/html'
import redis from '@/utils/redis'; import redis from '@/utils/redis';
@ -189,10 +188,12 @@ app.get('/channel/:id', async ({ params: { id }, set }) => {
.execute() .execute()
const processedVideos: processedVideo[] = videos.map((video: any) => ({ // it would be impossible to set types for youtube output... they change it every day. 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, id: video.videoId,
title: video.title.text, title: video.title,
thumbnail: video.thumbnails[0].url, thumbnail: video.thumbnails?.[0]?.url || video.videoThumbnails?.[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) published: video.published
? new Date(video.published).toISOString().slice(0, 10)
: video.publishedText || ''
})) }))
archived.forEach(v => { archived.forEach(v => {

View File

@ -280,11 +280,11 @@ app.ws('/savechannel', {
} }
for (const video of videos.slice(0, 5)) { 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') const already = await db.selectFrom('videos')
.select('id') .select('id')
.where('id', '=', video.video_id) .where('id', '=', video.videoId)
.executeTakeFirst() .executeTakeFirst()
if (already) continue if (already) continue
@ -298,10 +298,10 @@ app.ws('/savechannel', {
break; 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, const isSlop = await parseSlop(video.videoId, video.title,
video.description_snippet?.text || '', channelId) video.description || video.description_snippet?.text || '', channelId)
if (isSlop) { if (isSlop) {
sendError(ws, 'Filters can always be wrong. Is the rating wrong? Email me at admin@preservetube.com<br>', false); sendError(ws, 'Filters can always be wrong. Is the rating wrong? Email me at admin@preservetube.com<br>', false);
@ -310,24 +310,24 @@ app.ws('/savechannel', {
continue; continue;
} }
ws.send(`DATA - Processing video: ${video.title.text}`); ws.send(`DATA - Processing video: ${video.title}`);
await redis.set(saveKey(video.video_id), 'downloading', 'EX', 300); 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) { if (!downloadResult.fail) {
const mbsUsed = Math.ceil(downloadResult.size / (1024 * 1024)) const mbsUsed = Math.ceil(downloadResult.size / (1024 * 1024))
const limitStatus = await checkMbLimit(subjects, mbsUsed) const limitStatus = await checkMbLimit(subjects, mbsUsed)
if (limitStatus.isLimited) { 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) if (file) fs.unlinkSync('./videos/' + file)
sendError(ws, limitStatus.isNewVisitorLimited ? NEW_VISITOR_STORAGE_LIMIT_MESSAGE : DEFAULT_STORAGE_LIMIT_MESSAGE, false); sendError(ws, limitStatus.isNewVisitorLimited ? NEW_VISITOR_STORAGE_LIMIT_MESSAGE : DEFAULT_STORAGE_LIMIT_MESSAGE, false);
break; break;
} }
await handleUpload(ws, video.video_id, true); await handleUpload(ws, video.videoId, true);
} }
await redis.del(saveKey(video.video_id)); await redis.del(saveKey(video.videoId));
ws.send(`DATA - Created video page for ${video.title.text}`) ws.send(`DATA - Created video page for ${video.title}`)
} }
await cleanup(ws, channelId); await cleanup(ws, channelId);

View File

@ -59,7 +59,7 @@ async function createDatabaseVideo(id: string, videoUrl: string) {
if (data.error) return data if (data.error) return data
if (channelData.error) return channelData 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) const thumbnailUrl = await uploadImage(id, data.microformat.playerMicroformatRenderer.thumbnail.thumbnails[0].url)
await db.insertInto('videos') await db.insertInto('videos')
@ -72,9 +72,9 @@ async function createDatabaseVideo(id: string, videoUrl: string) {
source: videoUrl, source: videoUrl,
published: data.microformat.playerMicroformatRenderer.publishDate.slice(0, 10), published: data.microformat.playerMicroformatRenderer.publishDate.slice(0, 10),
archived: (new Date()).toISOString().slice(0, 10), archived: (new Date()).toISOString().slice(0, 10),
channel: channelData.metadata.title, channel: channelData.author,
channelId: channelData.metadata.external_id, channelId: channelData.authorId,
channelVerified: channelData.header.author?.is_verified || false, channelVerified: channelData.authorVerified || false,
channelAvatar: uploaderAvatar, channelAvatar: uploaderAvatar,
disabled: false, disabled: false,
hasBeenReported: false hasBeenReported: false
@ -84,4 +84,4 @@ async function createDatabaseVideo(id: string, videoUrl: string) {
return 'success' return 'success'
} }
export { convertRelativeToDate, checkCaptcha, createDatabaseVideo } export { convertRelativeToDate, checkCaptcha, createDatabaseVideo }