backend/utils/websocket.js

34 lines
1.2 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.authorId)
const uploaderAvatar = await upload.uploadImage(data.authorId, channelData.authorThumbnails[1].url)
const thumbnailUrl = await upload.uploadImage(id, data.videoThumbnails.find(o => o.quality == 'maxresdefault').url)
2023-03-03 16:44:40 +00:00
await prisma.videos.create({
data: {
id: id,
title: data.title,
description: (data.descriptionHtml).replaceAll('\n', '<br>'),
2023-03-03 16:44:40 +00:00
thumbnail: thumbnailUrl,
source: videoUrl,
published: (new Date(data.published*1000)).toISOString().slice(0,10),
2023-03-03 16:44:40 +00:00
archived: (new Date()).toISOString().slice(0,10),
channel: channelData.author,
channelId: channelData.authorId,
2023-03-03 16:44:40 +00:00
channelAvatar: uploaderAvatar,
channelVerified: channelData.authorVerified,
playlist: playlistId
2023-03-03 16:44:40 +00:00
}
})
return true
}
module.exports = { createDatabaseVideo }