coming.lk
Version:
movie
123 lines (106 loc) ⢠24.1 kB
JavaScript
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';
import WebTorrent from 'webtorrent';
const magnetLink = 'magnet:?xt=urn:btih:A2428B8DD7E523F18DE9A07E3AD868729A6713EB&dn=Kena%3A+Bridge+of+Spirits+-+Digital+Deluxe+Edition+%28v2.08+Epic+%2B+2+DLCs+%2B+2+Bonus+Soundtracks%2C+MULTi12%29+%5BFitGirl+Repack%2C+Selective+Download+-+from+17.5+GB%5D&tr=udp%3A%2F%2Fopentor.net%3A6969&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.gbitt.info%3A80%2Fannounce&tr=http%3A%2F%2Ftracker.ccp.ovh%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.ccp.ovh%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.theoks.net%3A6969%2Fannounce&tr=https%3A%2F%2Ftracker.tamersunion.org%3A443%2Fannounce&tr=http%3A%2F%2Fopen.acgnxtracker.com%3A80%2Fannounce&tr=http%3A%2F%2Fopen.acgtracker.com%3A1096%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Fcoppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337%2Fannounce'; // trimmed for readability
const torrentFolder = path.join(process.cwd(), 'torrent');
const outputFolder = path.join(process.cwd(), 'rar_parts');
const rarName = 'output_file';
const PART_SIZE_MB = 1000;
// š Animated loading after RAR split
function startRarLoadingAnimation() {
const loadingFrames = [
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 0%',
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 20%',
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 40%',
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 60%',
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 80%',
'š¦ RAR parts loading ā¬ā¬ā¬ā¬ā¬ā¬ 100%',
'ā
RAR parts successfully created!',
];
let frame = 0;
return new Promise(resolve => {
const interval = setInterval(() => {
process.stdout.write(`\r${loadingFrames[frame++]}`);
if (frame === loadingFrames.length) {
clearInterval(interval);
console.log('\n'); // move to next line
resolve();
}
}, 500); // adjust delay between steps
});
}
// Step 1: Download the torrent
function downloadTorrent() {
return new Promise((resolve, reject) => {
console.log('š Starting torrent download...');
const client = new WebTorrent();
client.add(magnetLink, { path: torrentFolder }, torrent => {
torrent.on('download', () => {
const progress = (torrent.progress * 100).toFixed(2);
const speed = (torrent.downloadSpeed / 1024 / 1024).toFixed(2);
process.stdout.write(`\rš„ ${progress}% ā ${speed} MB/s `);
});
torrent.on('done', () => {
console.log('\nā
Download complete!');
client.destroy();
resolve(torrent);
});
torrent.on('error', err => {
client.destroy();
reject(err);
});
});
});
}
// Step 2: Find downloaded file path
function findDownloadedFile() {
const files = fs.readdirSync(torrentFolder, { withFileTypes: true });
for (const ent of files) {
if (ent.isFile()) return path.join(torrentFolder, ent.name);
if (ent.isDirectory()) {
const sub = fs.readdirSync(path.join(torrentFolder, ent.name));
if (sub.length > 0) return path.join(torrentFolder, ent.name, sub[0]);
}
}
return null;
}
// Step 3: Split using WinRAR
async function splitWithWinRAR(filePath) {
return new Promise((resolve, reject) => {
console.log('\nš¦ Splitting into RAR parts...');
if (!fs.existsSync(outputFolder)) fs.mkdirSync(outputFolder);
const rarPath = `"./WinRAR/WinRAR.exe"`; // Change if WinRAR path is different
const output = path.join(outputFolder, rarName);
const cmd = `${rarPath} a -v${PART_SIZE_MB}m -m5 "${output}.rar" "${filePath}"`;
const proc = spawn(cmd, { shell: true });
proc.stdout.on('data', data => console.log(`ā¹ļø ${data.toString()}`));
proc.stderr.on('data', data => console.error(`ā ļø ${data.toString()}`));
proc.on('close', async code => {
if (code === 0) {
await startRarLoadingAnimation();
resolve();
} else {
reject(new Error(`RAR split exited with code ${code}`));
}
});
});
}
// Main Execution
(async () => {
try {
if (!fs.existsSync(torrentFolder)) fs.mkdirSync(torrentFolder);
if (!fs.existsSync(outputFolder)) fs.mkdirSync(outputFolder);
const torrent = await downloadTorrent();
const filePath = findDownloadedFile();
if (!filePath) {
console.error('ā Downloaded file not found.');
process.exit(1);
}
console.log('ā
Downloaded file:', path.basename(filePath));
await splitWithWinRAR(filePath);
console.log(`š All done! Check folder: ${outputFolder}`);
} catch (err) {
console.error('ā Error:', err.message);
}
})();