mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-14 23:11:28 +03:00
Added debug mode to server and relevant debug configurations
simplified youtubedl download process to speed up the download queryurl not printed any longer by youtube search service
This commit is contained in:
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "attach",
|
||||||
|
"name": "Attach",
|
||||||
|
"port": 9229
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
129
backend/app.js
129
backend/app.js
@@ -10,7 +10,12 @@ var app = express();
|
|||||||
|
|
||||||
var URL = require('url').URL;
|
var URL = require('url').URL;
|
||||||
|
|
||||||
var frontendUrl = config.get("YoutubeDLMaterial.Host.frontendurl");
|
// check if debug mode
|
||||||
|
let debugMode = process.env.YTDL_MODE === 'debug';
|
||||||
|
|
||||||
|
if (debugMode) console.log('YTDL-Material in debug mode!');
|
||||||
|
|
||||||
|
var frontendUrl = !debugMode ? config.get("YoutubeDLMaterial.Host.frontendurl") : 'http://localhost:4200';
|
||||||
var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl")
|
var backendUrl = config.get("YoutubeDLMaterial.Host.backendurl")
|
||||||
var backendPort = 17442;
|
var backendPort = 17442;
|
||||||
var usingEncryption = config.get("YoutubeDLMaterial.Encryption.use-encryption");
|
var usingEncryption = config.get("YoutubeDLMaterial.Encryption.use-encryption");
|
||||||
@@ -19,6 +24,7 @@ var audioFolderPath = config.get("YoutubeDLMaterial.Downloader.path-audio");
|
|||||||
var videoFolderPath = config.get("YoutubeDLMaterial.Downloader.path-video");
|
var videoFolderPath = config.get("YoutubeDLMaterial.Downloader.path-video");
|
||||||
var downloadOnlyMode = config.get("YoutubeDLMaterial.Extra.download_only_mode")
|
var downloadOnlyMode = config.get("YoutubeDLMaterial.Extra.download_only_mode")
|
||||||
|
|
||||||
|
|
||||||
if (usingEncryption)
|
if (usingEncryption)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -194,34 +200,38 @@ app.post('/tomp3', function(req, res) {
|
|||||||
var path = audioFolderPath;
|
var path = audioFolderPath;
|
||||||
var audiopath = '%(title)s';
|
var audiopath = '%(title)s';
|
||||||
|
|
||||||
youtubedl.exec(url, ['--get-filename', '-o', audiopath], {}, function(err_getting_name, output) {
|
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3', '--write-info-json', '--print-json'], {}, function(err, output) {
|
||||||
if (err_getting_name) {
|
if (debugMode) {
|
||||||
|
let new_date = Date.now();
|
||||||
|
let difference = (new_date - date)/1000;
|
||||||
|
console.log(`Audio download delay: ${difference} seconds.`);
|
||||||
|
}
|
||||||
|
if (err) {
|
||||||
|
audiopath = "-1";
|
||||||
res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
throw err_getting_name;
|
throw err;
|
||||||
}
|
} else if (output) {
|
||||||
var file_names = [];
|
var file_names = [];
|
||||||
for (let i = 0; i < output.length; i++) {
|
for (let i = 0; i < output.length; i++) {
|
||||||
var modified_file_name = output[i];
|
let output_json = null;
|
||||||
file_names.push(modified_file_name);
|
try {
|
||||||
}
|
output_json = JSON.parse(output[i]);
|
||||||
|
} catch {
|
||||||
var is_playlist = file_names.length > 1;
|
output_json = null;
|
||||||
if (!is_playlist) audiopath = file_names[0];
|
}
|
||||||
|
var modified_file_name = output_json ? output_json['title'] : null;
|
||||||
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + audiopath + ".mp3", '-x', '--audio-format', 'mp3', '--write-info-json'], {}, function(err, output) {
|
if (modified_file_name) file_names.push(modified_file_name);
|
||||||
if (err) {
|
|
||||||
audiopath = "-1";
|
|
||||||
res.sendStatus(500);
|
|
||||||
throw err;
|
|
||||||
} else if (output) {
|
|
||||||
var completeString = "done";
|
|
||||||
var audiopathEncoded = encodeURIComponent(file_names[0]);
|
|
||||||
res.send({
|
|
||||||
audiopathEncoded: audiopathEncoded,
|
|
||||||
file_names: is_playlist ? file_names : null
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
let is_playlist = file_names.length > 1;
|
||||||
|
if (!is_playlist) audiopath = file_names[0];
|
||||||
|
|
||||||
|
var audiopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
|
res.send({
|
||||||
|
audiopathEncoded: audiopathEncoded,
|
||||||
|
file_names: is_playlist ? file_names : null
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -231,36 +241,39 @@ app.post('/tomp4', function(req, res) {
|
|||||||
var path = videoFolderPath;
|
var path = videoFolderPath;
|
||||||
var videopath = '%(title)s';
|
var videopath = '%(title)s';
|
||||||
|
|
||||||
youtubedl.exec(url, ['--get-filename', '-o', videopath], {}, function(err_getting_name, output) {
|
youtubedl.exec(url, ['--external-downloader', 'aria2c', '-o', path + videopath + ".mp4", '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '--write-info-json', '--print-json'], {}, function(err, output) {
|
||||||
if (err_getting_name) {
|
if (debugMode) {
|
||||||
|
let new_date = Date.now();
|
||||||
|
let difference = (new_date - date)/1000;
|
||||||
|
console.log(`Video download delay: ${difference} seconds.`);
|
||||||
|
}
|
||||||
|
if (err) {
|
||||||
|
videopath = "-1";
|
||||||
res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
throw err_getting_name;
|
throw err;
|
||||||
}
|
} else if (output) {
|
||||||
|
var file_names = [];
|
||||||
var file_names = [];
|
for (let i = 0; i < output.length; i++) {
|
||||||
for (let i = 0; i < output.length; i++) {
|
let output_json = null;
|
||||||
var modified_file_name = output[i];
|
try {
|
||||||
file_names.push(modified_file_name);
|
output_json = JSON.parse(output[i]);
|
||||||
}
|
} catch {
|
||||||
|
output_json = null;
|
||||||
var is_playlist = file_names.length > 1;
|
}
|
||||||
if (!is_playlist) videopath = file_names[0];
|
var modified_file_name = output_json ? output_json['title'] : null;
|
||||||
|
if (modified_file_name) file_names.push(modified_file_name);
|
||||||
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) {
|
|
||||||
videopath = "-1";
|
|
||||||
res.sendStatus(500);
|
|
||||||
throw err;
|
|
||||||
} else if (output) {
|
|
||||||
var completeString = "done";
|
|
||||||
var videopathEncoded = encodeURIComponent(file_names[0]);
|
|
||||||
res.send({
|
|
||||||
videopathEncoded: videopathEncoded,
|
|
||||||
file_names: is_playlist ? file_names : null
|
|
||||||
});
|
|
||||||
res.end("yes");
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
let is_playlist = file_names.length > 1;
|
||||||
|
if (!is_playlist) audiopath = file_names[0];
|
||||||
|
|
||||||
|
var videopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
|
res.send({
|
||||||
|
videopathEncoded: videopathEncoded,
|
||||||
|
file_names: is_playlist ? file_names : null
|
||||||
|
});
|
||||||
|
res.end("yes");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -445,7 +458,7 @@ app.post('/deleteFile', function(req, res) {
|
|||||||
|
|
||||||
app.get('/video/:id', function(req , res){
|
app.get('/video/:id', function(req , res){
|
||||||
var head;
|
var head;
|
||||||
const path = "video/" + req.params.id + ".mp4";
|
const path = "video/" + req.params.id;
|
||||||
const stat = fs.statSync(path)
|
const stat = fs.statSync(path)
|
||||||
const fileSize = stat.size
|
const fileSize = stat.size
|
||||||
const range = req.headers.range
|
const range = req.headers.range
|
||||||
@@ -477,7 +490,7 @@ app.get('/video/:id', function(req , res){
|
|||||||
|
|
||||||
app.get('/audio/:id', function(req , res){
|
app.get('/audio/:id', function(req , res){
|
||||||
var head;
|
var head;
|
||||||
const path = "audio/" + req.params.id + ".mp3";
|
const path = "audio/" + req.params.id;
|
||||||
const stat = fs.statSync(path)
|
const stat = fs.statSync(path)
|
||||||
const fileSize = stat.size
|
const fileSize = stat.size
|
||||||
const range = req.headers.range
|
const range = req.headers.range
|
||||||
@@ -506,7 +519,7 @@ app.get('/audio/:id', function(req , res){
|
|||||||
fs.createReadStream(path).pipe(res)
|
fs.createReadStream(path).pipe(res)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ export class YoutubeSearchService {
|
|||||||
`maxResults=5`
|
`maxResults=5`
|
||||||
].join('&')
|
].join('&')
|
||||||
const queryUrl = `${this.url}?${params}`
|
const queryUrl = `${this.url}?${params}`
|
||||||
console.log(queryUrl)
|
|
||||||
return this.http.get(queryUrl).map(response => {
|
return this.http.get(queryUrl).map(response => {
|
||||||
return <any>response['items'].map(item => {
|
return <any>response['items'].map(item => {
|
||||||
return new Result({
|
return new Result({
|
||||||
|
|||||||
Reference in New Issue
Block a user