Skip to content

Instantly share code, notes, and snippets.

@BohemianHacks
Created December 13, 2024 11:12
Show Gist options
  • Save BohemianHacks/c88ef2effad0a6e4657a86befc17175e to your computer and use it in GitHub Desktop.
Save BohemianHacks/c88ef2effad0a6e4657a86befc17175e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Browser-Based Torrent Player (Experimental)</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/peerjs.min.js"></script>
<script>
const magnetURI = "magnet:?xt=urn:btih:YOUR_MAGNET_LINK_HERE";
// Create a PeerJS instance
const peer = new Peer();
peer.on('open', function(id) {
const conn = peer.connect(id);
conn.on('open', function() {
conn.send(magnetURI);
});
});
peer.on('connection', function(conn) {
conn.on('data', function(data) {
// Handle the received magnet URI
// **Note: This is a simplified approach. For a robust solution, consider using a dedicated torrent client or a web-based torrent player.**
console.log("Received magnet URI:", data);
// You might explore using a WebRTC-based streaming solution or a specialized library to handle torrent downloads and playback.
// However, direct browser-based torrent playback is not straightforward due to browser security restrictions and the complexity of the BitTorrent protocol.
});
});
</script>
</head>
<body>
<p>This is an experimental browser-based torrent player.</p>
<p>Please note that direct browser-based torrent playback has limitations and might not work as expected in all cases.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment