torrent-service
v0.1.1
Published
Aria2 powered torrent download manager plus torrent search helpers
Readme
torrent-service
An Aria2-powered torrent download manager bundled with ready-to-use torrent search helpers. Designed for Node.js 18 or newer.
Installation
Install from a local monorepo:
npm install ./packages/torrent-serviceInstall from npm (after publishing):
npm install torrent-serviceQuick start
const path = require('path');
const { TorrentManager, searchTorrents } = require('torrent-service');
const torrentManager = new TorrentManager({
mediaDir: path.join(__dirname, 'media'),
aria2Binary: process.env.ARIA2_BINARY // Optional
});
await torrentManager.readyPromise;
const results = await searchTorrents('His Girl Friday ');
const magnet = results[0]?.magnet;
if (magnet) {
const download = await torrentManager.startDownload({
magnet,
name: 'His Girl Friday (2023)',
provider: 'yts'
});
console.log(download.status); // downloading
}Configuration
| Option | Description |
| --- | --- |
| mediaDir | Root directory where downloads are stored (required). A downloads subfolder is created inside this directory. |
| libraryManager | Optional LibraryManager instance (from home-video-library) to trigger automatic rescans when a download completes. |
| aria2Binary | Path to the aria2c executable. If omitted, it is resolved from the current PATH. |
You can further tune the service with environment variables such as
ARIA2_RPC_PORT,ARIA2_RPC_SECRET,ARIA2_SESSION_FILE, etc.
Helper methods
searchTorrents(query)— Merges results from Apibay (The Pirate Bay) and YTS, returning the top 30 entries.listDownloads()— Provides a summary of active and past downloads.pauseDownload(gid),resumeDownload(gid),cancelDownload(gid)— Convenience wrappers around the Aria2 RPC commands.
Publishing
- Move into the package folder:
cd packages/torrent-service - Bump the version:
npm version patch(or minor/major as needed) - Log in to npm:
npm login - Publish:
npm publish --access public
