Skip to content

Instantly share code, notes, and snippets.

@daslicht
Created August 9, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daslicht/485fc17f8a692c3cccfb203a88064874 to your computer and use it in GitHub Desktop.
Save daslicht/485fc17f8a692c3cccfb203a88064874 to your computer and use it in GitHub Desktop.
$(document).ready(function ($) {
var client = new WebTorrent();
var timer = null;
window.client = client;
$('.message').removeClass('show');
function addVideo(uri) {
client.add(uri, function (torrent) {
var file = torrent.files.find(function (file) {
console.log(file);
return file.name;
//return file.name.endsWith('.wav');
})
file.appendTo('.video-content-wrapper');
var videos = $('.video-content-wrapper video');
if (!!videos && !!videos.length) {
$(videos[0]).on('loadstart', function () {
videos[0].autoplay = false;
videos[0].pause();
});
}
$('.progressbar').css('visibility', 'visible');
torrent.on('done', onDone);
timer = setInterval(updateProgress, 500);
function updateProgress() {
var percent = Math.round(torrent.progress * 100 * 100) / 100;
$('.progressbar').css('width', percent + '%');
}
function onDone() {
clearInterval(timer);
$('.progressbar').css('visibility', 'hidden');
}
})
client.on('error', function (err) {
$('.message').addClass('show');
$('.message').html('Invalid URL');
})
}
var params = new URLSearchParams(window.location.search);
if (params.has('hash')) {
let infoHash = params.get('hash');
let magnetURI = "magnet:?xt=urn:btih:" + infoHash + "&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.fastcast.nz";
addVideo(decodeURIComponent(magnetURI));
} else {
$('.message').addClass('show');
$('.message').html('Invalid URL');
}
});
function resizeVideo() {
var video_container = $(".video-container").eq(0);
video_container.css('height', (video_container.width() * 0.56) + 'px');
}
resizeVideo();
$(window).on('resize', resizeVideo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment