maybe no memory leak this time?

This commit is contained in:
unknown 2023-03-28 18:41:40 +02:00
parent f79e49053d
commit 8ec961ca38
1 changed files with 33 additions and 29 deletions

View File

@ -16,7 +16,7 @@ const prisma = new PrismaClient()
const queue = new PQueue({ concurrency: 4 })
async function handleCheck() {
async function check() {
const channels = await prisma.autodownload.findMany()
for (c of channels) {
@ -24,13 +24,13 @@ async function handleCheck() {
logger.info({ message: `${c.channel} is already being downloaded` })
} else {
await redis.set(c.channel, 'downloading')
await handleDownload(c.channel)
await checkChannel(c.channel)
await redis.del(c.channel)
}
}
}
async function handleDownload(channelId) {
async function checkChannel(channelId) {
logger.info({ message: `Checking ${channelId} for new videos...` })
const videos = await metadata.getChannelVideos(channelId)
@ -65,6 +65,12 @@ async function handleDownload(channelId) {
logger.info({ message: `Added ${video.title} to the queue, ${id}` })
queue.add(async () => {
await downloadVideo(video, id)
})
})
}
async function downloadVideo(video, id) {
logger.info({ message: `Starting to download ${video.title}, ${id}` })
const download = await ytdlp.downloadVideo('https://www.youtube.com' + video.url)
@ -89,11 +95,9 @@ async function handleDownload(channelId) {
logger.info({ message: `Couldn't find file for ${video.title}, ${id}` })
}
}
})
})
}
handleCheck()
check()
// setInterval(() => {
// handleCheck()
// check()
// }, 300000)