To automate the unpacking of *.rar files downloaded via qBittorrent (managed by Sonarr) to the same directory as the *.rar file, you can leverage qBittorrent’s ability to run an external program when a torrent finishes downloading. Since Sonarr doesn’t handle the extraction of compressed files like *.rar, this solution uses qBittorrent to trigger the extraction process automatically. Below are the detailed steps to set this up:
Step 1: Install an Extraction Tool
You’ll need a tool capable of extracting *.rar files installed on your system. Two popular options are:
- Unrar: A lightweight command-line tool specifically for *.rar files.
- 7-Zip (7z): A versatile tool that supports *.rar and many other archive formats.
For this guide, we’ll use unrar
as an example. Installation depends on your operating system:
For Windows
Download unrar
from the official RARLAB website (https://www.rarlab.com/rar_add.htm) and add it to your system PATH or note its installation path.
For Linux
Install via your package manager, e.g., sudo apt install unrar
(Ubuntu/Debian) or sudo yum install unrar
(CentOS).
For macOS
Install via Homebrew with brew install unrar
.
Ensure the tool is accessible from the command line by typing unrar
in a terminal or command prompt. If it’s not recognized, adjust your system PATH or use the full path to the executable in later steps.
Step 2: Configure qBittorrent to Run an External Program
qBittorrent can execute a command when a torrent finishes downloading, which we’ll use to extract the *.rar files.
- Open qBittorrent Options:
- Launch qBittorrent.
- Go to Tools Options (or Preferences on macOS/Linux).
- Navigate to the Downloads Section:
- In the left sidebar, select Downloads (highlighted with a blue background).
- Enable "Run on torrent finished":
- Scroll to the Run external program section.
- Check the box labeled Run on torrent finished. This ensures the command runs automatically when a download completes.
- Enter the Extraction Command:
- In the Run external program text box, enter the following command:
unrar x "%F/*.rar" "%F/"
- Explanation:
unrar x
: Extracts files with full paths from the *.rar archive."%F/*.rar"
: Specifies all *.rar files in the torrent’s content path (the directory where the downloaded files are saved). The%F
parameter is provided by qBittorrent and represents the content path for multi-file torrents."%F/"
: Sets the destination directory for extraction to the same location as the *.rar files.- Quotation marks ensure paths with spaces are handled correctly.
- Alternative with 7-Zip:
If you’re using 7-Zip, the command would be:
"C:\Program Files\7-Zip\7z.exe" x "%F/*.rar" -o"%F/"
Replace the path with the actual location of
7z.exe
on your system. - Full Path Note:
If
unrar
or7z
isn’t in your system PATH, use the full path, e.g.,"C:\Program Files\WinRAR\unrar.exe" x "%F/*.rar" "%F/"
on Windows.
- In the Run external program text box, enter the following command:
- Save Changes:
- Click OK or Apply to save the settings.
Step 3: Test the Setup
To ensure everything works as expected:
- Download a Test Torrent:
- Add a small torrent containing a *.rar file to qBittorrent (you can use a test file or a TV show episode managed by Sonarr).
- Wait for Completion:
- Let the download finish.
- Verify Extraction:
- Check the download directory (the content path) to confirm the *.rar file has been extracted to the same location. The extracted files should appear alongside the *.rar file.
Step 4: Ensure Compatibility with Sonarr
Since Sonarr manages your TV show downloads, the extraction must occur before Sonarr processes the files:
- Timing: qBittorrent’s “Run on torrent finished” triggers immediately after the download completes, typically before Sonarr imports the files. This should work seamlessly in most cases.
- Adjust Sonarr if Needed: If Sonarr processes files too quickly (before extraction finishes), increase the delay in Sonarr’s Download Client settings (e.g., set “Completed Download Handling” to wait a few minutes).
Step 5: Troubleshooting Common Issues
If the automation doesn’t work, check these:
- Command Syntax: Ensure the command is correct and the extraction tool is recognized. Test it manually in a terminal/command prompt with a sample *.rar file.
- Permissions: Confirm the user running qBittorrent has permission to execute
unrar
and write to the download directory. - Tool Installation: Verify
unrar
or7z
is installed and accessible. - Multiple *.rar Files: The
*.rar
wildcard handles multiple archives in the same directory. If this fails, consider a script (see below). - Console Output: Check Show console window in qBittorrent options to see error messages when the command runs.
Optional: Advanced Setup with a Script
For more control (e.g., handling multiple *.rar files or nested archives), use a script:
Windows (Batch Script)
Create extract_rar.bat
:
@echo off
for %%i in ("%1\*.rar") do "C:\Program Files\WinRAR\unrar.exe" x "%%i" "%1\"
Then set qBittorrent’s command to:
"C:\path\to\extract_rar.bat" "%F"
Linux/macOS (Bash Script)
Create extract_rar.sh
:
#!/bin/bash
for file in "$1"/*.rar; do
unrar x "$file" "$1/"
done
Make it executable (chmod +x extract_rar.sh
), then set the command to:
/path/to/extract_rar.sh "%F"
Final Notes
This setup automates the unpacking of *.rar files to the same directory as the *.rar file, integrating with your qBittorrent and Sonarr workflow. It’s simple, requires minimal setup, and uses tools you likely already have. If you encounter issues or need further customization, feel free to adjust the command or script based on your specific needs!
Was this helpful?
If you've followed this guide, we'd love to hear about your experience. Please leave a comment below to share whether this guide helped you achieve your goal. If you found an alternative approach that worked, we encourage you to share that as well. Your feedback helps us improve our documentation and assists others in the community.
Need Further Assistance?
If you need additional support or would like personalized guidance, we're here to help. Check out our dedicated support plans at IT Solver Support Plans for expert assistance tailored to your needs.
Comments
0 comments
Please sign in to leave a comment.