From fb26915f43806c91c7bc47124e033627d836dc25 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Thu, 19 Sep 2019 23:28:19 +0200 Subject: [PATCH] Added analyse function & fixed Unix/Windows paths --- routes/index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/routes/index.js b/routes/index.js index 7971670..d2f61d4 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,11 +2,13 @@ var express = require('express'); var YoutubeMp3Downloader = require("youtube-mp3-downloader"); var fs = require('fs'); var path = require('path'); +var urlParse = require("body-parser"); +var id3 = require('node-id3'); var router = express.Router(); var YD = new YoutubeMp3Downloader({ - "ffmpegPath": __dirname + "/../bin/ffmpeg", - "outputPath": __dirname + "/../music", + "ffmpegPath": path.join(__dirname + "/../bin/ffmpeg"), + "outputPath": path.join(__dirname + "/../music"), "youtubeVideoQuality": "highest", "queueParallelism": 1, "progressTimeout": 2000 @@ -127,4 +129,16 @@ router.get('/search/:query', (req, res, _next) => { }); }); +router.use(urlParse.urlencoded({extended : true})); +router.get('/analyse/*', (req, res, _next) => { + let file = req.params[0]; + if (fs.existsSync(file)) { + var result = id3.read(file); + result.image.base64 = result.image.imageBuffer.toString('base64'); + } else { + var result = 'File not found' + } + res.json({ result: result }); +}); + module.exports = router;