mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-12 06:11:29 +03:00
Added new methods to facilitate server-side download management
This commit is contained in:
@@ -141,6 +141,7 @@ if (writeConfigMode) {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var downloads = {};
|
||||||
var descriptors = {};
|
var descriptors = {};
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
@@ -1363,7 +1364,18 @@ app.post('/api/tomp3', async function(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds download to download helper
|
||||||
|
const download_uid = uuid();
|
||||||
|
downloads[download_uid] = {
|
||||||
|
uid: download_uid,
|
||||||
|
downloading: true,
|
||||||
|
complete: false,
|
||||||
|
url: url,
|
||||||
|
type: 'audio'
|
||||||
|
};
|
||||||
|
|
||||||
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
|
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
|
||||||
|
downloads[download_uid]['downloading'] = false;
|
||||||
var uid = null;
|
var uid = null;
|
||||||
let new_date = Date.now();
|
let new_date = Date.now();
|
||||||
let difference = (new_date - date)/1000;
|
let difference = (new_date - date)/1000;
|
||||||
@@ -1423,6 +1435,8 @@ app.post('/api/tomp3', async function(req, res) {
|
|||||||
fs.unlinkSync(merged_path)
|
fs.unlinkSync(merged_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloads[download_uid]['complete'] = true;
|
||||||
|
|
||||||
var audiopathEncoded = encodeURIComponent(file_names[0]);
|
var audiopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
res.send({
|
res.send({
|
||||||
audiopathEncoded: audiopathEncoded,
|
audiopathEncoded: audiopathEncoded,
|
||||||
@@ -1510,7 +1524,20 @@ app.post('/api/tomp4', async function(req, res) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds download to download helper
|
||||||
|
const download_uid = uuid();
|
||||||
|
downloads[download_uid] = {
|
||||||
|
uid: download_uid,
|
||||||
|
downloading: true,
|
||||||
|
complete: false,
|
||||||
|
url: url,
|
||||||
|
type: 'video',
|
||||||
|
percent_complete: 0,
|
||||||
|
is_playlist: url.includes('playlist')
|
||||||
|
};
|
||||||
|
|
||||||
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
|
youtubedl.exec(url, downloadConfig, {}, function(err, output) {
|
||||||
|
downloads[download_uid]['downloading'] = false;
|
||||||
var uid = null;
|
var uid = null;
|
||||||
let new_date = Date.now();
|
let new_date = Date.now();
|
||||||
let difference = (new_date - date)/1000;
|
let difference = (new_date - date)/1000;
|
||||||
@@ -1568,6 +1595,8 @@ app.post('/api/tomp4', async function(req, res) {
|
|||||||
const archive_path = path.join(archivePath, 'archive_video.txt');
|
const archive_path = path.join(archivePath, 'archive_video.txt');
|
||||||
fs.appendFileSync(archive_path, diff);
|
fs.appendFileSync(archive_path, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloads[download_uid]['complete'] = true;
|
||||||
|
|
||||||
var videopathEncoded = encodeURIComponent(file_names[0]);
|
var videopathEncoded = encodeURIComponent(file_names[0]);
|
||||||
res.send({
|
res.send({
|
||||||
@@ -2282,6 +2311,12 @@ app.get('/api/audio/:id', function(req , res){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Downloads management
|
||||||
|
|
||||||
|
app.get('/api/downloads', async (req, res) => {
|
||||||
|
res.send({downloads: downloads});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post('/api/getVideoInfos', async (req, res) => {
|
app.post('/api/getVideoInfos', async (req, res) => {
|
||||||
let fileNames = req.body.fileNames;
|
let fileNames = req.body.fileNames;
|
||||||
|
|||||||
@@ -215,6 +215,11 @@ export class PostsService {
|
|||||||
return this.http.post(this.path + 'getAllSubscriptions', {}, this.httpOptions);
|
return this.http.post(this.path + 'getAllSubscriptions', {}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// current downloads
|
||||||
|
getCurrentDownloads() {
|
||||||
|
return this.http.get(this.path + 'downloads', this.httpOptions);
|
||||||
|
}
|
||||||
|
|
||||||
// updates the server to the latest version
|
// updates the server to the latest version
|
||||||
updateServer(tag) {
|
updateServer(tag) {
|
||||||
return this.http.post(this.path + 'updateServer', {tag: tag}, this.httpOptions);
|
return this.http.post(this.path + 'updateServer', {tag: tag}, this.httpOptions);
|
||||||
|
|||||||
Reference in New Issue
Block a user