mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-22 09:23:19 +03:00
fixed file name paths on backend. backend also now tells frontend when the url provided is a playlist
frontend now does not get the file status and simply waits for the server to respond with the file added methods to download audio/video files to simplify downloadHelperMp3/Mp4
This commit is contained in:
@@ -173,7 +173,7 @@ function getVideoFormatID(name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteAudioFile(name) {
|
function deleteAudioFile(name) {
|
||||||
var jsonPath = audioFolderPath+name+'.info.json';
|
var jsonPath = audioFolderPath+name+'.mp3.info.json';
|
||||||
var audioFilePath = audioFolderPath+name+'.mp3';
|
var audioFilePath = audioFolderPath+name+'.mp3';
|
||||||
|
|
||||||
fs.unlinkSync(audioFilePath);
|
fs.unlinkSync(audioFilePath);
|
||||||
@@ -192,15 +192,22 @@ app.post('/tomp3', function(req, res) {
|
|||||||
var url = req.body.url;
|
var url = req.body.url;
|
||||||
var date = Date.now();
|
var date = Date.now();
|
||||||
var path = audioFolderPath;
|
var path = audioFolderPath;
|
||||||
var audiopath = '%(title)s.%(ext)s';
|
var audiopath = '%(title)s';
|
||||||
|
|
||||||
youtubedl.exec(url, ['--get-filename', '-o', audiopath], {}, function(err_getting_name, output) {
|
youtubedl.exec(url, ['--get-filename', '-o', audiopath], {}, function(err_getting_name, output) {
|
||||||
if (err_getting_name) {
|
if (err_getting_name) {
|
||||||
res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
throw err_getting_name;
|
throw err_getting_name;
|
||||||
}
|
}
|
||||||
var output_string = output[0];
|
var file_names = [];
|
||||||
audiopath = output_string.substring(0, output_string.lastIndexOf('.')) + '.mp3';
|
for (let i = 0; i < output.length; i++) {
|
||||||
|
var modified_file_name = output[i];
|
||||||
|
file_names.push(modified_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var is_playlist = file_names.length > 1;
|
||||||
|
if (!is_playlist) audiopath = file_names[0];
|
||||||
|
|
||||||
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3', '--write-info-json'], {}, function(err, output) {
|
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3', '--write-info-json'], {}, function(err, output) {
|
||||||
if (err) {
|
if (err) {
|
||||||
audiopath = "-1";
|
audiopath = "-1";
|
||||||
@@ -208,9 +215,10 @@ app.post('/tomp3', function(req, res) {
|
|||||||
throw err;
|
throw err;
|
||||||
} else if (output) {
|
} else if (output) {
|
||||||
var completeString = "done";
|
var completeString = "done";
|
||||||
var audiopathEncoded = encodeURIComponent(audiopath);
|
var audiopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
res.send({
|
res.send({
|
||||||
audiopathEncoded: audiopathEncoded
|
audiopathEncoded: audiopathEncoded,
|
||||||
|
file_names: is_playlist ? file_names : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -221,15 +229,23 @@ app.post('/tomp4', function(req, res) {
|
|||||||
var url = req.body.url;
|
var url = req.body.url;
|
||||||
var date = Date.now();
|
var date = Date.now();
|
||||||
var path = videoFolderPath;
|
var path = videoFolderPath;
|
||||||
var videopath = '%(title)s.%(ext)s';
|
var videopath = '%(title)s';
|
||||||
|
|
||||||
youtubedl.exec(url, ['--get-filename', '-o', videopath], {}, function(err_getting_name, output) {
|
youtubedl.exec(url, ['--get-filename', '-o', videopath], {}, function(err_getting_name, output) {
|
||||||
if (err_getting_name) {
|
if (err_getting_name) {
|
||||||
res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
throw err_getting_name;
|
throw err_getting_name;
|
||||||
}
|
}
|
||||||
var output_string = output[0];
|
|
||||||
videopath = output_string.substring(0, output_string.lastIndexOf('.')) + '.mp4';
|
var file_names = [];
|
||||||
|
for (let i = 0; i < output.length; i++) {
|
||||||
|
var modified_file_name = output[i];
|
||||||
|
file_names.push(modified_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var is_playlist = file_names.length > 1;
|
||||||
|
if (!is_playlist) videopath = file_names[0];
|
||||||
|
|
||||||
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '--write-info-json'], {}, function(err, output) {
|
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '--write-info-json'], {}, function(err, output) {
|
||||||
if (err) {
|
if (err) {
|
||||||
videopath = "-1";
|
videopath = "-1";
|
||||||
@@ -237,9 +253,10 @@ app.post('/tomp4', function(req, res) {
|
|||||||
throw err;
|
throw err;
|
||||||
} else if (output) {
|
} else if (output) {
|
||||||
var completeString = "done";
|
var completeString = "done";
|
||||||
var videopathEncoded = encodeURIComponent(videopath);
|
var videopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
res.send({
|
res.send({
|
||||||
videopathEncoded: videopathEncoded
|
videopathEncoded: videopathEncoded,
|
||||||
|
file_names: is_playlist ? file_names : null
|
||||||
});
|
});
|
||||||
res.end("yes");
|
res.end("yes");
|
||||||
}
|
}
|
||||||
@@ -403,6 +420,7 @@ app.post('/deleteMp4', function(req, res) {
|
|||||||
|
|
||||||
app.post('/downloadFile', function(req, res) {
|
app.post('/downloadFile', function(req, res) {
|
||||||
let fileName = req.body.fileName;
|
let fileName = req.body.fileName;
|
||||||
|
let is_playlist = req.body.is_playlist;
|
||||||
let type = req.body.type;
|
let type = req.body.type;
|
||||||
let file = null;
|
let file = null;
|
||||||
if (type === 'audio') {
|
if (type === 'audio') {
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ export class AppComponent implements OnInit {
|
|||||||
percentDownloaded: number;
|
percentDownloaded: number;
|
||||||
fileManagerEnabled = false;
|
fileManagerEnabled = false;
|
||||||
downloadOnlyMode = false;
|
downloadOnlyMode = false;
|
||||||
|
baseStreamPath;
|
||||||
|
audioFolderPath;
|
||||||
|
videoFolderPath;
|
||||||
|
|
||||||
mp3s: any[] = [];
|
mp3s: any[] = [];
|
||||||
mp4s: any[] = [];
|
mp4s: any[] = [];
|
||||||
@@ -45,6 +48,9 @@ export class AppComponent implements OnInit {
|
|||||||
this.topBarTitle = result['YoutubeDLMaterial']['Extra']['title_top'];
|
this.topBarTitle = result['YoutubeDLMaterial']['Extra']['title_top'];
|
||||||
this.fileManagerEnabled = result['YoutubeDLMaterial']['Extra']['file_manager_enabled'];
|
this.fileManagerEnabled = result['YoutubeDLMaterial']['Extra']['file_manager_enabled'];
|
||||||
this.downloadOnlyMode = result['YoutubeDLMaterial']['Extra']['download_only_mode'];
|
this.downloadOnlyMode = result['YoutubeDLMaterial']['Extra']['download_only_mode'];
|
||||||
|
this.baseStreamPath = result['YoutubeDLMaterial']['Downloader']['path-base'];
|
||||||
|
this.audioFolderPath = result['YoutubeDLMaterial']['Downloader']['path-audio'];
|
||||||
|
this.videoFolderPath = result['YoutubeDLMaterial']['Downloader']['path-video'];
|
||||||
|
|
||||||
this.postsService.path = backendUrl;
|
this.postsService.path = backendUrl;
|
||||||
this.postsService.startPath = backendUrl;
|
this.postsService.startPath = backendUrl;
|
||||||
@@ -83,9 +89,9 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
public goToFile(name, isAudio) {
|
public goToFile(name, isAudio) {
|
||||||
if (isAudio) {
|
if (isAudio) {
|
||||||
this.downloadHelperMp3(name, true);
|
this.downloadHelperMp3(name, false, true);
|
||||||
} else {
|
} else {
|
||||||
this.downloadHelperMp4(name, true);
|
this.downloadHelperMp4(name, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +120,8 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
// download helpers
|
// download helpers
|
||||||
|
|
||||||
downloadHelperMp3(name: string, forceView = false) {
|
downloadHelperMp3(name, is_playlist = false, forceView = false) {
|
||||||
|
/*
|
||||||
this.postsService.getFileStatusMp3(name).subscribe(fileExists => {
|
this.postsService.getFileStatusMp3(name).subscribe(fileExists => {
|
||||||
const exists = fileExists;
|
const exists = fileExists;
|
||||||
this.exists = exists[0];
|
this.exists = exists[0];
|
||||||
@@ -125,35 +132,39 @@ export class AppComponent implements OnInit {
|
|||||||
this.determinateProgress = true;
|
this.determinateProgress = true;
|
||||||
this.percentDownloaded = percent * 100;
|
this.percentDownloaded = percent * 100;
|
||||||
}
|
}
|
||||||
setTimeout(() => this.downloadHelperMp3(name), 500);
|
setTimeout(() => this.downloadHelperMp3(name, is_playlist, forceView), 500);
|
||||||
} else {
|
} else {
|
||||||
|
*/
|
||||||
this.downloadingfile = false;
|
this.downloadingfile = false;
|
||||||
|
|
||||||
// if download only mode, just download the file. no redirect
|
// if download only mode, just download the file. no redirect
|
||||||
if (forceView === false && this.downloadOnlyMode && !this.iOS) {
|
if (forceView === false && this.downloadOnlyMode && !this.iOS) {
|
||||||
this.postsService.downloadFileFromServer(name, 'audio').subscribe(res => {
|
if (is_playlist) {
|
||||||
const blob: Blob = res;
|
for (let i = 0; i < name.length; i++) {
|
||||||
saveAs(blob, name + '.mp3');
|
this.downloadAudioFile(name[i]);
|
||||||
|
}
|
||||||
// tell server to delete the file once downloaded
|
} else {
|
||||||
this.postsService.deleteFile(name, true).subscribe(delRes => {
|
this.downloadAudioFile(name);
|
||||||
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
window.location.href = this.exists;
|
if (is_playlist) {
|
||||||
|
window.location.href = this.baseStreamPath + this.audioFolderPath + name[0];
|
||||||
|
} else {
|
||||||
|
window.location.href = this.baseStreamPath + this.audioFolderPath + name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reloads mp3s
|
// reloads mp3s
|
||||||
if (this.fileManagerEnabled) {
|
if (this.fileManagerEnabled) {
|
||||||
this.getMp3s();
|
this.getMp3s();
|
||||||
}
|
}
|
||||||
}
|
/* }
|
||||||
});
|
});*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadHelperMp4(name: string, forceView = false) {
|
downloadHelperMp4(name, is_playlist = false, forceView = false) {
|
||||||
|
/*
|
||||||
this.postsService.getFileStatusMp4(name).subscribe(fileExists => {
|
this.postsService.getFileStatusMp4(name).subscribe(fileExists => {
|
||||||
const exists = fileExists;
|
const exists = fileExists;
|
||||||
this.exists = exists[0];
|
this.exists = exists[0];
|
||||||
@@ -163,30 +174,36 @@ export class AppComponent implements OnInit {
|
|||||||
this.determinateProgress = true;
|
this.determinateProgress = true;
|
||||||
this.percentDownloaded = percent * 100;
|
this.percentDownloaded = percent * 100;
|
||||||
}
|
}
|
||||||
setTimeout(() => this.downloadHelperMp4(name), 500);
|
setTimeout(() => this.downloadHelperMp4(name, is_playlist, forceView), 500);
|
||||||
} else {
|
} else {
|
||||||
|
*/
|
||||||
this.downloadingfile = false;
|
this.downloadingfile = false;
|
||||||
|
|
||||||
// if download only mode, just download the file. no redirect
|
// if download only mode, just download the file. no redirect
|
||||||
if (forceView === false && this.downloadOnlyMode) {
|
if (forceView === false && this.downloadOnlyMode) {
|
||||||
this.postsService.downloadFileFromServer(name, 'video').subscribe(res => {
|
if (is_playlist) {
|
||||||
const blob: Blob = res;
|
for (let i = 0; i < name.length; i++) {
|
||||||
saveAs(blob, name + '.mp4');
|
this.downloadVideoFile(name[i]);
|
||||||
|
}
|
||||||
// tell server to delete the file once downloaded
|
} else {
|
||||||
this.postsService.deleteFile(name, false).subscribe(delRes => {
|
this.downloadVideoFile(name);
|
||||||
});
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
window.location.href = this.exists;
|
if (is_playlist) {
|
||||||
|
window.location.href = this.baseStreamPath + this.videoFolderPath + name[0];
|
||||||
|
} else {
|
||||||
|
window.location.href = this.baseStreamPath + this.videoFolderPath + name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reloads mp4s
|
// reloads mp4s
|
||||||
if (this.fileManagerEnabled) {
|
if (this.fileManagerEnabled) {
|
||||||
this.getMp4s();
|
this.getMp4s();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,9 +216,10 @@ export class AppComponent implements OnInit {
|
|||||||
if (this.audioOnly) {
|
if (this.audioOnly) {
|
||||||
this.downloadingfile = true;
|
this.downloadingfile = true;
|
||||||
this.postsService.makeMP3(this.url).subscribe(posts => {
|
this.postsService.makeMP3(this.url).subscribe(posts => {
|
||||||
this.path = posts['audiopathEncoded'];
|
const is_playlist = !!(posts['file_names']);
|
||||||
|
this.path = is_playlist ? posts['file_names'] : posts['audiopathEncoded'];
|
||||||
if (this.path !== '-1') {
|
if (this.path !== '-1') {
|
||||||
this.downloadHelperMp3(this.path);
|
this.downloadHelperMp3(this.path, is_playlist);
|
||||||
}
|
}
|
||||||
}, error => { // can't access server
|
}, error => { // can't access server
|
||||||
this.downloadingfile = false;
|
this.downloadingfile = false;
|
||||||
@@ -210,9 +228,10 @@ export class AppComponent implements OnInit {
|
|||||||
} else {
|
} else {
|
||||||
this.downloadingfile = true;
|
this.downloadingfile = true;
|
||||||
this.postsService.makeMP4(this.url).subscribe(posts => {
|
this.postsService.makeMP4(this.url).subscribe(posts => {
|
||||||
this.path = posts['videopathEncoded'];
|
const is_playlist = !!(posts['file_names']);
|
||||||
|
this.path = is_playlist ? posts['file_names'] : posts['videopathEncoded'];
|
||||||
if (this.path !== '-1') {
|
if (this.path !== '-1') {
|
||||||
this.downloadHelperMp4(this.path);
|
this.downloadHelperMp4(this.path, is_playlist);
|
||||||
}
|
}
|
||||||
}, error => { // can't access server
|
}, error => { // can't access server
|
||||||
this.downloadingfile = false;
|
this.downloadingfile = false;
|
||||||
@@ -224,6 +243,30 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadAudioFile(name) {
|
||||||
|
this.postsService.downloadFileFromServer(name, 'audio').subscribe(res => {
|
||||||
|
const blob: Blob = res;
|
||||||
|
saveAs(blob, name + '.mp3');
|
||||||
|
|
||||||
|
// tell server to delete the file once downloaded
|
||||||
|
this.postsService.deleteFile(name, true).subscribe(delRes => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadVideoFile(name) {
|
||||||
|
this.postsService.downloadFileFromServer(name, 'video').subscribe(res => {
|
||||||
|
const blob: Blob = res;
|
||||||
|
saveAs(blob, name + '.mp4');
|
||||||
|
|
||||||
|
// tell server to delete the file once downloaded
|
||||||
|
this.postsService.deleteFile(name, false).subscribe(delRes => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// checks if url is a valid URL
|
// checks if url is a valid URL
|
||||||
ValidURL(str) {
|
ValidURL(str) {
|
||||||
// tslint:disable-next-line: max-line-length
|
// tslint:disable-next-line: max-line-length
|
||||||
|
|||||||
Reference in New Issue
Block a user