Created
August 9, 2020 13:50
-
-
Save daslicht/485fc17f8a692c3cccfb203a88064874 to your computer and use it in GitHub Desktop.
Revisions
-
Marc Wensauer created this gist
Aug 9, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ $(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);