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')
|
|
|
|
|
2023-03-10 14:20:56 +00:00
|
|
|
async function createDatabaseVideo(id, videoUrl, playlistId) {
|
2023-03-24 14:20:06 +00:00
|
|
|
const data = await metadata.getVideoMetadata(id)
|
2023-03-03 16:44:40 +00:00
|
|
|
const uploaderAvatar = await upload.uploadImage((data.uploaderUrl).replace('/channel/', ''), data.uploaderAvatar)
|
|
|
|
const thumbnailUrl = await upload.uploadImage(id, data.thumbnailUrl)
|
|
|
|
|
|
|
|
await prisma.videos.create({
|
|
|
|
data: {
|
|
|
|
id: id,
|
|
|
|
title: data.title,
|
|
|
|
description: data.description,
|
|
|
|
thumbnail: thumbnailUrl,
|
|
|
|
source: videoUrl,
|
|
|
|
published: data.uploadDate,
|
|
|
|
archived: (new Date()).toISOString().slice(0,10),
|
|
|
|
channel: data.uploader,
|
|
|
|
channelId: (data.uploaderUrl).replace('/channel/', ''),
|
|
|
|
channelAvatar: uploaderAvatar,
|
2023-03-10 14:20:56 +00:00
|
|
|
channelVerified: data.uploaderVerified,
|
|
|
|
playlist: playlistId
|
2023-03-03 16:44:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { createDatabaseVideo }
|