diff --git a/backend/app.js b/backend/app.js index a8a7c82..d8a4c0d 100644 --- a/backend/app.js +++ b/backend/app.js @@ -141,6 +141,7 @@ if (writeConfigMode) { loadConfig(); } +var downloads = {}; var descriptors = {}; 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) { + downloads[download_uid]['downloading'] = false; var uid = null; let new_date = Date.now(); let difference = (new_date - date)/1000; @@ -1423,6 +1435,8 @@ app.post('/api/tomp3', async function(req, res) { fs.unlinkSync(merged_path) } + downloads[download_uid]['complete'] = true; + var audiopathEncoded = encodeURIComponent(file_names[0]); res.send({ 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) { + downloads[download_uid]['downloading'] = false; var uid = null; let new_date = Date.now(); 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'); fs.appendFileSync(archive_path, diff); } + + downloads[download_uid]['complete'] = true; var videopathEncoded = encodeURIComponent(file_names[0]); 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) => { let fileNames = req.body.fileNames; diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 8aa05d1..6112e75 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -215,6 +215,11 @@ export class PostsService { 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 updateServer(tag) { return this.http.post(this.path + 'updateServer', {tag: tag}, this.httpOptions);