Deleting a file will now delete its downloaded thumbnail as well

Thumbnails will now have their permissions auto updated to align themselves with the other downloaded files
This commit is contained in:
Isaac Grynsztein
2020-06-30 22:38:01 -04:00
parent efdc471ccf
commit 5537852134
4 changed files with 63 additions and 6 deletions

View File

@@ -27,10 +27,8 @@ function getJSONMp4(name, customPath, openReadPerms = false) {
if (fs.existsSync(jsonPath))
{
obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
if (openReadPerms) fs.chmodSync(jsonPath, 0o644);
} else if (fs.existsSync(alternateJsonPath)) {
obj = JSON.parse(fs.readFileSync(alternateJsonPath, 'utf8'));
if (openReadPerms) fs.chmodSync(alternateJsonPath, 0o644);
}
else obj = 0;
return obj;
@@ -43,11 +41,9 @@ function getJSONMp3(name, customPath, openReadPerms = false) {
var alternateJsonPath = path.join(customPath, name + ".mp3.info.json");
if (fs.existsSync(jsonPath)) {
obj = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
if (!is_windows && openReadPerms) fs.chmodSync(jsonPath, 0o755);
}
else if (fs.existsSync(alternateJsonPath)) {
obj = JSON.parse(fs.readFileSync(alternateJsonPath, 'utf8'));
if (!is_windows && openReadPerms) fs.chmodSync(alternateJsonPath, 0o755);
}
else
obj = 0;
@@ -55,6 +51,28 @@ function getJSONMp3(name, customPath, openReadPerms = false) {
return obj;
}
function fixVideoMetadataPerms(name, type, customPath = null) {
if (is_windows) return;
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';
const files_to_fix = [
// JSONs
path.join(customPath, name + '.info.json'),
path.join(customPath, name + ext + '.info.json'),
// Thumbnails
path.join(customPath, name + '.webp'),
path.join(customPath, name + '.jpg')
];
for (const file of files_to_fix) {
if (!fs.existsSync(file)) continue;
fs.chmodSync(file, 0o644);
}
}
// objects
function File(id, title, thumbnailURL, isAudio, duration, url, uploader, size, path, upload_date) {
@@ -74,5 +92,6 @@ module.exports = {
getJSONMp3: getJSONMp3,
getJSONMp4: getJSONMp4,
getTrueFileName: getTrueFileName,
fixVideoMetadataPerms: fixVideoMetadataPerms,
File: File
}