backend/utils/websocket.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-03-03 16:44:40 +00:00
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
const metadata = require('./metadata.js')
const upload = require('./upload.js')
async function createDatabaseVideo(id, videoUrl, playlistId) {
2023-03-24 14:20:06 +00:00
const data = await metadata.getVideoMetadata(id)
const channelData = await metadata.getChannel(data.basic_info.channel_id)
if (data.error) return data
if (channelData.error) return channelData
const uploaderAvatar = await upload.uploadImage(data.basic_info.channel_id, channelData.metadata.thumbnail[0].url)
const thumbnailUrl = await upload.uploadImage(id, data.basic_info.thumbnail[0].url)
2023-03-03 16:44:40 +00:00
await prisma.videos.create({
data: {
id: id,
title: data.basic_info.title,
description: (data.basic_info.short_description).replaceAll('\n', '<br>'),
2023-03-03 16:44:40 +00:00
thumbnail: thumbnailUrl,
source: videoUrl,
published: (new Date(data.primary_info.published.text)).toISOString().slice(0,10),
2023-03-03 16:44:40 +00:00
archived: (new Date()).toISOString().slice(0,10),
channel: channelData.metadata.title,
channelId: channelData.metadata.external_id,
2023-03-03 16:44:40 +00:00
channelAvatar: uploaderAvatar,
channelVerified: channelData.header.author?.is_verified || false,
playlist: playlistId
2023-03-03 16:44:40 +00:00
}
})
2024-05-25 13:37:12 +00:00
return 'success'
2023-03-03 16:44:40 +00:00
}
module.exports = { createDatabaseVideo }