Purgearr is a Python-based tool that interacts with Sonarr and Radarr APIs to manage and delete media files based on configurable criteria such as file age and tags. This script helps maintain your media library by automatically purging old files that are no longer needed, while allowing you to preserve certain shows or movies using the "keeper" tag in Sonarr, Radarr, Overseerr, Jellyseerr.
- Automatic Deletion: Delete media files older than 90 days.
- Test Mode: Simulate the deletion process to preview what files would be removed.
- Intelligent Season-Monitoring: Deactivates monitoring of fully deleted seasons.
- Tag Exclusion: Protect shows and movies tagged with "keeper" from deletion.
- Customizable: Set custom cut-offs and/or keeper tags within the script.
- Python 3.8+
- Sonarr and Radarr installations
- API keys for both Sonarr and Radarr
-
Clone the repository:
git clone https://github.com/h3rb1n4t0r/purgearr.git cd purgearr -
Install required Python packages:
pip install requests
-
Update the
Purgearr.pyscript with your Sonarr and Radarr API keys and URLs:SONARR_API_KEY = 'your_sonarr_api_key' RADARR_API_KEY = 'your_radarr_api_key' SONARR_URL = 'http://sonarr.yourdomain.com:8989/api/v3' RADARR_URL = 'http://radarr.yourdomain.com:7878/api/v3'
- The script is set to delete files older than 90 days. You can adjust this by changing the
cutoff_datevalue in the script. - The default tag for exclusion is
"keeper". To modify this, update theEXCLUDE_TAGvariable in the script.
EXCLUDE_TAG = 'keeper'Run the script in test mode to preview which files would be deleted without making any actual changes:
python3 Purgearr.py --testRun the script to permanently delete files older than 90 days:
python3 Purgearr.pyTo automate the execution of Purgearr, you can set up a cronjob that runs the script at a specific time interval. Here's how to do it:
-
Open the crontab editor:
crontab -e
-
Add a cronjob entry to run Purgearr daily at midnight (00:00). Modify the path to the script based on its location on your system:
0 0 * * * /usr/bin/python3 /path/to/Purgearr.py >> /path/to/log/purgearr.log 2>&1
This cronjob does the following:
- Runs the script every day at midnight (00:00).
- Logs both standard output and errors to
purgearr.logfor troubleshooting and monitoring.
-
Save and exit the crontab editor.
Purgearr supports excluding media from deletion by using tags. If a show or movie is tagged with keeper, the file will be skipped.
You can add the "keeper" tag in Sonarr or Radarr:
- Go to the series/movie page.
- Navigate to the tags section.
- Add or create the tag "keeper".
If you find a bug or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the GNU General Public License v3.0.
Under the GPL, you are free to use, modify, and distribute this software, provided that any derivative works are also distributed under the same license.