Skip to content

COttenTBL/plex-scripts

Repository files navigation

Plex Scripts Collection

Collection of utility scripts for managing and auditing Plex libraries, exporting metadata, syncing metadata across servers, and bulk file operations.

Repository Contents

  • forceanalyze.py - Queue analyze jobs for all movie and TV libraries.
  • forceanalyzetv.py - Refresh and analyze TV episodes, optionally resuming from a specific file.
  • voiceanalyzed.py - List movies in Movies that appear to be missing voice/audio analysis metadata.
  • plexUpdateMovie.py - Bulk update movie titles and sort titles from CSV.
  • UpdateMovieSort.py - Bulk update movie sort titles from an export CSV.
  • plexMovieExport.py - Export movie metadata and file paths to CSV.
  • plexTvExport.py - Export detailed TV episode metadata and file paths to CSV.
  • plexGetTVShows.py - Export show-level TV metadata and source paths to CSV.
  • findDups.py - Print movies with multiple media files.
  • optimize4K.py - Request Plex optimized versions for detected 4K movies.
  • nothumbnails.py - Find movies missing thumbnails through Plex XML API endpoints.
  • deleteThumbnails.py - Delete video preview thumbnails for TV Shows.
  • tvPoster.py - Download and save show/episode posters to media folders.
  • file_rename.py - Move/rename files in bulk from CSV mapping.
  • plexsync/plex_sync.py - Combined poster download + optional metadata sync between source/target Plex servers.

Prerequisites

  • Python 3.9+ recommended
  • Access to Plex server(s) and valid token(s)
  • Network access from the machine running scripts to Plex server URL(s)

Install dependencies:

pip install plexapi requests

Important Safety Notes

  • Several scripts currently contain hardcoded server URLs, tokens, and absolute file paths.
  • Before running anything, replace credentials and paths with your values.
  • Consider moving secrets to environment variables and never committing real tokens.
  • Test on a small subset/library first before full-library runs.

Common Plex Configuration

Most scripts expect:

  • Plex URL, example: http://192.168.1.1:32400
  • Plex token (from your Plex account/server)
  • Existing library names (for example Movies, TV Shows)

If names differ on your server, update the script constants accordingly.

Script Usage

forceanalyze.py

Queues analyze() for every item in every movie/show library section.

  • Retries on read timeout (max_retries=3)
  • Adds a 2-second delay between requests

Run:

python forceanalyze.py

forceanalyzetv.py

Refreshes and analyzes TV episodes in all show libraries.

  • Can resume from a hardcoded start_file
  • Skips episodes until that file is found

Run:

python forceanalyzetv.py

voiceanalyzed.py

Scans Movies and prints titles where no stream appears to include audioChannelLayout on stream type 3.

Run:

python voiceanalyzed.py

plexUpdateMovie.py

Bulk updates movie titles and sort titles by rating_key from CSV.

Expected CSV columns:

  • rating_key
  • new_title
  • sort_title

Default CSV path in script: C:/Users/craig/Downloads/movie_titles.csv

Run:

python plexUpdateMovie.py

UpdateMovieSort.py

Loads plex_movies_export.csv and updates titleSort for matching Plex ID.

Expected CSV columns:

  • Plex ID
  • Title Sort

Run:

python UpdateMovieSort.py

plexMovieExport.py

Exports movie details to plex_movies_export.csv.

Output columns:

  • Plex ID
  • Title
  • Year
  • Title Sort
  • Collections
  • Edition
  • IMDb ID
  • File Path(s)

Run:

python plexMovieExport.py

plexTvExport.py

Exports detailed episode data from TV Shows to CSV.

Default output path: C:/Users/craig/Downloads/tv_library_info.csv

Output includes show/season/episode metadata, IMDb IDs, raw file path, shell-quoted path, and file-friendly title.

Run:

python plexTvExport.py

plexGetTVShows.py

Exports one row per TV show to tv_shows.csv in the current working directory.

Output columns:

  • Title
  • Year
  • Folder Friendly Name
  • IMDb ID
  • TheTVDB ID
  • TV Show Path

Run:

python plexGetTVShows.py

findDups.py

Prints movies where len(movie.media) > 1 (potential duplicate/multi-file entries).

Run:

python findDups.py

optimize4K.py

Finds movies with detected 4K resolution and calls Plex optimize() with preset "4K Optimized".

Notes:

  • Preset name must exist in your Plex environment.
  • Resolution detection depends on media.videoResolution.

Run:

python optimize4K.py

nothumbnails.py

Uses direct Plex XML API requests to identify movies missing thumbnail metadata.

Run:

python nothumbnails.py

deleteThumbnails.py

Calls deleteMediaPreviews() on the TV Shows library.

Run:

python deleteThumbnails.py

tvPoster.py

Downloads and writes show/episode poster images into media folders.

Behavior highlights:

  • Creates/uses poster.jpg at show folder level
  • Writes episode poster files named like:
    <Show Title> (YEAR) - sXXeYY - poster.jpg
  • Skips existing files

Important:

  • Script currently prepends '/Volumes/Media' to derived media paths. This is platform/path specific and likely needs adjustment on Windows/Linux.

Run:

python tvPoster.py

file_rename.py

Bulk move/rename using CSV mappings.

Expected CSV columns:

  • old_path
  • new_path

Default CSV path in script: C:/Users/craig/Downloads/file_paths.csv

Run:

python file_rename.py

plexsync (Docker and CLI)

plexsync/plex_sync.py supports:

  • Downloading movie/show/episode posters from source Plex
  • Optional metadata sync (title + sort title) from source to target Plex using library mapping

Command Line Arguments

python plexsync/plex_sync.py --source-url http://SOURCE:32400 --source-token TOKEN

Optional:

  • --target-url http://TARGET:32400
  • --target-token TARGET_TOKEN
  • --media-path /media
  • --skip-posters
  • --skip-sync
  • --library-mapping '{"Movies":"Peliculas","TV Shows":"Series"}'
  • --library-mapping-file plexsync/library_mapping.json

Environment Variables

  • PLEX_SOURCE_URL
  • PLEX_SOURCE_TOKEN
  • PLEX_TARGET_URL
  • PLEX_TARGET_TOKEN
  • MEDIA_PATH (default /media)
  • LIBRARY_MAPPING (JSON string)
  • LIBRARY_MAPPING_FILE (path to JSON file)

Docker Compose

From plexsync/:

docker compose up --build

Current compose files:

  • Mount media path to /media
  • Mount library_mapping.json to /app/library_mapping.json
  • Set source/target Plex env vars

Update docker-compose.yml values before running in your environment.

Recommended Next Improvements

  • Replace all hardcoded tokens/URLs with environment variables.
  • Add requirements.txt (or pyproject.toml) with pinned dependencies.
  • Add a dry-run mode to destructive/bulk-update scripts.
  • Add logging and per-script argument parsing (argparse) for safer repeated use.

About

Collection of custom plexapi scripts I use for various maintenance and data pulls from my plex library.

Resources

Stars

Watchers

Forks

Contributors