diff --git a/Server/index.js b/Server/index.js index a9863ac..39085b8 100644 --- a/Server/index.js +++ b/Server/index.js @@ -1,23 +1,24 @@ const express = require('express'); const cors = require('cors'); const ytdl = require('ytdl-core'); - const app = express(); +const PORT = 4000; app.use(cors()); -app.listen(4000, () => { - console.log('Server Works !!! At port 4000'); +app.listen(PORT, () => { + console.log(`Server Works !!! At port ${PORT}`); }); app.get('/downloadmp3', async (req, res, next) => { try { var url = req.query.url; let title = 'audio'; + await ytdl.getBasicInfo(url, { format: 'mp4' }, (err, info) => { - title = info.player_response.videoDetails.title; + title = info.player_response.videoDetails.title.replace(/[^\x00-\x7F]/g, ""); }); res.header('Content-Disposition', `attachment; filename="${title}.mp3"`); @@ -25,6 +26,7 @@ app.get('/downloadmp3', async (req, res, next) => { format: 'mp3', filter: 'audioonly', }).pipe(res); + } catch (err) { console.error(err); } @@ -38,13 +40,14 @@ app.get('/downloadmp4', async (req, res, next) => { await ytdl.getBasicInfo(URL, { format: 'mp4' }, (err, info) => { - title = info.player_response.videoDetails.title; + title = info.player_response.videoDetails.title.replace(/[^\x00-\x7F]/g, ""); }); res.header('Content-Disposition', `attachment; filename="${title}.mp4"`); ytdl(URL, { format: 'mp4', }).pipe(res); + } catch (err) { console.error(err); }