forked from Moorad/youtube-video-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed formatting (Whitespace and quotations)
- Loading branch information
Showing
4 changed files
with
118 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,51 @@ | ||
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("/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); | ||
} | ||
}); | ||
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Youtube Downloader</title> | ||
</head> | ||
<html lang='en'> | ||
|
||
<body> | ||
<h1 class="heading">Paste YouTube URL</h1> | ||
<input | ||
class="URL-input" | ||
placeholder="https://www.youtube.com/watch?v=MtN1YnoL46Q" | ||
/> | ||
<select class="opt"> | ||
<option value="mp3">mp3</option> | ||
<option value="mp4">mp4</option> | ||
</select> | ||
<head> | ||
<link rel='stylesheet' href='./style.css' /> | ||
<title>Youtube Downloader</title> | ||
</head> | ||
|
||
<button class="convert-button" id="btn">Convert</button> | ||
<script src="./script.js"></script> | ||
</body> | ||
</html> | ||
<body> | ||
<h1 class='heading'>Paste YouTube URL</h1> | ||
<input class='URL-input' placeholder='https://www.youtube.com/watch?v=MtN1YnoL46Q' /> | ||
<select class='opt'> | ||
<option value='mp3'>mp3</option> | ||
<option value='mp4'>mp4</option> | ||
</select> | ||
|
||
<button class='convert-button' id='btn'>Convert</button> | ||
<script src='./script.js'></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
let Btn = document.getElementById("btn"); | ||
let URLinput = document.querySelector(".URL-input"); | ||
let select = document.querySelector(".opt"); | ||
let serverURL = "http://localhost:4000"; | ||
let Btn = document.getElementById('btn'); | ||
let URLinput = document.querySelector('.URL-input'); | ||
let select = document.querySelector('.opt'); | ||
let serverURL = 'http://localhost:4000'; | ||
|
||
Btn.addEventListener("click", () => { | ||
if (!URLinput.value) { | ||
alert("Enter YouTube URL"); | ||
} else { | ||
if (select.value == "mp3") { | ||
redirectMp3(URLinput.value); | ||
} else if (select.value == "mp4") { | ||
redirectMp4(URLinput.value); | ||
} | ||
} | ||
Btn.addEventListener('click', () => { | ||
if (!URLinput.value) { | ||
alert('Enter YouTube URL'); | ||
} else { | ||
if (select.value == 'mp3') { | ||
redirectMp3(URLinput.value); | ||
} else if (select.value == 'mp4') { | ||
redirectMp4(URLinput.value); | ||
} | ||
} | ||
}); | ||
|
||
function redirectMp3(query) { | ||
window.location.href = `${serverURL}/downloadmp3?url=${query}`; | ||
window.location.href = `${serverURL}/downloadmp3?url=${query}`; | ||
} | ||
|
||
function redirectMp4(query) { | ||
window.location.href = `${serverURL}/downloadmp4?url=${query}`; | ||
} | ||
window.location.href = `${serverURL}/downloadmp4?url=${query}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
* { | ||
text-align: center; | ||
text-align: center; | ||
} | ||
|
||
body { | ||
display: grid; | ||
grid-template-columns: auto; | ||
display: grid; | ||
grid-template-columns: auto; | ||
} | ||
|
||
.heading { | ||
font-family: Arial; | ||
margin-top: 40vh; | ||
font-family: Arial; | ||
margin-top: 40vh; | ||
} | ||
|
||
.URL-input, | ||
.convert-button { | ||
font-size: 1.3em; | ||
padding: 5px 10px; | ||
font-size: 1.3em; | ||
padding: 5px 10px; | ||
} | ||
|
||
.URL-input { | ||
margin: auto; | ||
border-radius: 4px 0px 0px 4px; | ||
width: 30em; | ||
text-align: left; | ||
border: 2px solid #eeeeee; | ||
background: #eeeeee; | ||
outline: none; | ||
margin: auto; | ||
border-radius: 4px 0px 0px 4px; | ||
width: 30em; | ||
text-align: left; | ||
border: 2px solid #eeeeee; | ||
background: #eeeeee; | ||
outline: none; | ||
} | ||
|
||
.URL-input:focus { | ||
border: 2px solid #0485ff; | ||
border: 2px solid #0485ff; | ||
} | ||
|
||
.convert-button { | ||
margin: 2% auto; | ||
border: 2px solid #0485ff; | ||
background: #0485ff; | ||
color: white; | ||
transition: 0.15s; | ||
margin: 2% auto; | ||
border: 2px solid #0485ff; | ||
background: #0485ff; | ||
color: white; | ||
transition: 0.15s; | ||
} | ||
|
||
.convert-button:hover { | ||
background: #016acc; | ||
border-color: #016acc; | ||
background: #016acc; | ||
border-color: #016acc; | ||
} | ||
|
||
@media only screen and (max-width: 600px) { | ||
body { | ||
display: grid; | ||
grid-template-columns: auto; | ||
justify-content: center; | ||
} | ||
.URL-input { | ||
margin: auto; | ||
width: 100%; | ||
} | ||
.convert-button { | ||
margin: 7% auto; | ||
width: 100%; | ||
} | ||
body { | ||
display: grid; | ||
grid-template-columns: auto; | ||
justify-content: center; | ||
} | ||
|
||
.URL-input { | ||
margin: auto; | ||
width: 100%; | ||
} | ||
|
||
.convert-button { | ||
margin: 7% auto; | ||
width: 100%; | ||
} | ||
} | ||
|
||
.opt { | ||
width: 30vw; | ||
margin: 2% auto; | ||
padding: 4px; | ||
border-radius: 7%; | ||
} | ||
width: 30vw; | ||
margin: 2% auto; | ||
padding: 4px; | ||
border-radius: 7%; | ||
} |