mirror of https://github.com/preservetube/auto.git
				
				
				
			maybe no memory leak this time?
This commit is contained in:
		
							parent
							
								
									f79e49053d
								
							
						
					
					
						commit
						8ec961ca38
					
				
							
								
								
									
										18
									
								
								index.js
								
								
								
								
							
							
						
						
									
										18
									
								
								index.js
								
								
								
								
							| 
						 | 
					@ -16,7 +16,7 @@ const prisma = new PrismaClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const queue = new PQueue({ concurrency: 4 })
 | 
					const queue = new PQueue({ concurrency: 4 })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function handleCheck() {
 | 
					async function check() {
 | 
				
			||||||
    const channels = await prisma.autodownload.findMany()
 | 
					    const channels = await prisma.autodownload.findMany()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (c of channels) {
 | 
					    for (c of channels) {
 | 
				
			||||||
| 
						 | 
					@ -24,13 +24,13 @@ async function handleCheck() {
 | 
				
			||||||
            logger.info({ message: `${c.channel} is already being downloaded` })
 | 
					            logger.info({ message: `${c.channel} is already being downloaded` })
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            await redis.set(c.channel, 'downloading')
 | 
					            await redis.set(c.channel, 'downloading')
 | 
				
			||||||
            await handleDownload(c.channel)
 | 
					            await checkChannel(c.channel)
 | 
				
			||||||
            await redis.del(c.channel)
 | 
					            await redis.del(c.channel)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function handleDownload(channelId) {
 | 
					async function checkChannel(channelId) {
 | 
				
			||||||
    logger.info({ message: `Checking ${channelId} for new videos...` })
 | 
					    logger.info({ message: `Checking ${channelId} for new videos...` })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const videos = await metadata.getChannelVideos(channelId)
 | 
					    const videos = await metadata.getChannelVideos(channelId)
 | 
				
			||||||
| 
						 | 
					@ -65,6 +65,12 @@ async function handleDownload(channelId) {
 | 
				
			||||||
        logger.info({ message: `Added ${video.title} to the queue, ${id}` })
 | 
					        logger.info({ message: `Added ${video.title} to the queue, ${id}` })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        queue.add(async () => {
 | 
					        queue.add(async () => {
 | 
				
			||||||
 | 
					            await downloadVideo(video, id)
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function downloadVideo(video, id) {
 | 
				
			||||||
    logger.info({ message: `Starting to download ${video.title}, ${id}` })
 | 
					    logger.info({ message: `Starting to download ${video.title}, ${id}` })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const download = await ytdlp.downloadVideo('https://www.youtube.com' + video.url)
 | 
					    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}` })
 | 
					            logger.info({ message: `Couldn't find file for ${video.title}, ${id}` })
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
handleCheck()
 | 
					check()
 | 
				
			||||||
// setInterval(() => {
 | 
					// setInterval(() => {
 | 
				
			||||||
//     handleCheck()
 | 
					//     check()
 | 
				
			||||||
// }, 300000)
 | 
					// }, 300000)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue