Plex-Cleaner
is a Python script that can clean up your Plex directory by deleting movies and TV shows after you’ve watched them. This will stop your disk from filling up with lots of old media files over time. You can run this script on your server (or Raspberry Pi, or wherever you run Plex Media Server.)
I like to put things in the /opt
directory on my servers.
git clone https://github.com/ndbroadbent/Plex-Cleaner.git /opt
python3 PlexCleaner.py --dump Cleaner.conf
to create a new configuration fileConfigure an authentication token in Cleaner.conf
, under the "Token"
key.
Call python3 PlexCleaner.py
to test it out.
The script will run in test mode and won’t delete anything if your Cleaner.conf
contains "test": true
, or if you call python3 PlexCleaner.py --test
.
"test": false
in Cleaner.conf
.You’ll probably want to run this script regularly as a cron job. Run crontab -e
to edit your crontab, then add the following line to run the script every day at 4am:
0 4 * * * /usr/bin/python3 /opt/Plex-Cleaner/PlexCleaner.py
I always like to set up monitoring for any scheduled scripts so that I get a notification if when they stop working. healthchecks.io is my favorite monitoring tool and they have a generous free tier. (No affiliation, they’re just an awesome service.)
To set up monitoring with healthchecks.io, you can call the run_plex_cleaner.sh
script from my fork. This script will ping healthchecks.io on success or failure. healthchecks.io will also send you a notification if it doesn’t receive any ping at the expected time (e.g. if your server has been turned off.)
0 4 * * *
.healthchecksio_id
file in the Plex-Cleaner
directoryCleaner.conf
so that it writes logs to a file:"LogFile": "/opt/Plex-Cleaner/plexcleaner.log",
0 4 * * * /opt/Plex-Cleaner/run_plex_cleaner.sh
Now you’ll get an email alert whenever something goes wrong:
plexcleaner.log
log file contains any ERROR
entries