Skip to content

Instantly share code, notes, and snippets.

@drego85
Last active November 26, 2025 10:38
Show Gist options
  • Select an option

  • Save drego85/c8518bb15a157e6f5dd27d62c2c6c343 to your computer and use it in GitHub Desktop.

Select an option

Save drego85/c8518bb15a157e6f5dd27d62c2c6c343 to your computer and use it in GitHub Desktop.
BitTorrent Magnet Link Generator
<!-- This tool generates a BitTorrent Magnet Link based on a given hash value and optionally a custom resource name.
You can also provide the "hash" and "name" parameters as URL GET parameters,
and they will be automatically filled into the form.
Customize the trackers by editing the list below.
These will be included in the generated magnet link to ensure better availability and downloading speed.
Made with ♥ by Andrea Draghetti
This file may be licensed under the terms of of the GNU General Public License Version 3 (the ``GPL''). -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magnet Link Generator - Generate Custom Magnet Links for BitTorrent</title>
<!-- Meta tags for SEO -->
<meta name="description" content="Generate custom torrent magnet links quickly and easily. Enter an info hash and torrent name to create a personalized magnet link with the latest trackers for optimal download speed.">
<meta name="keywords" content="Torrent Magnet Link Generator, BitTorrent Magnet Link, Custom Magnet Link, Torrent Hash Generator, Online Magnet Link Creator, BitTorrent Tracker, Torrent Generator">
<meta name="author" content="Andrea Draghetti">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://magnet.draghetti.it">
<meta property="og:title" content="Torrent Magnet Link Generator - Generate Custom Magnet Links for BitTorrent">
<meta property="og:description" content="Easily create a custom BitTorrent magnet link by providing an info hash and torrent name. Automatically includes top trackers for better download performance.">
<meta property="og:image" content="https://magnet.draghetti.it/images/magnet-link-generator-thumbnail.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://magnet.draghetti.it">
<meta property="twitter:title" content="Torrent Magnet Link Generator - Generate Custom Magnet Links for BitTorrent">
<meta property="twitter:description" content="Easily create a custom BitTorrent magnet link by providing an info hash and torrent name. Includes top trackers for faster downloads.">
<meta property="twitter:image" content="https://magnet.draghetti.it/images/magnet-link-generator-thumbnail.png">
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="https://magnet.draghetti.it/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://magnet.draghetti.it/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://magnet.draghetti.it/favicon-16x16.png">
<link rel="manifest" href="https://magnet.draghetti.it/site.webmanifest">
<!-- Bootstrap CSS (version 5.3.3) with integrity check -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body class="d-flex flex-column align-items-center bg-light min-vh-100">
<div class="container bg-white shadow rounded p-4 mt-5">
<!-- Page title -->
<div class="text-center mb-4">
<h1 class="h4 fw-bold">BitTorrent Magnet Link Generator</h1>
</div>
<!-- Information section -->
<div class="text-secondary mb-4">
<p>This tool generates a BitTorrent Magnet Link based on a given hash value and optionally a custom resource name. You can also provide the "hash" and "name" parameters as URL GET parameters, and they will be automatically filled into the form.</p>
<p>Customize the trackers by editing the list below. These will be included in the generated magnet link to ensure better availability and downloading speed.</p>
</div>
<form name="form" onsubmit="update(); return false;">
<!-- Info hash input field -->
<div class="mb-3">
<label for="hash" class="form-label">Info Hash <small>(Mandatory)</small></label>
<input id="hash" type="text" class="form-control" placeholder="Enter the info hash" required>
</div>
<!-- Torrent name input field -->
<div class="mb-3">
<label for="name" class="form-label">Resource Name <small>(Optional)</small></label>
<input id="name" type="text" class="form-control" placeholder="Enter the resource name">
</div>
<!-- Generate button -->
<button type="submit" class="btn btn-primary w-100">Generate</button>
<!-- Generated Magnet Link display section -->
<div class="mt-3">
<a href="magnet:" id="link" class="text-primary fw-bold">Magnet Link</a>:
<input id="link_text" type="text" class="form-control mt-2" readonly>
</div>
<!-- Trackers list for customization -->
<div class="mb-3 mt-3">
<label for="trackers" class="form-label">Trackers to include in the magnet link:</label>
<textarea id="trackers" class="form-control" rows="6">http://tracker.opentrackr.org:1337/announce
udp://tracker.torrent.eu.org:451/announce</textarea>
<small class="form-text text-muted">These trackers are sourced from the <a href="https://github.com/ngosang/trackerslist" target="_blank">TrackersList project</a>.</small>
</div>
</form>
</div>
<!-- Footer with credit -->
<footer class="text-center mt-auto py-3 text-muted">
BitTorrent Magnet Link Generator made with ♥ by <a href="https://www.andreadraghetti.it/" target="_blank">Andrea Draghetti</a>.
</footer>
<!-- Bootstrap JS and dependencies (version 5.3.3) with integrity check -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js" integrity="sha512-7Pi/otdlbbCR+LnW+F7PwFcSDJOuUJB3OxtEHbg4vSMvzvJjde4Po1v4BR9Gdc9aXNUNFVUY+SK51wWT8WF0Gg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
/* Function to retrieve URL GET parameters */
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')).trim();
}
/* Function to auto-fill form fields if GET parameters are provided */
async function autoFillForm() {
var hashValue = getUrlParameter('hash');
var nameValue = getUrlParameter('name');
if (hashValue) {
document.getElementById("hash").value = hashValue.trim();
}
if (nameValue) {
document.getElementById("name").value = nameValue.trim();
}
// Wait for trackers to load before generating the link
await loadTrackers();
// Execute update only if hash is provided
if (hashValue) {
update();
}
}
/* Function to generate the magnet link */
function update() {
try {
var hashInput = document.getElementById("hash").value.trim().toUpperCase(); // Convert to uppercase
var nameInput = document.getElementById("name").value.trim();
// Set `name` to `hash` if it is empty
if (hashInput && !nameInput) {
document.getElementById("name").value = hashInput;
nameInput = hashInput; // Update variable
}
// Generate the magnet link
if (hashInput) {
var trackers = document.getElementById("trackers").value.match(/[^\s\|]+:\/\/[^\s\|]+/g);
var data = "magnet:" + "?xt=urn:btih:" + hashInput;
data += "&dn=" + encodeURIComponent(nameInput);
for (var t in trackers) {
data += "&tr=" + encodeURIComponent(trackers[t]);
}
document.getElementById("link").href = data;
document.getElementById("link_text").value = data;
} else {
// Clear the link_text field if hash is not present
document.getElementById("link_text").value = '';
}
} catch (e) {
alert("exception: " + e);
}
}
/* Automatically fill the form on page load if GET parameters are present */
window.onload = autoFillForm;
</script>
<script type="text/javascript">
// Function to load trackers from the external URL
async function loadTrackers() {
const url = "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt";
try {
const response = await fetch(url);
if (response.ok) {
// Get the trackers list as text
let trackersList = await response.text();
// Remove empty lines
trackersList = trackersList
.split('\n') // Split into an array of lines
.filter(line => line.trim() !== '') // Remove empty lines
.join('\n'); // Rejoin into a single string
document.getElementById("trackers").value = trackersList;
} else {
console.error("Failed to load trackers: " + response.status);
}
} catch (error) {
console.error("Error fetching trackers: ", error);
}
}
// Load trackers on page load
window.onload = function() {
autoFillForm(); // Existing function to autofill form fields if URL parameters are provided
loadTrackers(); // Load trackers from the external source
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment