From f31dad0215a7898c98cadbe94686de5dc53f17b0 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sun, 30 Aug 2020 05:56:25 -0400 Subject: [PATCH] JSON metadata files are no longer kept if the associated setting is not enabled --- backend/db.js | 13 ++++++++----- backend/utils.js | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/db.js b/backend/db.js index dd0d0944..c46cfd84 100644 --- a/backend/db.js +++ b/backend/db.js @@ -26,10 +26,7 @@ function registerFileDB(file_path, type, multiUserMode = null, sub = null) { utils.fixVideoMetadataPerms(file_id, type, multiUserMode && multiUserMode.file_path); - // add additional info - file_object['uid'] = uuid(); - file_object['registered'] = Date.now(); - file_object['path'] = path.format(path.parse(file_object['path'])); + // add thumbnail path file_object['thumbnailPath'] = utils.getDownloadedThumbnail(file_id, type, multiUserMode && multiUserMode.file_path); if (!sub) { @@ -48,7 +45,13 @@ function registerFileDB(file_path, type, multiUserMode = null, sub = null) { } } - const file_uid = registerFileDBManual(db_path, file_object) + const file_uid = registerFileDBManual(db_path, file_object); + + // remove metadata JSON if needed + if (!config_api.getConfigItem('ytdl_include_metadata')) { + utils.deleteJSONFile(file_id, type, multiUserMode && multiUserMode.file_path) + } + return file_uid; } diff --git a/backend/utils.js b/backend/utils.js index d2e2a5e7..efedb3b7 100644 --- a/backend/utils.js +++ b/backend/utils.js @@ -119,7 +119,7 @@ function getExpectedFileSize(info_json) { } }); }); - + return expected_filesize; } @@ -145,6 +145,19 @@ function fixVideoMetadataPerms(name, type, customPath = null) { } } +function deleteJSONFile(name, type, customPath = null) { + if (!customPath) customPath = type === 'audio' ? config_api.getConfigItem('ytdl_audio_folder_path') + : config_api.getConfigItem('ytdl_video_folder_path'); + + const ext = type === 'audio' ? '.mp3' : '.mp4'; + let json_path = path.join(customPath, name + '.info.json'); + let alternate_json_path = path.join(customPath, name + ext + '.info.json'); + + if (fs.existsSync(json_path)) fs.unlinkSync(json_path); + if (fs.existsSync(alternate_json_path)) fs.unlinkSync(alternate_json_path); +} + + function recFindByExt(base,ext,files,result) { files = files || fs.readdirSync(base) @@ -191,6 +204,7 @@ module.exports = { getDownloadedThumbnail: getDownloadedThumbnail, getExpectedFileSize: getExpectedFileSize, fixVideoMetadataPerms: fixVideoMetadataPerms, + deleteJSONFile: deleteJSONFile, getDownloadedFilesByType: getDownloadedFilesByType, recFindByExt: recFindByExt, File: File