Skip to content

Maik-Wi/Plex-YouTube-Cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Plex YouTube Cleaner

A small Bash script to automatically remove watched YouTube videos from a Plex library.

This script was created for a very specific use case:

  • I download YouTube videos using the open-source tool ytdl-sub.
  • Those downloads are added into Plex as a dedicated "YouTube" library (of type TV Shows).
  • To keep Plex uncluttered, I wanted a way to automatically delete watched episodes while keeping unwatched ones intact.
  • The script is designed to run on Unraid with a Plex installation, where the available system packages are limited.
    Therefore, it has minimal dependencies: only bash, curl, and jq are required (both included in Unraid by default).

Features

  • Connects to your Plex server via the Plex API.
  • Identifies the library section by name (YouTube by default).
  • Lists all watched episodes (viewCount > 0).
  • Runs in dry-run mode by default – nothing is deleted until you explicitly enable it.
  • Optionally deletes the episodes directly from Plex once confirmed.
  • Outputs clean, human-readable logs of what would/will be removed.
  • Leaves unwatched or partially-watched episodes untouched.

Requirements

  • Plex Media Server with "Allow media deletion" enabled in the settings.
  • Dependencies: bash, curl, jq.
  • A valid Plex token and the server's base URL.

Usage

  1. Copy the script to your Unraid server (or any machine with network access to Plex).
  2. Make it executable:
   chmod +x plex-delete-watched-youtube.sh
  1. Run in dry-run mode (default):
./plex-delete-watched-youtube.sh

This will list all watched YouTube episodes that would be deleted.

  1. Actually delete them:
./plex-delete-watched-youtube.sh --delete
  1. You’ll be prompted for confirmation.

To skip the prompt:

./plex-delete-watched-youtube.sh --delete --yes

Configuration

The script uses sensible defaults but can be overridden with environment variables or CLI arguments. PLEX_URL – Plex server URL (default: http://YOURIP:32400) PLEX_TOKEN – Your Plex auth token LIB_TITLE – Library title (default: YouTube) PAGE_SIZE – API fetch size (default: 200) Example:

PLEX_URL="http://myserver:32400" \
PLEX_TOKEN="abc123" \
LIB_TITLE="YouTube" \
./plex-delete-watched-youtube.sh --delete --yes

License

This project is released under the GPL-3.0. Contributions, forks, and improvements are welcome!

About

A small Bash script to automatically remove watched YouTube videos from a Plex library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages