Fixed bug where subscription videos could not be downloaded from the player

pull/49/head
Isaac Grynsztein 5 years ago
parent fa488015c3
commit 720fceefb6

@ -1997,13 +1997,26 @@ app.post('/api/downloadFile', async (req, res) => {
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 fullPathProvided = req.body.fullPathProvided;
let subscriptionName = req.body.subscriptionName;
let subscriptionPlaylist = req.body.subscriptionPlaylist;
let file = null; let file = null;
if (!zip_mode) { if (!zip_mode) {
fileNames = decodeURIComponent(fileNames); fileNames = decodeURIComponent(fileNames);
if (type === 'audio') { if (type === 'audio') {
file = __dirname + '/' + audioFolderPath + fileNames + '.mp3'; if (!subscriptionName) {
} else if (type === 'video') { file = path.join(__dirname, audioFolderPath, fileNames + '.mp3');
file = __dirname + '/' + videoFolderPath + fileNames + '.mp4'; } else {
let basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
file = path.join(__dirname, basePath, (subscriptionPlaylist ? 'playlists' : 'channels'), subscriptionName, fileNames + '.mp3')
}
} else {
// if type is 'subscription' or 'video', it's a video
if (!subscriptionName) {
file = path.join(__dirname, videoFolderPath, fileNames + '.mp4');
} else {
let basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
file = path.join(__dirname, basePath, (subscriptionPlaylist ? 'playlists' : 'channels'), subscriptionName, fileNames + '.mp4')
}
} }
} else { } else {
for (let i = 0; i < fileNames.length; i++) { for (let i = 0; i < fileNames.length; i++) {
@ -2011,10 +2024,9 @@ app.post('/api/downloadFile', async (req, res) => {
} }
file = await createPlaylistZipFile(fileNames, type, outputName, fullPathProvided); file = await createPlaylistZipFile(fileNames, type, outputName, fullPathProvided);
} }
res.sendFile(file, function (err) { res.sendFile(file, function (err) {
if (err) { if (err) {
next(err); logger.error(err);
} else if (fullPathProvided) { } else if (fullPathProvided) {
try { try {
fs.unlinkSync(file); fs.unlinkSync(file);

@ -250,7 +250,7 @@ export class PlayerComponent implements OnInit {
const ext = (this.type === 'audio') ? '.mp3' : '.mp4'; const ext = (this.type === 'audio') ? '.mp3' : '.mp4';
const filename = this.playlist[0].title; const filename = this.playlist[0].title;
this.downloading = true; this.downloading = true;
this.postsService.downloadFileFromServer(filename, this.type).subscribe(res => { this.postsService.downloadFileFromServer(filename, this.type, null, null, this.subscriptionName, this.subPlaylist).subscribe(res => {
this.downloading = false; this.downloading = false;
const blob: Blob = res; const blob: Blob = res;
saveAs(blob, filename + ext); saveAs(blob, filename + ext);

@ -122,12 +122,15 @@ export class PostsService {
return this.http.post(this.path + 'getFile', {uid: uid, type: type}); return this.http.post(this.path + 'getFile', {uid: uid, type: type});
} }
downloadFileFromServer(fileName, type, outputName = null, fullPathProvided = null) { downloadFileFromServer(fileName, type, outputName = null, fullPathProvided = null, subscriptionName = null, subPlaylist = null) {
return this.http.post(this.path + 'downloadFile', {fileNames: fileName, return this.http.post(this.path + 'downloadFile', {fileNames: fileName,
type: type, type: type,
zip_mode: Array.isArray(fileName), zip_mode: Array.isArray(fileName),
outputName: outputName, outputName: outputName,
fullPathProvided: fullPathProvided}, fullPathProvided: fullPathProvided,
subscriptionName: subscriptionName,
subPlaylist: subPlaylist
},
{responseType: 'blob'}); {responseType: 'blob'});
} }

Loading…
Cancel
Save