adding videos to redis as downloading when its their time in queue, not before

This commit is contained in:
localhost 2023-10-04 19:54:14 +02:00
parent 44832e36ee
commit a2b437a752
1 changed files with 6 additions and 1 deletions

View File

@ -82,7 +82,6 @@ async function checkChannel(channelId) {
return return
} }
await redis.set(id, 'downloading')
logger.info({ message: `Added ${video.title} to the queue, ${id}` }) logger.info({ message: `Added ${video.title} to the queue, ${id}` })
queue.createJob({ video, id }).save() queue.createJob({ video, id }).save()
@ -92,7 +91,13 @@ async function checkChannel(channelId) {
queue.process(1, async function (job, done) { queue.process(1, async function (job, done) {
const { video, id } = job.data const { video, id } = job.data
if (await redis.get(id)) {
logger.info({ message: `Someone is already downloading ${video.title}, ${id}` })
return done()
}
logger.info({ message: `Starting to download ${video.title}, ${id}` }) logger.info({ message: `Starting to download ${video.title}, ${id}` })
await redis.set(id, 'downloading')
const download = await ytdlp.downloadVideo('https://www.youtube.com' + video.url) const download = await ytdlp.downloadVideo('https://www.youtube.com' + video.url)
if (download.fail) { if (download.fail) {