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-08-01 08:55:52 +00:00
|
|
|
const channelData = await metadata.getChannel(data.authorId)
|
|
|
|
|
|
|
|
const uploaderAvatar = await upload.uploadImage(data.authorId, channelData.authorThumbnails[1].url)
|
2023-08-02 14:51:41 +00:00
|
|
|
const thumbnailUrl = await upload.uploadImage(id, data.videoThumbnails[0].url)
|
2023-03-03 16:44:40 +00:00
|
|
|
|
|
|
|
await prisma.videos.create({
|
|
|
|
data: {
|
|
|
|
id: id,
|
|
|
|
title: data.title,
|
2023-08-01 08:55:52 +00:00
|
|
|
description: (data.descriptionHtml).replaceAll('\n', '<br>'),
|
2023-03-03 16:44:40 +00:00
|
|
|
thumbnail: thumbnailUrl,
|
|
|
|
source: videoUrl,
|
2023-08-01 08:55:52 +00:00
|
|
|
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),
|
2023-08-01 08:55:52 +00:00
|
|
|
channel: channelData.author,
|
|
|
|
channelId: channelData.authorId,
|
2023-03-03 16:44:40 +00:00
|
|
|
channelAvatar: uploaderAvatar,
|
2023-08-01 08:55:52 +00:00
|
|
|
channelVerified: channelData.authorVerified,
|
2023-03-10 14:20:56 +00:00
|
|
|
playlist: playlistId
|
2023-03-03 16:44:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { createDatabaseVideo }
|