mirror of
https://github.com/SrIzan10/youtubeDownloader.git
synced 2026-05-01 11:06:58 +00:00
fix: title value with character outside ASCII range
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user