Torrent System β
TuneCamp integrates WebTorrent to allow administrators to download music via magnet links and automatically import it into the library.
1. Architecture β
The system is managed by the TorrentService (src/server/modules/integrations/torrent.service.ts), which wraps a WebTorrent client instance.
No in-app search. Searching public trackers from the server was removed: it relied on reaching ThePirateBay/
apibay.org, which is blocked at the ISP level in many regions (e.g. Italy/AGCOM), so it silently returned zero results. The Content Search β WebTorrent tab now links out to external torrent search engines; the user copies a magnet and pastes it into the "Add magnet" box, which downloads via WebTorrent independently of any blocked host.
Opt-in: Like Soulseek, the torrent plugin is disabled by default for legal reasons and must be enabled explicitly from the Admin panel.
Key Components β
- WebTorrent Client: Handles the peer-to-peer download protocol.
- SQLite Persistence: Torrent metadata (infoHash, magnet URI, status) is stored in the database to allow resuming downloads after a server restart.
- Auto-Scanner Integration: Once a torrent finishes downloading, the service automatically triggers the
Scannerto process any detected audio files and add them to the TuneCamp catalog.
2. Directory Structure β
Torrents are downloaded into a dedicated subdirectory to prevent the main library scanner from picking up incomplete files:
- Path:
music/downloads/torrents/
3. API Routes β
Admin-only routes are available under /api/admin/torrents:
GET /: Returns a list of all torrents (active and stored in DB) with their current progress, speeds, and file list.POST /add: Adds a new magnet link to the download queue.DELETE /:infoHash: Removes a torrent. Optional query param?deleteFiles=truewill also remove the downloaded data from disk.
4. Automation Flow β
- Addition: Admin submits a magnet URI.
- Metadata: The client fetches torrent metadata (name, file list).
- Download: Files are downloaded to the torrent directory.
- Completion: When 100% reached, the
doneevent is fired. - Import: The service iterates through files. Any file with a valid audio extension (
.mp3,.flac, etc.) is passed toscanner.processAudioFile. - Library Update: The scanner moves/copies the file to the library and updates the database.
5. Finding torrents β
In-app search has been removed (see the note in Β§1). The WebTorrent tab in Content Search instead lists external search engines (BTDigg, 1337x, Knaben, Solid Torrents, and a ThePirateBay proxy list) that open in a new tab, pre-filled with the typed query. Find a release there, copy its magnet link, and paste it into the "Add magnet" box to start the download.