This script watches a specified directory for new .torrent files and adds them to Transmission for downloading. The download directory is determined based on the folder structure of the watched directory.
This means that when you use this script to watch the directory ./torrents which has the following structure:
- torrents/
- Movies/
- TVShows/
- Anime/
- Audio/
and configure download to /media/(basedir).
When you upload a .torrent file to ./torrents/Movies/ - the script will add it to transmission to download to /media/Movies/.
When you upload a .torrent file to ./torrents/TVShows/Anime/ - the script will add it to transmission to download to /media/TVShows/Anime/.
When you upload a .torrent file to ./torrents - the script will add it to transmission to download to /media/.
When the script successfully adds a .torrent file to transmission, it'll delete it from the --watch-dir directory.
If adding fails 5 times, the file will be renamed to {name}.failed and an additional {name}.traceback will be created with the last error.
The purpose of this script is to automate the process of adding .torrent files to Transmission and organizing the downloads into a specified base directory, preserving the folder structure.
- Python 3.10+
systemdif using the provided method of autostart
Note: It's advised to run this script as the same user as transmission-daemon. This way the majority of settings will be picked up automatically.
-
Clone the repository (or copy the script to your desired location):
git clone <repository-url> cd <project-directory>
-
Create a virtual environment:
python3 -m venv ~/.transmission-dir-watcher-env source ~/.transmission-dir-watcher-env/bin/activate
-
Install the required packages:
pip install . --force-reinstall -
Create a systemd user unit file:
Replace
your_password,/path/to/watch/folder, and/path/to/base/download/dirwith your desired locations.[Unit] Description=Watch directory for torrent files and add to Transmission After=network-online.target Wants=network-online.target [Service] Type=simple Environment=TRANSMISSION_RPC_PASSWORD=your_password ExecStart=%h/.transmission-dir-watcher-env/bin/transmission-dir-watcher --watch-dir /path/to/watch/folder --download-basedir /path/to/base/download/dir Restart=on-failure [Install] WantedBy=default.target
Save the above content in
~/.config/systemd/user/transmission-dir-watcher.service.
torrent-watcher --watch-dir ~/mnt/gdrive-torrents/ --download-basedir /media/data/
-
Reload systemd and start the service:
systemctl --user daemon-reload systemctl --user enable --now transmission-dir-watcher.service # Make the service start at boot and keep running irrespective of current user login loginctl enable-linger
-
Transmission Settings:
By default, the script sources Transmission settings from
~/.config/transmission-daemon/settings.json. Ensure this file contains the correct settings forrpc-bind-address,rpc-port, andrpc-username.You can override the settings file location with
--transmission-settings-pathcli argument. -
Environment Variable:
Set the
TRANSMISSION_RPC_PASSWORDenvironment variable to your Transmission RPC password:export TRANSMISSION_RPC_PASSWORD=your_password
Run the script with the following command (assuming you still have the python virtual environment active):
transmission-dir-watcher --watch-dir /path/to/watch/folder --download-basedir /path/to/base/download/dirBy default, the script scans the directory every 5 seconds. This can be changed by setting the desired number of seconds in the --poll-interval argument.