Plex Library Automation — Auto-Clean Unwatched Media with n8n
If you’ve been building a Plex library for any length of time, you know how it goes. You add a movie, watch half of it, forget about it. You rip a few seasons of a show you were really into, blow through Season 1, and then life happens. Meanwhile your server storage is quietly filling up with content you haven’t touched in months. In my homelab, I only have like 2TB so it was vital that it clears out regularly.
I got tired of manually auditing my library, so I built in some plex library automation to do it for me. Here’s what it does, how I built it, and why it’s been one of the most useful things running on my home server.
The Problem
My Plex library lives on a self-hosted server running Ubuntu with Docker. Over time the media folder had grown to the point where I was manually going in every few months, sorting by date added, and deleting things I clearly wasn’t going to watch. It was tedious, error-prone, and easy to forget.
I also use Radarr and Sonarr to manage my movie and TV libraries. The problem with just deleting files manually is that Radarr and Sonarr don’t know you deleted them — so they sit there thinking the content is still monitored, which causes all sorts of confusion.
I needed something that would:
- Automatically remove movies and TV seasons I hadn’t watched in 60 days
- Tell Radarr and Sonarr what got removed so they didn’t get out of sync
- Let me protect specific content I always want to keep
- Send me a daily report so I knew what was happening
The Solution: An n8n Workflow
I built this as an n8n workflow — n8n is a self-hosted automation tool (think Zapier but running on your own machine). It runs every night at 2:00 AM and handles everything automatically.
How it decides what to delete
For movies, the logic is straightforward:
- Never watched and added more than 60 days ago → removed
- Watched but last viewed more than 60 days ago → removed
- Has a “Keep” label in Plex → never touched, no matter what
I also built in a 3-day warning window. Anything hitting 57-59 days gets flagged in my Discord before it’s actually removed, so I have a chance to add the Keep label if I change my mind.
For TV shows, it’s smarter than just “hasn’t been watched.” Deleting a whole show because you haven’t finished Season 4 yet would be a disaster. So the workflow uses what I call active season logic:
It finds the highest season where you’ve actually watched at least one episode — that’s your active season. Everything above and including that season is completely safe. Only seasons below your active season are candidates for removal, and only if all their episodes are 60+ days old.
So if you’re currently watching Season 3 of something, Seasons 1 and 2 might eventually be cleaned up — but Season 3 and anything above it is untouched. If you’ve never watched anything in a show at all, it gets treated like a movie and removed after 60 days.
The Radarr and Sonarr Integration
If you use Radarr and Sonarr to manage your libraries, you already know the anxiety of files going missing without the apps knowing about it. They’ll either throw errors, show the content as missing, or add it back to your monitored list — which completely defeats the purpose of cleaning up in the first place.
That’s why before anything gets deleted, the workflow talks to Radarr and Sonarr first and unmonitors the content. For movies it unmonitors at the movie level in Radarr. For TV it unmonitors at the season level in Sonarr — so the rest of your series stays monitored and untouched.
Your cleanup stays clean. Your libraries stay in sync.
The Discord Reports
Every morning I get two Discord messages — one for movies and one for TV — whether anything was deleted or not. If it was a quiet night, it just says “Nothing removed today.” If something got cleaned up, it lists exactly what was removed. If anything is in the 57-59 day warning window, that gets its own message with a countdown.
Having the daily report was actually more useful than I expected. It’s a nice passive way to stay aware of what’s in your library without having to go looking.
Safety Guards
A few things I made sure to build in so this couldn’t go wrong in a bad way:
- Every delete command checks that the file or folder actually exists before touching it
- There are path guards that prevent the script from accidentally targeting root-level media folders
- The Keep label in Plex is the ultimate override — anything labeled Keep is skipped unconditionally
- The workflow echoes “DELETED:” or “SKIP:” for every item so the Discord report only shows confirmed removals
Is This Available?
Yes — I packaged this up as a downloadable n8n workflow. It includes the workflow JSON file, a full README, and a variables reference that walks you through every placeholder you need to fill in. You import it into your own n8n instance, fill in your credentials, test it manually first, then activate it.
If you’re just getting started with a home server setup and want help putting something like this together — or you’re already running Plex and want to level up your automation — that’s exactly the kind of thing CookieBytes Technologies helps with. We serve the Muscle Shoals area with on-site and remote support, and we genuinely enjoy this stuff. Reach out at cookiebytestech.com or (256) 415-6844.




