|
|
@ -358,10 +358,16 @@ function getVideoFormatID(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function createPlaylistZipFile(fileNames, type, outputName) {
|
|
|
|
async function createPlaylistZipFile(fileNames, type, outputName, fullPathProvided = null) {
|
|
|
|
return new Promise(async resolve => {
|
|
|
|
return new Promise(async resolve => {
|
|
|
|
let zipFolderPath = path.join(__dirname, (type === 'audio') ? audioFolderPath : videoFolderPath);
|
|
|
|
let zipFolderPath = null;
|
|
|
|
// let name = fileNames[0].split(' ')[0] + fileNames[1].split(' ')[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (!fullPathProvided) {
|
|
|
|
|
|
|
|
zipFolderPath = path.join(__dirname, (type === 'audio') ? audioFolderPath : videoFolderPath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
zipFolderPath = path.join(__dirname, config_api.getConfigItem('ytdl_subscriptions_base_path'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let ext = (type === 'audio') ? '.mp3' : '.mp4';
|
|
|
|
let ext = (type === 'audio') ? '.mp3' : '.mp4';
|
|
|
|
|
|
|
|
|
|
|
|
let output = fs.createWriteStream(path.join(zipFolderPath, outputName + '.zip'));
|
|
|
|
let output = fs.createWriteStream(path.join(zipFolderPath, outputName + '.zip'));
|
|
|
@ -381,7 +387,8 @@ async function createPlaylistZipFile(fileNames, type, outputName) {
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < fileNames.length; i++) {
|
|
|
|
for (let i = 0; i < fileNames.length; i++) {
|
|
|
|
let fileName = fileNames[i];
|
|
|
|
let fileName = fileNames[i];
|
|
|
|
archive.file(zipFolderPath + fileName + ext, {name: fileName + ext})
|
|
|
|
let file_path = !fullPathProvided ? zipFolderPath + fileName + ext : fileName;
|
|
|
|
|
|
|
|
archive.file(file_path, {name: fileName + ext})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await archive.finalize();
|
|
|
|
await archive.finalize();
|
|
|
@ -1141,9 +1148,6 @@ app.post('/api/getSubscription', async (req, res) => {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.sendStatus(500);
|
|
|
|
res.sendStatus(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/api/downloadVideosForSubscription', async (req, res) => {
|
|
|
|
app.post('/api/downloadVideosForSubscription', async (req, res) => {
|
|
|
@ -1278,11 +1282,12 @@ app.post('/api/deleteMp4', async (req, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/api/downloadFile', async (req, res) => {
|
|
|
|
app.post('/api/downloadFile', async (req, res) => {
|
|
|
|
let fileNames = req.body.fileNames;
|
|
|
|
let fileNames = req.body.fileNames;
|
|
|
|
let is_playlist = req.body.is_playlist;
|
|
|
|
let zip_mode = req.body.zip_mode;
|
|
|
|
let type = req.body.type;
|
|
|
|
let type = req.body.type;
|
|
|
|
let outputName = req.body.outputName;
|
|
|
|
let outputName = req.body.outputName;
|
|
|
|
|
|
|
|
let fullPathProvided = req.body.fullPathProvided;
|
|
|
|
let file = null;
|
|
|
|
let file = null;
|
|
|
|
if (!is_playlist) {
|
|
|
|
if (!zip_mode) {
|
|
|
|
fileNames = decodeURIComponent(fileNames);
|
|
|
|
fileNames = decodeURIComponent(fileNames);
|
|
|
|
if (type === 'audio') {
|
|
|
|
if (type === 'audio') {
|
|
|
|
file = __dirname + '/' + audioFolderPath + fileNames + '.mp3';
|
|
|
|
file = __dirname + '/' + audioFolderPath + fileNames + '.mp3';
|
|
|
@ -1293,10 +1298,20 @@ app.post('/api/downloadFile', async (req, res) => {
|
|
|
|
for (let i = 0; i < fileNames.length; i++) {
|
|
|
|
for (let i = 0; i < fileNames.length; i++) {
|
|
|
|
fileNames[i] = decodeURIComponent(fileNames[i]);
|
|
|
|
fileNames[i] = decodeURIComponent(fileNames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file = await createPlaylistZipFile(fileNames, type, outputName);
|
|
|
|
file = await createPlaylistZipFile(fileNames, type, outputName, fullPathProvided);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res.sendFile(file);
|
|
|
|
res.sendFile(file, function (err) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
next(err);
|
|
|
|
|
|
|
|
} else if (fullPathProvided) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fs.unlinkSync(file);
|
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
|
|
|
|
console.log("ERROR: Failed to remove file", file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/api/deleteFile', async (req, res) => {
|
|
|
|
app.post('/api/deleteFile', async (req, res) => {
|
|
|
|