magnetic url download added

This commit is contained in:
Abhishek Sinha 2018-08-15 18:20:21 +05:30
parent 5224eb6a96
commit e819db3494
8 changed files with 108 additions and 6 deletions

View File

@ -9,6 +9,7 @@
}
footer {
margin-top: 20px;
position:fixed;
bottom:0;
left:0;
@ -56,3 +57,12 @@ footer {
color: #30a247;
text-decoration: none;
}
#mag-res {
height: 500px;
width: auto;
}
.pd-10 {
padding: 10px 10px;
}

View File

@ -8,3 +8,7 @@ client.on('error', function (err) {
console.error('ERROR: ' + err.message)
})

View File

@ -31,4 +31,12 @@ router.get('/download', (req, res)=>{
})
})
router.get('/download-magnetic-uri', (req, res)=>{
res.render('magnetic.ejs', {
data: {},
errors: {},
title: 'Download Magnetic URI!'
})
})
module.exports = router

View File

@ -37,10 +37,6 @@
<script>
function file_ext(file) {
return filename.substring(filename.lastIndexOf('.')+1, filename.length) || filename;
}
//http://www.ytsyify.org/[EZTV]/(eztvtorrent.net)%20The%20Originals%20(S05E04)%20(480p).torrent
$(document).on('click', '#btn-download', function() {
var torrentId = $('#torrent_url').val();
@ -77,11 +73,17 @@
return file.name.endsWith('.pdf')
} else if (file.name.endsWith('.mp3')) {
return file.name.endsWith('.mp3')
} else if (file.name.endsWith('.jpg')) {
return file.name.endsWith('.jpg')
} else if (file.name.endsWith('.png')) {
return file.name.endsWith('.png')
} else if (file.name.endsWith('.gif')) {
return file.name.endsWith('.gif')
}
})
if (typeof file==undefined) {
alert("Unsupported files: Torrent file must contain .mp4, .webm, .avi, .pdf or .mp3 file only.");
alert("Unsupported files: Torrent file must contain .mp4, .webm, .avi, .pdf, .jpg, .png, .gif or .mp3 file only.");
return false;
}

View File

@ -4,6 +4,7 @@
<ul>
<li><a href="/seed">Seed Torrent</a></li>
<li><a href="/download">Download Torrent</a></li>
<li><a href="/download-magnetic-uri">Download Torrent from Magnetic URL</a></li>
</ul>
</div>

74
views/magnetic.ejs Normal file
View File

@ -0,0 +1,74 @@
<%include partials/header.ejs %>
<div class="container">
<label for="mag_text">Provide a magnetic URL below:</label>
<textarea class="form-control" id="mag_text" rows="3"></textarea>
<p><button id="dwn-seed" class="btn btn-primary">View</button></p>
<p id="dwld"></p>
<div class="pd-10">
<div id="mag-res"></div>
</div>
</div>
<%include partials/footer.ejs %>
<script>
$(document).on('click', '#dwn-seed', function() {
var client = new WebTorrent()
var torrentId = document.getElementById('mag_text').value;
if (torrentId.trim() == '') {
alert("Please specify a magnetic url.");
return;
}
client.add(torrentId, function (torrent) {
// Torrents can contain many files. Let's use the .mp4 file
var file = torrent.files.find(function (file) {
console.log(file);
if (file.name.endsWith('.mp4')) {
return file.name.endsWith('.mp4')
} else if (file.name.endsWith('.webm')) {
return file.name.endsWith('.webm')
} else if (file.name.endsWith('.avi')) {
return file.name.endsWith('.avi')
} else if (file.name.endsWith('.pdf')) {
return file.name.endsWith('.pdf')
} else if (file.name.endsWith('.mp3')) {
return file.name.endsWith('.mp3')
} else if (file.name.endsWith('.jpg')) {
return file.name.endsWith('.jpg')
} else if (file.name.endsWith('.png')) {
return file.name.endsWith('.png')
} else if (file.name.endsWith('.gif')) {
return file.name.endsWith('.gif')
} else if (file.name.endsWith('.jpeg')) {
return file.name.endsWith('.jpeg')
}
})
console.log('Client is downloading:', torrent.infoHash)
// Display the file by adding it to the DOM. Supports video, audio, image, etc. files
file.appendTo('#mag-res')
file.getBlobURL(function (err, url) {
if (err) throw err
var a = document.createElement('a')
a.download = file.name
a.href = url
a.textContent = 'Download ' + file.name
document.getElementById("dwld").appendChild(a)
})
})
});
</script>

View File

@ -32,6 +32,9 @@
<li class="nav-item">
<a class="nav-link" href="/download">Download</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/download-magnetic-uri">Download from magnetic url</a>
</li>
</ul>
</div>
</nav>