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.
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.
-
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:
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.
- 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.
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
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 |
- 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.
- Extracts, cleans, and renames subtitles for supported languages.
- Uses
LanguageCodes.jsonto convert 3-letter language codes to 2-letter codes.
- Logs are stored in a defined path (
LogArchivePathinconfig.json). - Errors are logged and can be sent via email notifications.
- 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.





