From ce2f294a3dc1bc99eb95918bf38bbcb78c22126c Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Fri, 20 Mar 2020 16:17:15 -0400 Subject: [PATCH] Removed potential race condition with youtube-dl archives in main downloader Fixed bug where downloaded subscriptions' zip files would include erroneous folders for their videos --- backend/app.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/app.js b/backend/app.js index 7c30a6b..5752fa9 100644 --- a/backend/app.js +++ b/backend/app.js @@ -393,8 +393,9 @@ async function createPlaylistZipFile(fileNames, type, outputName, fullPathProvid for (let i = 0; i < fileNames.length; i++) { let fileName = fileNames[i]; + let fileNamePathRemoved = path.parse(fileName).base; let file_path = !fullPathProvided ? zipFolderPath + fileName + ext : fileName; - archive.file(file_path, {name: fileName + ext}) + archive.file(file_path, {name: fileNamePathRemoved + ext}) } await archive.finalize(); @@ -744,6 +745,7 @@ app.post('/api/tomp3', async function(req, res) { let downloadConfig = null; let qualityPath = '-f bestaudio'; + let merged_path = null; let merged_string = null; if (customArgs) { @@ -788,7 +790,8 @@ app.post('/api/tomp3', async function(req, res) { fs.closeSync(fs.openSync(blacklist_path, 'w')); } - let merged_path = audioFolderPath + 'merged.txt'; + // creates merged folder + merged_path = audioFolderPath + `merged_${uuid()}.txt`; // merges blacklist and regular archive let inputPathList = [archive_path, blacklist_path]; let status = await mergeFiles(inputPathList, merged_path); @@ -853,9 +856,10 @@ app.post('/api/tomp3', async function(req, res) { let is_playlist = file_names.length > 1; if (merged_string !== null) { - let current_merged_archive = fs.readFileSync(audioFolderPath + 'merged.txt', 'utf8'); + let current_merged_archive = fs.readFileSync(merged_path, 'utf8'); let diff = current_merged_archive.replace(merged_string, ''); fs.appendFileSync(audioFolderPath + 'archive.txt', diff); + fs.unlinkSync(merged_path) } var audiopathEncoded = encodeURIComponent(file_names[0]);