The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Twjwb
By Guest on 25th January 2023 02:02:44 PM | Syntax: TEXT | Views: 16



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. <html>
  2. <head>
  3.   <script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
  4.   <style>
  5.     /* Loading Animation */
  6.     #loading {
  7.       display: none;
  8.       position: absolute;
  9.       left: 50%;
  10.       top: 50%;
  11.       transform: translate(-50%, -50%);
  12.     }
  13.   </style>
  14. </head>
  15. <body>
  16.   <form onsubmit="loadTorrent(event)">
  17.     <label for="torrent-input">Enter Magnet or Torrent URL:</label>
  18.     <input type="text" id="torrent-input" name="torrent-input">
  19.     <input type="submit" value="Load Video">
  20.   </form>
  21.   <video id="videoPlayer" controls></video>
  22.   <div id="loading">
  23.     <img src="loading.gif" alt="Loading...">
  24.   </div>
  25.   <script>
  26.     function loadTorrent(event) {
  27.         event.preventDefault();
  28.         document.getElementById("loading").style.display = "block";
  29.         var torrentId = document.getElementById("torrent-input").value;
  30.         var client = new WebTorrent();
  31.         client.add(torrentId, function (torrent) {
  32.           var file = torrent.files.find(function (file) {
  33.             return file.name.endsWith('.mp4');
  34.           });
  35.           file.appendTo('#videoPlayer', function () {
  36.               document.getElementById("loading").style.display = "none";
  37.           });
  38.           torrent.on('download', function (bytes) {
  39.             console.log('just downloaded: ' + bytes);
  40.             console.log('download speed: ' + torrent.downloadSpeed);
  41.             console.log('progress: ' + (torrent.progress * 100).toFixed(1) + '%');
  42.           });
  43.         });
  44.     }
  45.   </script>
  46. </body>
  47. </html>



  • Recent Pastes
  • Questions
    13 hours 55 mins 25 secs ago
  • Adrs
    14 hours 35 secs ago
  • Docs
    14 hours 1 min 19 secs ago
  • Servs
    14 hours 2 mins 2 secs ago
  • Srvs
    14 hours 6 mins 51 secs ago