fix: title value with character outside ASCII range

This commit is contained in:
chrisVillanueva
2020-06-16 09:35:10 -04:00
parent d1c2789e15
commit d37ee9ff1a

View File

@@ -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);
}