Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
balajinikhil committed Apr 13, 2020
1 parent cbbedbb commit 4fe525f
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 357 deletions.
1 change: 1 addition & 0 deletions Contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Balaji S github URL: https://github.com/balajinikhil
74 changes: 38 additions & 36 deletions Server/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
const express = require("express");
const cors = require("cors");
const ytdl = require("ytdl-core");
const express = require('express');
const cors = require('cors');
const ytdl = require('ytdl-core');

const app = express();

app.use(cors());

app.listen(4000, () => {
console.log("Server Works !!! At port 4000");
console.log('Server Works !!! At port 4000');
});

app.get("/downloadmp4", async (req, res, next) => {
try {
let URL = req.query.url;
let title = "video";

await ytdl.getBasicInfo(URL, { format: "mp4" }, (err, info) => {
title = info.player_response.videoDetails.title;
});

res.header("Content-Disposition", `attachment; filename="${title}.mp4"`);
ytdl(URL, {
format: "mp4",
}).pipe(res);
} catch (err) {
console.error(err);
}
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;
});

res.header('Content-Disposition', `attachment; filename='${title}.mp3'`);
ytdl(url, {
format: 'mp3',
filter: 'audioonly',
}).pipe(res);
} catch (err) {
console.error(err);
}
});

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

res.header("Content-Disposition", `attachment; filename="${title}.mp3"`);
ytdl(url, {
format: "mp3",
filter: "audioonly",
}).pipe(res);
} catch (err) {
console.error(err);
}
app.get('/downloadmp4', async (req, res, next) => {
try {
let URL = req.query.url;
let title = 'video';

await ytdl.getBasicInfo(URL, { format: 'mp4' }, (err, info) => {
title = info.player_response.videoDetails.title;
});

res.header('Content-Disposition', `attachment; filename='${title}.mp4'`);
ytdl(URL, {
format: 'mp4',
}).pipe(res);
} catch (err) {
console.error(err);
}
});


Loading

0 comments on commit 4fe525f

Please sign in to comment.