Turn your magnet links into direct downloads, because sharing shouldn't require a degree in computer science!
Ever tried sharing a torrent and got the response "What's a magnet link?" ๐ค This app is your savior - it converts those cryptic magnet links into normal, friendly download links!
- ๐ Real-time download progress (with fancy progress bars!)
- ๐ Dark mode (for your 3 AM downloading sessions)
- ๐ฑ Works on phones (yes, even on that old iPhone!)
- ๐จ Beautiful UI (because we're not savages)
- ๐ Individual file downloads (why wait for everything?)
- ๐ Live stats (speed, time, size - we've got all the numbers!)
Magnet-Link-To-Direct-Link-Web-App/
โโโ api/ # Backend API code
โ โโโ index.js # Main API logic
โโโ public/ # Frontend files
โ โโโ index.html # Main webpage
โ โโโ app.js # Frontend JavaScript
โโโ src/
โโโ server.js # Development server
-
index.html: Contains the user interface
<!-- Main input form --> <div class="input-group"> <input type="text" id="magnetLink" placeholder="Paste your magnet link here"> <button onclick="startDownload()">Convert</button> </div> <!-- Status display area --> <div id="status"></div>
-
app.js: Handles user interactions
// When user clicks "Convert" function startDownload() { const magnetLink = document.getElementById('magnetLink').value; // Send magnet link to server fetch('/api/download', { method: 'POST', body: JSON.stringify({ magnet: magnetLink }) }); } // Check download progress every second setInterval(() => { checkStatus(); }, 1000);
- Main Components:
// 1. Setup WebTorrent client const client = new WebTorrent({ uploadLimit: ENABLE_UPLOAD ? -1 : 1024, // Control upload speed maxConns: PEER_LIMIT // Control connections }); // 2. Handle new download requests handler.post('/api/download', (req, res) => { const { magnet } = req.body; // Get magnet link const downloadId = createUniqueId(); // Generate ID const torrent = client.add(magnet); // Start download // Send response to user }); // 3. Check download status handler.get('/api/status/:downloadId', (req, res) => { const torrent = downloads.get(req.params.downloadId); // Send progress info });
-
Environment Variables (
.env
)ENABLE_UPLOAD=true # Control if uploading is allowed MAX_DOWNLOADS=10 # Maximum simultaneous downloads PEER_LIMIT=50 # Maximum peer connections
- These control how the app behaves
- Can be changed without modifying code
-
API Endpoints
/api/download
: Start a new download/api/status
: Check download progress/api/downloads
: List all downloads
-
WebTorrent Basics
// Create a torrent const torrent = client.add(magnet); // Monitor progress torrent.on('download', (bytes) => { console.log('Progress:', torrent.progress); }); // When download completes torrent.on('done', () => { console.log('Download complete!'); });
-
Change Download Location
DOWNLOAD_PATH=./downloads # Change where files are saved
-
Adjust Upload Settings
ENABLE_UPLOAD=false # Disable uploading
-
Control Connections
PEER_LIMIT=30 # Reduce for slower connections
- Start by understanding
public/app.js
- it's the simplest part - Look at
api/index.js
to see how downloads work - Use the environment variables to experiment with settings
- Check the logs to understand what's happening
- Use the example magnet links for testing
Need help? Check the troubleshooting section or open an issue!
Magnet-Link-To-Direct-Link-Web-App/
โโโ api/
โ โโโ index.js # API endpoints & WebTorrent logic
โโโ public/
โ โโโ index.html # Frontend UI with styles
โ โโโ app.js # Frontend JavaScript
โโโ server.js # Development server
โโโ package.json # Dependencies & scripts
โโโ vercel.json # Vercel deployment config
โโโ .gitignore # Git ignore rules
# Clone this beauty
git clone https://github.com/sh13y/Magnet-Link-To-Direct-Link-Web-App
# Jump into the folder
cd Magnet-Link-To-Direct-Link-Web-App
# Install the goodies
npm install
# Fire it up!
npm run dev
- Copy your magnet link
- Paste it in the box
- Click "Convert"
- Watch the magic happen
- Download your files
# Ubuntu 22.04 (Small)
magnet:?xt=urn:btih:3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0
# Big Buck Bunny (Medium)
magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c
# Blender Demo Files (Large)
magnet:?xt=urn:btih:a9a8257fbc7726a891e94f04500fb7c51df25e69
โ ๏ธ Important Warning: Vercel deployment is only suitable for demo/testing purposes! Vercel has strict limitations on execution time and file operations that make it unsuitable for production use of WebTorrent applications. For actual production use, please use a VPS or Docker deployment instead.
# Install Vercel CLI
npm i -g vercel
# Deploy to the cloud
vercel
# Follow the prompts...
# 1. First, install Node.js and npm on your VPS
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# 2. Clone the repository
git clone https://github.com/sh13y/Magnet-Link-To-Direct-Link-Web-App
cd Magnet-Link-To-Direct-Link-Web-App
# 3. Install dependencies
npm install
# 4. Install PM2 globally
npm i -g pm2
# 5. Start the app with PM2
pm2 start server.js --name magnet-converter --node-args="--experimental-modules"
# Or alternatively, create an ecosystem file
cat > ecosystem.config.cjs << 'EOF'
module.exports = {
apps: [{
name: 'magnet-converter',
script: 'server.js',
node_args: '--experimental-modules',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
}
EOF
# Then start using the ecosystem file
pm2 start ecosystem.config.cjs
# Other useful PM2 commands:
pm2 logs magnet-converter # View logs
pm2 status # Check status
pm2 restart magnet-converter # Restart app
pm2 stop magnet-converter # Stop app
pm2 delete magnet-converter # Remove app from PM2
# 6. Setup PM2 to start on system boot
pm2 startup
pm2 save
# 7. Optional: Setup basic firewall
sudo ufw allow 22 # SSH port
sudo ufw allow 3000 # App port
sudo ufw enable
๐ก Pro Tips for VPS:
- Use
screen
ortmux
for persistent terminal sessions- Set up SSL with Nginx or Certbot for HTTPS
- Keep your system updated:
sudo apt update && sudo apt upgrade
- Monitor disk space:
df -h
- Check system resources:
htop
# 1. Create a Dockerfile if not exists
cat > Dockerfile << 'EOF'
FROM node:18-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
EOF
# 2. Build the image
docker build -t magnet-converter .
# 3. Run for testing
docker run -p 3000:3000 magnet-converter
# 4. Run in production
docker run -d \
--name magnet-converter \
-p 3000:3000 \
-v $(pwd)/downloads:/app/downloads \
--restart unless-stopped \
magnet-converter
# 5. View logs
docker logs -f magnet-converter
# Other useful commands:
docker ps # List running containers
docker stop magnet-converter # Stop the container
docker start magnet-converter # Start the container
docker rm magnet-converter # Remove the container
๐ก Docker Pro Tips:
- Use
docker-compose
for easier management- Set up container monitoring with Portainer
- Use Docker volumes for persistent storage
- Remember to clean up old containers and images
- Is your internet alive? (
ping 8.8.8.8
) - Did you try turning it off and on again? (
npm run dev
) - Check the logs (
pm2 logs
ordocker logs
)
// Typical download speeds:
{
"Good": "> 1 MB/s",
"Okay": "500 KB/s - 1 MB/s",
"Bad": "< 500 KB/s",
"Solution": "More seeders needed!"
}
ERROR 1: "Invalid magnet link"
โ Check your magnet link format
ERROR 2: "No peers found"
โ Wait for peers or try another magnet
ERROR 3: "Download failed"
โ Check network/firewall settings
# Required
PORT=3000 # Server port
NODE_ENV=development # Environment (development/production)
# WebTorrent Settings
ENABLE_UPLOAD=true # Enable/disable uploading (true/false)
MAX_DOWNLOADS=10 # Maximum concurrent downloads
CLEANUP_TIMEOUT=3600 # Time before deleting completed downloads (seconds)
MIN_PERCENTAGE=0 # Minimum download percentage to show
MAX_PERCENTAGE=100 # Maximum download percentage to show
PEER_LIMIT=50 # Maximum peer connections
DOWNLOAD_PATH="./downloads" # Path to save downloaded files
๐ก Pro Tip: Create a
.env
file in your project root with these settings:
# Create .env file
cat > .env << 'EOF'
PORT=3000
NODE_ENV=production
ENABLE_UPLOAD=true
MAX_DOWNLOADS=10
CLEANUP_TIMEOUT=3600
MIN_PERCENTAGE=0
MAX_PERCENTAGE=100
PEER_LIMIT=50
DOWNLOAD_PATH="./downloads"
EOF
# Development
npm run dev # Start development server with hot reload
# Production
npm start # Start production server
npm run build # Build for production
# Maintenance
npm run clean # Clean temporary files
npm run logs # Show PM2 logs
- Set
ENABLE_UPLOAD=false
in.env
to disable uploading (client becomes download-only) - Set
ENABLE_UPLOAD=true
to allow uploading (default P2P behavior)
The app now properly handles download percentages:
- Prevents negative percentages
- Caps maximum percentage at 100%
- Shows accurate progress even with multiple files
Example progress display:
{
"Downloading": "45.6%", // Normal progress
"Starting": "0%", // Initial state
"Complete": "100%" // Finished download
}
- Found a bug? Open an issue with reproduction steps!
- Want to add something cool? PRs are welcome!
- Know how to make it faster? We're all ears!
If this tool saved you from explaining torrents to your non-tech friends, consider starring the repo. It's free and makes me happy! ๐
- Coffee (the real MVP)
- Stack Overflow (my second home)
- The rubber duck on my desk (best debugger ever)
- You (for reading this far! ๐)
MIT License - Go wild, just don't blame us if your downloads include cat videos instead of Linux ISOs!
Remember: With great power comes great download responsibility! ๐ฆธโโ๏ธ
Made in Ceylon ๐ฑ๐ฐ with โค๏ธ by sh13y and probably too much back pain ๐ฆด (Send help... and a better chair! ๐ช)