mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-19 11:10:57 +03:00
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:
@@ -884,11 +884,14 @@ async function deleteAudioFile(name, blacklistMode = false) {
|
||||
var jsonPath = path.join(audioFolderPath,name+'.mp3.info.json');
|
||||
var altJSONPath = path.join(audioFolderPath,name+'.info.json');
|
||||
var audioFilePath = path.join(audioFolderPath,name+'.mp3');
|
||||
var thumbnailPath = path.join(filePath,name+'.webp');
|
||||
var altThumbnailPath = path.join(filePath,name+'.jpg');
|
||||
jsonPath = path.join(__dirname, jsonPath);
|
||||
altJSONPath = path.join(__dirname, altJSONPath);
|
||||
audioFilePath = path.join(__dirname, audioFilePath);
|
||||
|
||||
let jsonExists = fs.existsSync(jsonPath);
|
||||
let thumbnailExists = fs.existsSync(thumbnailPath);
|
||||
|
||||
if (!jsonExists) {
|
||||
if (fs.existsSync(altJSONPath)) {
|
||||
@@ -897,6 +900,13 @@ async function deleteAudioFile(name, blacklistMode = false) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!thumbnailExists) {
|
||||
if (fs.existsSync(altThumbnailPath)) {
|
||||
thumbnailExists = true;
|
||||
thumbnailPath = altThumbnailPath;
|
||||
}
|
||||
}
|
||||
|
||||
let audioFileExists = fs.existsSync(audioFilePath);
|
||||
|
||||
if (config_api.descriptors[name]) {
|
||||
@@ -930,6 +940,7 @@ async function deleteAudioFile(name, blacklistMode = false) {
|
||||
}
|
||||
|
||||
if (jsonExists) fs.unlinkSync(jsonPath);
|
||||
if (thumbnailExists) fs.unlinkSync(thumbnailPath);
|
||||
if (audioFileExists) {
|
||||
fs.unlink(audioFilePath, function(err) {
|
||||
if (fs.existsSync(jsonPath) || fs.existsSync(audioFilePath)) {
|
||||
@@ -950,12 +961,30 @@ async function deleteVideoFile(name, customPath = null, blacklistMode = false) {
|
||||
return new Promise(resolve => {
|
||||
let filePath = customPath ? customPath : videoFolderPath;
|
||||
var jsonPath = path.join(filePath,name+'.info.json');
|
||||
var altJSONPath = path.join(filePath,name+'.mp4.info.json');
|
||||
var videoFilePath = path.join(filePath,name+'.mp4');
|
||||
var thumbnailPath = path.join(filePath,name+'.webp');
|
||||
var altThumbnailPath = path.join(filePath,name+'.jpg');
|
||||
jsonPath = path.join(__dirname, jsonPath);
|
||||
videoFilePath = path.join(__dirname, videoFilePath);
|
||||
|
||||
jsonExists = fs.existsSync(jsonPath);
|
||||
videoFileExists = fs.existsSync(videoFilePath);
|
||||
let jsonExists = fs.existsSync(jsonPath);
|
||||
let videoFileExists = fs.existsSync(videoFilePath);
|
||||
let thumbnailExists = fs.existsSync(thumbnailPath);
|
||||
|
||||
if (!jsonExists) {
|
||||
if (fs.existsSync(altJSONPath)) {
|
||||
jsonExists = true;
|
||||
jsonPath = altJSONPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!thumbnailExists) {
|
||||
if (fs.existsSync(altThumbnailPath)) {
|
||||
thumbnailExists = true;
|
||||
thumbnailPath = altThumbnailPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (config_api.descriptors[name]) {
|
||||
try {
|
||||
@@ -988,6 +1017,7 @@ async function deleteVideoFile(name, customPath = null, blacklistMode = false) {
|
||||
}
|
||||
|
||||
if (jsonExists) fs.unlinkSync(jsonPath);
|
||||
if (thumbnailExists) fs.unlinkSync(thumbnailPath);
|
||||
if (videoFileExists) {
|
||||
fs.unlink(videoFilePath, function(err) {
|
||||
if (fs.existsSync(jsonPath) || fs.existsSync(videoFilePath)) {
|
||||
|
||||
@@ -23,6 +23,8 @@ function registerFileDB(file_path, type, multiUserMode = null, sub = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
utils.fixVideoMetadataPerms(file_id, type, multiUserMode && multiUserMode.file_path);
|
||||
|
||||
// add additional info
|
||||
file_object['uid'] = uuid();
|
||||
file_object['registered'] = Date.now();
|
||||
|
||||
@@ -195,10 +195,12 @@ async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null,
|
||||
var jsonPath = path.join(__dirname,filePath,name+'.info.json');
|
||||
var videoFilePath = path.join(__dirname,filePath,name+ext);
|
||||
var imageFilePath = path.join(__dirname,filePath,name+'.jpg');
|
||||
var altImageFilePath = path.join(__dirname,filePath,name+'.jpg');
|
||||
|
||||
jsonExists = fs.existsSync(jsonPath);
|
||||
videoFileExists = fs.existsSync(videoFilePath);
|
||||
imageFileExists = fs.existsSync(imageFilePath);
|
||||
altImageFileExists = fs.existsSync(altImageFilePath);
|
||||
|
||||
if (jsonExists) {
|
||||
retrievedID = JSON.parse(fs.readFileSync(jsonPath, 'utf8'))['id'];
|
||||
@@ -209,6 +211,10 @@ async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null,
|
||||
fs.unlinkSync(imageFilePath);
|
||||
}
|
||||
|
||||
if (altImageFileExists) {
|
||||
fs.unlinkSync(altImageFilePath);
|
||||
}
|
||||
|
||||
if (videoFileExists) {
|
||||
fs.unlink(videoFilePath, function(err) {
|
||||
if (fs.existsSync(jsonPath) || fs.existsSync(videoFilePath)) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user