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)
|
2024-03-30 10:11:49 +00:00
|
|
|
const channelData = await metadata.getChannel(data.basic_info.channel_id)
|
2023-08-01 08:55:52 +00:00
|
|
|
|
2024-03-30 10:11:49 +00:00
|
|
|
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,
|
2024-03-30 10:11:49 +00:00
|
|
|
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,
|
2024-03-30 10:11:49 +00:00
|
|
|
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),
|
2024-03-30 10:11:49 +00:00
|
|
|
channel: channelData.metadata.title,
|
|
|
|
channelId: channelData.metadata.external_id,
|
2023-03-03 16:44:40 +00:00
|
|
|
channelAvatar: uploaderAvatar,
|
2024-03-30 10:11:49 +00:00
|
|
|
channelVerified: channelData.header.author.is_verified,
|
2023-03-10 14:20:56 +00:00
|
|
|
playlist: playlistId
|
2023-03-03 16:44:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { createDatabaseVideo }
|