TorrentScript
qBittorrent post processing script, with Subtitle extraction and cleaning, Radarr and Medusa or Sonarr Import.
Install / Use
/learn @Rouzax/TorrentScriptREADME
TorrentScript
qBittorrent post‑processing PowerShell script that imports newly downloaded media into Radarr (Movies) and Medusa or Sonarr (TV), while taking care of unpacking, remuxing, subtitle handling, cleanup, logging, and notifications.
⚠️ I'm not a programmer — use at your own risk 🙂. Tested on Windows with PowerShell 7+. Most paths below assume Windows. PowerShell 7 can run on Linux/macOS, but you’ll need equivalent tools and paths.
Description
The script processes torrent downloads by:
- Unpacking or copying files to a Temporary Processing folder defined in
config.json. - If the torrent label is a TV show (as defined in
config.jsonunderLabel.TV):- Removes unwanted subtitle languages from MKV files.
- Extracts subtitles in the wanted languages from MKV files.
- Attempts to download missing subtitles from OpenSubtitles.
- Converts subtitle language codes from ISO 639-2 (3-letter) to ISO 639-1 (2-letter) as per
LanguageCodes.json. - Cleans up SRT subtitles using Subtitle Edit:
- Removes Hearing Impaired subtitles.
- Fixes common errors.
- Starts Medusa or Sonarr import (as defined in
config.jsonunderImportPrograms.TV).
- If the torrent label is a Movie (as defined in
config.jsonunderLabel.Movie):- Performs the same subtitle processing as above.
- Starts Radarr import.
- If there is another unrecognized label, the script will simply unpack/extract the files without further processing.
- Cleans up the temporary folder after processing.
- If no label is set or if the label is
NoProcess, the script exits without processing. - Sends an email notification with the result.
Success

Medusa wrong host

Unrar error

Installation
-
Create a
config.jsonfile in the root directory of the script.
You can copy the providedconfig-sample.jsonand modify it as needed, see: https://github.com/Rouzax/TorrentScript/wiki/Configuration-file-explained for information -
Set up qBittorrent to trigger the script after downloads finish
The script should be triggered with the following command:powershell "C:\Scripts\TorrentScript\TorrentScript.ps1" -DownloadPath '%R' -DownloadLabel '%L' -TorrentHash '%I'
-
Enable per-torrent folders in qBittorrent
This setting ensures that each torrent is placed inside its own folder.
-
Configure Remote Path Mapping in Radarr/Sonarr
Radarr and Sonarr should not directly access qBittorrent's completed downloads folder. We need to trick them to look at an empty folder.Example:
- qBittorrent root download path:
C:\Torrent\Downloads\ - Radarr Remote Path Mapping:
C:\Torrent\Radarr\

This ensures that Radarr and Sonarr only imports processed media via this script.
- qBittorrent root download path:
Understanding RemotePath in config.json
The RemotePath setting in config.json ensures that Medusa, Radarr, and Sonarr receive the correct file paths when the script is executed from a different machine than where these applications are running.
How It Works
- If the script is triggered from a jumphost or another system different from the one hosting Medusa, Radarr, or Sonarr, the local file paths may not match what these applications expect.
- The
RemotePathsetting provides the correct path that Medusa, Radarr, or Sonarr should use to locate the processed files, even when the script itself is running from another machine. - This is especially useful in setups using shared storage where multiple machines have access to the same files but reference them with different paths.
Example Scenario
Assume your downloads are stored on a network share at \\NAS\Downloads\, but:
- The jumphost (where the script runs) mounts this as
D:\Downloads\ - The server running Medusa accesses the same location as
C:\TEMP\Torrent\Medusa - The server running Radarr expects
C:\TEMP\Torrent\Radarr
Required External Tools
This script relies on the following external tools, which need to be installed and defined in config.json:
| Tool | Purpose | | ------------------------------------------------------------- | ------------------------------- | | WinRAR | Extracting archives | | MKVMerge | Merging MKV streams | | MKVExtract | Extracting subtitles from MKV | | Subtitle Edit | Cleaning and renaming subtitles |
Advanced Features & Additional Notes
1. Multi-Instance Handling
- The script ensures that only one instance runs at a time.
- If multiple torrents complete while a process is already running, they wait until the first script execution is finished.
2. Subtitle Processing
- Extracts, cleans, and renames subtitles for supported languages.
- Uses
LanguageCodes.jsonto convert 3-letter language codes to 2-letter codes.
3. Logging & Error Handling
- Logs are stored in a defined path (
LogArchivePathinconfig.json). - Errors are logged and can be sent via email notifications.
4. Medusa/Radarr/Sonarr Import
- The script interacts with Medusa or Sonarr and Radarr via their API using the provided API keys.
- It ensures that only properly processed files are imported.
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
