From a8d6298cfd6151b487a27a499bf86dce1f21515d Mon Sep 17 00:00:00 2001 From: Isaac Grynsztein Date: Wed, 15 Apr 2020 02:01:25 -0400 Subject: [PATCH] Adds preliminary support for tiktok and periscope Added alternate json path for mp4s in case it's not found in the main location --- backend/app.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/app.js b/backend/app.js index 2f0e2e5..f159431 100644 --- a/backend/app.js +++ b/backend/app.js @@ -713,30 +713,37 @@ function getJSONMp3(name) { var jsonPath = audioFolderPath+name+".info.json"; var alternateJsonPath = audioFolderPath+name+".mp3.info.json"; + var obj = null; if (fs.existsSync(jsonPath)) - var obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); + obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); else if (fs.existsSync(alternateJsonPath)) - var obj = JSON.parse(fs.readFileSync(alternateJsonPath, 'utf8')); + obj = JSON.parse(fs.readFileSync(alternateJsonPath, 'utf8')); else - var obj = 0; + obj = 0; return obj; } function getJSONMp4(name, customPath = null) { + var obj = null; // output let jsonPath = null; + var alternateJsonPath = videoFolderPath + name + ".mp4.info.json"; if (!customPath) { - jsonPath = videoFolderPath+name+".info.json"; + jsonPath = videoFolderPath + name + ".info.json"; } else { jsonPath = customPath + name + ".info.json"; + alternateJsonPath = customPath + name + ".mp4.info.json"; } if (fs.existsSync(jsonPath)) { - var obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); + obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); return obj; + } else if (fs.existsSync(alternateJsonPath)) { + obj = JSON.parse(fs.readFileSync(alternateJsonPath, 'utf8')); } - else return 0; + else obj = 0; + return obj; } function getAmountDownloadedMp3(name) @@ -1005,7 +1012,7 @@ function generateFileObject(id, type) { var url = jsonobj.webpage_url; var uploader = jsonobj.uploader; var upload_date = jsonobj.upload_date; - upload_date = `${upload_date.substring(0, 4)}-${upload_date.substring(4, 6)}-${upload_date.substring(6, 8)}`; + upload_date = upload_date ? `${upload_date.substring(0, 4)}-${upload_date.substring(4, 6)}-${upload_date.substring(6, 8)}` : 'N/A'; var size = stats.size; @@ -1437,6 +1444,11 @@ app.post('/api/tomp4', async function(req, res) { let downloadConfig = null; let qualityPath = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'; + if (url.includes('tiktok') || url.includes('pscp.tv')) { + // tiktok videos fail when using the default format + qualityPath = 'best'; + } + if (customArgs) { downloadConfig = customArgs.split(' '); } else {