A Python tool that analyzes your Plex movie library and provides personalized movie recommendations based on your viewing preferences.
-
Library Analysis: Get detailed statistics about your movie collection
- Genre distribution
- Top directors and actors
- Movies by decade
- Average ratings
-
Smart Recommendations: Get movie suggestions based on:
- Your favorite genres
- Directors you love
- Actors frequently in your library
- Your preferred time periods
- Hidden gems matching your taste
Follow these steps to get up and running on macOS:
Press Cmd + Space to open Spotlight, type "Terminal", and press Enter.
python3 --versionIf you see a version number (e.g., Python 3.11.4), skip to Step 4.
If you get "command not found", proceed to Step 3.
Option A: Using Homebrew (recommended)
First, install Homebrew if you don't have it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Then install Python:
brew install pythonOption B: Direct Download
Download Python from python.org and run the installer.
# Navigate to your home folder (or wherever you want to store the project)
cd ~
# Clone the repository
git clone https://github.com/dwchal/plex_analysis.git
# Enter the project directory
cd plex_analysisOr download the ZIP from GitHub and extract it.
This keeps the project dependencies isolated:
# Create virtual environment
python3 -m venv venv
# Activate it
source venv/bin/activateYou'll see (venv) appear at the start of your terminal prompt.
pip install -r requirements.txt- Open your browser and go to app.plex.tv
- Sign in to your Plex account
- Play any movie and click on the "Get Info" or info icon
- Click "View XML" at the bottom of the info panel
- Look at the URL in your browser - find
X-Plex-Token=XXXXXX - Copy the token value (the part after the
=)
- Go to themoviedb.org and create a free account
- Go to Settings (click your profile icon) > API
- Click "Create" or "Request an API Key"
- Choose "Developer" and fill out the form (for personal use, the details don't matter much)
- Copy your API Key (not the "API Read Access Token")
- If Plex runs on your Mac:
http://localhost:32400 - If Plex runs on another machine:
http://YOUR_SERVER_IP:32400- Find the IP in Plex Settings > Network, or check your router
Basic analysis (no recommendations):
python3 plex_analyzer.py \
--plex-url http://localhost:32400 \
--plex-token YOUR_PLEX_TOKENWith movie recommendations:
python3 plex_analyzer.py \
--plex-url http://localhost:32400 \
--plex-token YOUR_PLEX_TOKEN \
--tmdb-key YOUR_TMDB_API_KEY \
--recommendations 20Save results to files:
python3 plex_analyzer.py \
--plex-url http://localhost:32400 \
--plex-token YOUR_PLEX_TOKEN \
--tmdb-key YOUR_TMDB_API_KEY \
--recommendations 20 \
--output ~/Desktop/my_library_analysis.json \
--rec-output ~/Desktop/movie_recommendations.jsonTo avoid typing credentials every time, add them to your shell profile:
# Open your shell profile in a text editor
nano ~/.zshrcAdd these lines at the end:
export PLEX_URL="http://localhost:32400"
export PLEX_TOKEN="your-plex-token-here"
export TMDB_API_KEY="your-tmdb-api-key-here"Save (Ctrl+O, Enter) and exit (Ctrl+X), then reload:
source ~/.zshrcNow you can simply run:
python3 plex_analyzer.py --recommendations 20"command not found: python3"
- Make sure Python is installed (Step 3)
- Try
pythoninstead ofpython3
"Connection refused" or "Unable to connect"
- Verify your Plex server is running
- Check the URL and port are correct
- Make sure your firewall allows connections
"Invalid token" or "Unauthorized"
- Get a fresh token from Plex (tokens can expire)
- Make sure you copied the entire token
"No movie libraries found"
- Use
--list-librariesto see available libraries - Specify the correct library name with
--library "Library Name"
pip install -r requirements.txt- Sign in to Plex Web App
- Browse to any media item and click "Get Info"
- Click "View XML" in the modal
- Look for
X-Plex-Tokenin the URL
Or use the Plex Token Guide
- Create an account at TMDB
- Go to Settings > API
- Request an API key (free for personal use)
# Using direct Plex connection
python plex_analyzer.py --plex-url http://localhost:32400 --plex-token YOUR_TOKEN
# Using MyPlex account
python plex_analyzer.py --username email@example.com --password yourpassword# Get 20 movie recommendations
python plex_analyzer.py --plex-url http://localhost:32400 --plex-token YOUR_TOKEN \
--tmdb-key YOUR_TMDB_KEY --recommendations 20You can set credentials via environment variables:
export PLEX_URL="http://localhost:32400"
export PLEX_TOKEN="your-plex-token"
export TMDB_API_KEY="your-tmdb-api-key"
# Then just run:
python plex_analyzer.py --recommendations 20Plex Connection:
--plex-url URL Plex server URL (e.g., http://localhost:32400)
--plex-token TOKEN Plex authentication token
--username USER MyPlex account username/email
--password PASS MyPlex account password
--server-name NAME Plex server name (for MyPlex accounts)
Analysis Options:
--library, -l NAME Name of movie library to analyze
--output, -o FILE Save analysis to JSON file
--top N Number of top items to show (default: 10)
Recommendation Options:
--tmdb-key KEY TMDB API key for recommendations
--recommendations N Number of recommendations to generate
--rec-output FILE Save recommendations to JSON file
Other:
--list-libraries List available movie libraries
--quiet, -q Minimal output
# List all movie libraries
python plex_analyzer.py --plex-url http://localhost:32400 --plex-token TOKEN --list-libraries
# Analyze a specific library
python plex_analyzer.py --plex-url http://localhost:32400 --plex-token TOKEN --library "4K Movies"
# Save analysis and recommendations to files
python plex_analyzer.py --plex-url http://localhost:32400 --plex-token TOKEN \
--tmdb-key TMDB_KEY \
--output analysis.json \
--recommendations 30 \
--rec-output recommendations.json============================================================
PLEX LIBRARY ANALYSIS
============================================================
Total Movies: 487
Average Rating: 7.2/10
Top 10 Genres:
Drama: 203 (41.7%)
Action: 156 (32.0%)
Thriller: 98 (20.1%)
Comedy: 87 (17.9%)
...
Top 10 Directors:
Christopher Nolan: 8 movies
Denis Villeneuve: 6 movies
...
============================================================
MOVIE RECOMMENDATIONS
============================================================
1. Arrival (2016)
Rating: 7.9/10
Why: Directed by Denis Villeneuve (one of your favorites)
A linguist is recruited by the military to communicate with...
2. Prisoners (2013)
Rating: 8.1/10
Why: Highly rated in your favorite genres: Drama, Thriller
...
MIT License