- Celana Pendek Merah -
1. Update Sistem
sudo apt update && sudo apt upgrade -y
2. Install Node.js dan npm
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
3. Install WebTorrent
mkdir -p $HOME/.npm-global
npm config set prefix $HOME/.npm-global
echo 'export PATH=$HOME/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
npm install -g webtorrent-cli
# Buat Server Node.js untuk Streaming
1. Buat Folder dan File Server
mkdir ~/webtorrent-server && cd ~/webtorrent-server
2. Tambahkan Kode Berikut ke server.js
const express = require('express');
const fs = require('fs');
const path = require('path');
// Fungsi async untuk mengimpor WebTorrent secara dinamis
(async () => {
const WebTorrentModule = await import('webtorrent');
const WebTorrent = WebTorrentModule.default;
const app = express();
const client = new WebTorrent();
const magnetURI = '[MAGNET:LINK]'; // Ganti dengan magnet link film
client.add(magnetURI, { path: 'downloads' }, (torrent) => {
console.log(`Downloading: ${torrent.name}`);
const file = torrent.files.find(file => file.name.endsWith('.mp4'));
if (file) {
const filePath = path.join(__dirname, 'downloads', file.name);
file.createReadStream().pipe(fs.createWriteStream(filePath));
app.get('/stream', (req, res) => {
const stat = fs.statSync(filePath);
res.writeHead(200, { 'Content-Type': 'video/mp4' });
fs.createReadStream(filePath).pipe(res);
});
console.log('Streaming available at: http://[IP SERVER]:3000/stream');
}
});
app.listen(3000, () => console.log('Server running on port 3000'));
})();
3. Install Express dan WebTorrent di Project
npm install express webtorrent
4. Jalankan Server
node server.js
5. Akses di Browser di Host
Buka http://[IP SERVER]:3000/stream
https://radio.niklaus.web.id/live