Metadata-Version: 2.4 Name: plex-reaper Version: 0.1.0 Summary: Find and prune unwatched, low-rated content from your Plex library, with Radarr/Sonarr integration. Author: Aubrey License: MIT License Copyright (c) 2026 Aubrey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Project-URL: Homepage, https://github.com/alewman/plex-reaper Project-URL: Issues, https://github.com/alewman/plex-reaper/issues Keywords: plex,radarr,sonarr,cleanup,media,library Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: End Users/Desktop Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Topic :: Multimedia :: Video Classifier: Topic :: Utilities Requires-Python: >=3.9 Description-Content-Type: text/markdown License-File: LICENSE Provides-Extra: config Requires-Dist: PyYAML>=6.0; extra == "config" Requires-Dist: python-dotenv>=1.0; extra == "config" Provides-Extra: dev Requires-Dist: pytest>=7; extra == "dev" Requires-Dist: ruff>=0.4; extra == "dev" Dynamic: license-file # PlexReaper [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/) [![Code style: ruff](https://img.shields.io/badge/lint-ruff-%23261230)](https://github.com/astral-sh/ruff) > Reap what your Plex library has sown โ€” find and prune unwatched, low-rated content. PlexReaper scans your Plex Media Server library for content nobody has watched, cross-references it with **Radarr** / **Sonarr**, and (on your command) unmonitors the entries and deletes the files โ€” leaving the `*arr` database entry intact so the content can be re-requested later via tools like Ombi or Overseerr. It never deletes anything on its own: you review a plain-text selection list and mark the items you want gone with `[X]`. ## Why another Plex cleanup tool? Most existing cleanup tools focus on **pruning what you've already watched** โ€” you saw the show, now free up the space. PlexReaper inverts that: > **Find old content that nobody on the server has *ever* watched and is > probably not worth watching anyway.** That's the sweet spot for shared Plex servers where disk is tight: low-rated movies that have been sitting idle for 2+ years, obscure shows the original requester forgot about, the direct-to-streaming 3.4-rated comedy nobody ever queued up. Combine a rating ceiling (`--max-rating 5`), an age floor (`--min-days 730`), and the never-watched flag, and you get a reliably uninteresting pile of gigabytes. Other things that make this tool different: - **Aggregates watch history across all users**, not just yours. - **Selection-list workflow**: review candidates in a text file, mark with `[X]`, then execute. Every deletion is reviewed. - **`*arr` integration preserves re-requestability**: the files go away but the Radarr/Sonarr database entry stays, so end users can re-request through [Ombi](https://ombi.io/) or [Overseerr](https://overseerr.dev/) if it turns out someone did want it. - **Two backends**: read the Plex SQLite DB directly (fast) or hit the HTTP API (no filesystem access needed). - **Tiny**: zero runtime dependencies in the core, single CLI, no Docker, no web UI, no background daemon. If you want a polished web-based manager, [Maintainerr](https://github.com/jorenn92/Maintainerr) is a better fit. ## Features - ๐Ÿ“Š **Accurate watch tracking** โ€” aggregates views across all users on your server (not just your own account). - ๐Ÿ—‚๏ธ **Two backends** โ€” query the Plex SQLite database directly (fastest) or use the HTTP API (no filesystem access required). - ๐Ÿ›ก๏ธ **Protection rules** โ€” exclude entire libraries, genres (`Sport`, `Documentary`, โ€ฆ), or title regex patterns (e.g. `IMAX`, `3D`). - โœ๏ธ **Human-in-the-loop** โ€” every deletion is reviewed in a text file before it happens. - ๐Ÿ” **Safe for re-requests** โ€” `*arr` database entries are kept (only the underlying files are removed), so end users can re-request via Ombi/Overseerr without issue. - ๐Ÿงช **Dry-run mode** on every destructive operation. ## Install > Not yet on PyPI. Install from source: ```bash git clone https://github.com/alewman/plex-reaper.git cd plex-reaper pip install -e '.[config]' # adds YAML + .env support # or for development: pip install -e '.[config,dev]' ``` Python 3.9+ is required. The core package has **zero runtime dependencies**; the `[config]` extra adds `PyYAML` and `python-dotenv`. ## Configure 1. Copy `.env.example` to `.env` and fill in API keys: ```env PLEX_URL=http://192.168.1.10:32400 PLEX_TOKEN=xxxxxxxxxxxxxxxxxxxx RADARR_URL=http://localhost:7878 RADARR_API_KEY=xxxxxxxxxxxxxxxxxxxx SONARR_URL=http://localhost:8989 SONARR_API_KEY=xxxxxxxxxxxxxxxxxxxx ``` > **Finding your Plex token:** 2. *(Optional)* Copy `cleanup_config.example.yaml` to `cleanup_config.yaml` for library / genre / pattern protections. 3. Verify connectivity: ```bash plex-reaper --test-connections ``` ## Usage ### Discover your library IDs ```bash plex-reaper --list-libraries ``` ### Generate a selection list Using the Plex HTTP API (no DB file needed): ```bash plex-reaper --use-api \ --selection-list candidates.txt \ --libraries 2,3 \ --never-watched \ --min-days 730 \ --max-rating 5.0 \ --exclude-genres "Sport,Documentary" ``` Or against a copy of the Plex database (much faster on big libraries): ```bash plex-reaper /path/to/com.plexapp.plugins.library.db \ --selection-list candidates.txt \ --never-watched --min-days 730 --max-rating 5.0 ``` > โš ๏ธ **Always work on a copy of the Plex database.** The live file is opened by > the Plex server and may be in an inconsistent state. PlexReaper opens the DB > read-only, but copying also protects you from accidental `fsync` lag. ### Review & edit the selection list Open `candidates.txt`. Change `[ ]` to `[X]` on anything you actually want to delete. ```text [ ] | 1.42 GB | 2.1 | Bad Movie (2020) | Movies | Action | tmdb:12345 [X] | 8.50 GB | 3.2 | Another Bad Movie (2019) | Movies | Horror | tmdb:67890 [P] | 4.20 GB | Movie | Protected Sports Doc (2021) | Sport ``` Markers: | Marker | Meaning | | ------ | ------------------------------------- | | `[ ]` | Not selected โ€” will be kept | | `[X]` | Selected for deletion | | `[P]` | Protected โ€” ignored even if edited | ### Preview, then execute ```bash plex-reaper --process-selection candidates.txt --dry-run # preview plex-reaper --process-selection candidates.txt # do it ``` ### Fully automatic cleanup If you trust your protection rules, you can skip the selection step: ```bash plex-reaper --arr-cleanup --config cleanup_config.yaml --dry-run ``` ## Example output ``` $ plex-reaper --use-api --selection-list candidates.txt \ --libraries 2 --never-watched --min-days 730 --max-rating 5 Loaded environment from: /home/you/plex-reaper/.env Using Plex API... Fetching watch history for view counts... Found 412 shows and 1173 movies with watch history Selection list exported to: candidates.txt Movies: 284 (967.41 GB) Shows: 17 (412.08 GB) Protected: 63 (not selectable) ``` And the file itself: ``` ========================================================================================== PLEXREAPER โ€” SELECTION LIST Generated: 2026-04-19 14:22:08 ========================================================================================== MOVIES (284 items, 967.41 GB total) ------------------------------------------------------------------------------------------ [ ] | 8.72 GB | 3.4 | Cats (2019) | Movies | Comedy | tmdb:568124 [ ] | 7.14 GB | 2.1 | Jack and Jill (2011) | Movies | Comedy | tmdb:71805 [ ] | 5.90 GB | 4.8 | Gods of Egypt (2016) | Movies | Action | tmdb:295693 ... TV SHOWS (17 items, 412.08 GB total) ------------------------------------------------------------------------------------------ [ ] | 48.20 GB | 4.9 | Some Forgotten Procedural (2014) | TV | Drama | tvdb:278899 ... ========================================================================================== PROTECTED ITEMS (not eligible for deletion) โ€” 63 items ------------------------------------------------------------------------------------------ [P] | 12.10 GB | Movie | Some Surfing Documentary (2018) | Sport, Documentary ``` ## How it works ```mermaid flowchart LR A[Plex DB / API] -->|MediaItem[]| B[filters.partition_candidates] B --> C[candidates] C -->|write_selection_list| D[candidates.txt] D -->|you edit [X]| D D -->|parse_selection_file| E{execute} E -->|movies| F[Radarr
unmonitor + delete files] E -->|shows| G[Sonarr
unmonitor + delete files] ``` ## Safety - Two-step, human-in-the-loop workflow by default. - The Plex database is opened **read-only** (`sqlite:...?mode=ro`). - `*arr` deletions remove *only the media files* (via `moviefile`/`episodefile` endpoints) โ€” the metadata entry is kept so re-requests still work. - `--dry-run` on every destructive subcommand. - Protected items (`[P]`) are ignored even if someone edits the flag in the selection file. ### Reversing a cleanup There is no undo. Deleted files are gone. To restore content, re-monitor the item in Radarr/Sonarr and trigger a search, or have a user re-request via Ombi/Overseerr โ€” the `*arr` database entry was preserved precisely for this. ## Threat model PlexReaper takes API keys with **delete permission** on Radarr and Sonarr. Be aware of what it can and cannot do: **What it can do** - Read every item in your Plex library and every user's watch history. - Delete media files via `DELETE /api/v3/moviefile/{id}` (Radarr) and `DELETE /api/v3/episodefile/{id}` (Sonarr). - Set `monitored = false` on movies and series. **What it will NOT do** - Delete the `*arr` database entry itself (so re-requests still work). - Touch your Plex server directly โ€” all destructive actions go through Radarr/Sonarr, never through the Plex API or DB. - Write to the Plex database (it's opened read-only). - Bypass protected items, even if someone manually edits the `[P]` flag in a selection file. - Phone home. There is no telemetry, no update check, no network call other than to the hosts you configure. **What you should do** - Put `.env` in `.gitignore` (already done in this repo) and never commit it. - Use the **least-privileged** Radarr/Sonarr API key you can โ€” these services only have one tier, but at least keep the key off public services. - Always `--dry-run` first against a new library or new filter settings. - Back up the Plex SQLite DB before running anything destructive for the first time, even though we don't touch it. ## Known limitations / architecture notes - The HTTP API backend is slower for large show libraries because Plex requires an extra call per show to sum episode sizes (`/library/metadata/{id}/allLeaves`). - View counts from the API use `/status/sessions/history/all`, which is limited by the retention of your Plex history. The DB backend is authoritative. - The selection-list format is plain text (human-friendly, fragile by definition). Scripts should use the Python API in `plexreaper.selection`. - No rate limiting on `*arr` requests. With ~1000 item cleanups you may want to add a sleep if your `*arr` instance runs on constrained hardware. ## Development ```bash pip install -e '.[config,dev]' pytest ruff check plexreaper tests ``` Contributions welcome. See [AGENTS.md](AGENTS.md) for conventions (it's also what AI assistants are instructed to follow when working in this repo). ## License [MIT](LICENSE) โ€” do whatever you want, no warranty.