Added mp3 support

This commit is contained in:
MooradAltamimi
2019-10-18 14:49:34 +01:00
parent cb7b33ce2d
commit 3800c1d22a
6 changed files with 445 additions and 394 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -10,10 +10,19 @@ app.listen(4000, () => {
console.log('Server Works !!! At port 4000');
});
app.get('/download', (req,res) => {
var URL = req.query.URL;
app.get('/downloadmp3', (req,res) => {
var url = req.query.url;
res.header('Content-Disposition', 'attachment; filename="audio.mp3"');
ytdl(url, {
format: 'mp3',
filter: 'audioonly'
}).pipe(res);
});
app.get('/downloadmp4', (req,res) => {
var url = req.query.url;
res.header('Content-Disposition', 'attachment; filename="video.mp4"');
ytdl(URL, {
ytdl(url, {
format: 'mp4'
}).pipe(res);
});

785
Server/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
<body>
<h1 class="heading">My Own Youtube Downloader !</h1>
<input class="URL-input" placeholder="https://www.youtube.com/watch?v=MtN1YnoL46Q"><button class="convert-button">Convert</button>
<input class="URL-input" placeholder="https://www.youtube.com/watch?v=MtN1YnoL46Q"><button class="convert-button" id="mp4">Convert mp4</button><button class="convert-button" id='mp3'>Convert mp3</button>
<script src='script.js'></script>
</body>

View File

@@ -1,11 +1,23 @@
var convertBtn = document.querySelector('.convert-button');
var mp3Btn = document.getElementById('mp3');
var mp4Btn = document.getElementById('mp4');
var URLinput = document.querySelector('.URL-input');
var server = 'http://localhost:4000';
convertBtn.addEventListener('click', () => {
mp3Btn.addEventListener('click', () => {
console.log(`URL: ${URLinput.value}`);
sendURL(URLinput.value);
redirectMp3(URLinput.value);
});
function sendURL(URL) {
window.location.href = `http://localhost:4000/download?URL=${URL}`;
mp4Btn.addEventListener('click', () => {
console.log(`URL: ${URLinput.value}`);
redirectMp4(URLinput.value);
});
function redirectMp3(query) {
window.location.href = `${server}/downloadmp3?url=${query}`;
}
function redirectMp4(query) {
window.location.href = `${server}/downloadmp4?url=${query}`;
}

View File

@@ -26,8 +26,18 @@
}
.convert-button {
border-radius:0px 4px 4px 0px;
border:2px solid #0485ff;
background: #0485ff;
color:white;
}
transition: 0.15s;
}
.convert-button:hover {
background: #016acc;
border-color: #016acc;
}
#mp3 {
border-radius:0px 4px 4px 0px;
}