Skip to content

Commit

Permalink
Changed formatting (Whitespace and quotations)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moorad committed Apr 13, 2020
1 parent 1820c29 commit 500c2c1
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 113 deletions.
78 changes: 41 additions & 37 deletions Server/index.js
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);
}
});
37 changes: 18 additions & 19 deletions index.html
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>
34 changes: 17 additions & 17 deletions script.js
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}`;
}
82 changes: 42 additions & 40 deletions style.css
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%;
}

0 comments on commit 500c2c1

Please sign in to comment.