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.confto create a new configuration file
Configure an authentication token in
Cleaner.conf, under the
python3 PlexCleaner.py to test it out.
The script will run in test mode and won’t delete anything if your
"test": true, or if you call
python3 PlexCleaner.py --test.
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_idfile in the
Cleaner.confso that it writes logs to a file:
0 4 * * * /opt/Plex-Cleaner/run_plex_cleaner.sh
Now you’ll get an email alert whenever something goes wrong:
plexcleaner.loglog file contains any