A robust solution for automatically processing downloaded media files from Transmission, organizing them with FileBot, and triggering Plex library updates. This project evolved from a simple cleanup script into a comprehensive media management solution.
- macOS (tested on Monterey and later)
- Plex Media Server (running locally)
- FileBot (licensed version)
- Transmission (for downloading)
- Homebrew (for installing dependencies)
- Command line tools:
- yq (
brew install yq
) - jq (
brew install jq
) - curl (usually pre-installed on macOS)
- netcat (
brew install netcat
)
- yq (
-
Clone this repository or download the scripts to your preferred location:
git clone <repository-url> cd transmission-filebot
-
Create the necessary configuration directory:
mkdir -p ~/.config/transmission-done
-
Copy the sample config file:
cp config.yml ~/.config/transmission-done/
-
Generate your Plex token:
./plex-token.sh
Follow the prompts to enter your Plex credentials. The script will provide you with a token to add to your config.yml.
-
Edit
~/.config/transmission-done/config.yml
with your settings:paths: default_home: /Users/yourusername plex: server: http://localhost:32400 token: your_plex_token_here media_path: /path/to/your/plex/media logging: file: .filebot/logs/transmission-processing.log max_size: 10485760 # 10MB in bytes
-
Configure Transmission to run the script:
- Open Transmission
- Go to Preferences (⌘,)
- Navigate to the "Downloading" tab
- Check "Run script when download completes"
- Enter the full path to
transmission-done.sh
-
Ensure the script is executable:
chmod +x transmission-done.sh chmod +x plex-token.sh
When Transmission completes a download:
- The script validates the environment and configuration
- Cleans up unwanted files (NFO, TXT, EXE)
- Uses FileBot to:
- Identify the media (TV show or movie)
- Rename files according to Plex conventions
- Move files to the appropriate Plex library folder
- Download artwork and metadata
- Import subtitles
- Triggers a Plex library scan
- Logs all actions for troubleshooting
When Transmission runs the script, it does so with a limited environment that differs from your regular shell environment. The script receives:
-
From Transmission:
TR_TORRENT_DIR
: Directory containing the downloaded filesTR_TORRENT_NAME
: Name of the downloaded torrentTR_APP_VERSION
: Transmission versionTR_TIME_LOCALTIME
: Local time of completionTR_TORRENT_HASH
: Torrent hashTR_TORRENT_ID
: Internal Transmission torrent ID
-
System Environment:
- Limited
PATH
(usually just/usr/bin:/bin:/usr/sbin:/sbin
) - No user environment variables (like those set in
.zshrc
or.bash_profile
) - No
HOME
variable by default
- Limited
This is why the script:
- Explicitly sets
PATH
to include/usr/local/bin
- Uses a configurable
default_home
in config.yml - Sources all paths from the config file rather than environment variables
If you need to debug environment issues:
# Add this near the start of the script
env > /tmp/transmission-env.log
-
Script not running after download
- Check Transmission's script path setting
- Verify script permissions (
chmod +x
) - Check the log file for errors
-
FileBot errors
- Ensure FileBot is properly licensed
- Verify FileBot is in your PATH
- Check if the target media directory exists and is writable
-
Plex not updating
- Verify your Plex token is correct
- Ensure Plex server is running
- Check server URL in config.yml
- Look for connection errors in the logs
-
Check the logs:
tail -f ~/.filebot/logs/transmission-processing.log
-
Run the test suite:
TEST_MODE=true ./transmission-done.sh
-
Verify Plex connectivity:
curl -H "X-Plex-Token: your_token" http://localhost:32400/identity
This project began as a simple "done-cleanup" script that removed unwanted files after Transmission downloads completed. Key evolution points:
- Initial Version: Basic cleanup of NFO, TXT, and EXE files
- FileBot Integration: Added automated media organization and renaming
- Plex Integration: Implemented automatic library updates
- Robust Error Handling: Added retry logic and comprehensive logging
- Configuration Management: Moved from hardcoded values to YAML configuration
- Test Suite: Added comprehensive testing capabilities
- Token Management: Added secure Plex token generation utility
The current version represents a complete rewrite with proper error handling, logging, configuration management, and extensive testing capabilities.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
MIT License - See LICENSE file for details