A robust, multi-threaded Python tool to automate the extraction, enrichment, and management of metadata and artwork for your Plex libraries. This script fetches high-quality data from TMDb, generates Kometa compatible YAML files, manages poster/season assets, and keeps your library clean by removing orphans—all with smart update logic and flexible configuration.
- Connects to Plex: Reads your Plex libraries directly.
- Fetches TMDb Metadata: Pulls rich, up-to-date info for movies and TV shows.
- Smart Metadata Updates: Only updates YAML if something has changed, minimizing unnecessary writes.
- Asset Management: Downloads, upgrades, and manages posters and season artwork.
- Orphan Cleanup: Removes unused metadata and asset files for a tidy library.
- Kometa-Compatible: Outputs YAML ready for Kometa and similar tools.
- Multi-threaded: Fast, parallel processing for large libraries.
- Dry-Run Mode: Test everything safely—no files are written or deleted.
- Highly Configurable: Choose which libraries, asset types, and metadata to process—all via
config.yml.
- Connects to Plex using your server URL and token.
- Scans your selected libraries for movies and TV shows.
- Fetches metadata from TMDb for each item, using smart caching and update logic.
- Downloads and manages posters/season artwork based on your preferences.
- Writes YAML files compatible with Kometa, one per library.
- Optionally cleans up orphaned metadata and assets not linked to any current Plex item.
- Logs a detailed summary of all actions and changes.
- Python: 3.8+
- Dependencies:
requestsplexapiPyYAMLpycountryPillow(for image handling)
Install all dependencies with:
pip install -r requirements.txt- Download the provided
config_template.ymlfrom the repo. - Rename it to
config.yml(the script will only useconfig.yml).
Open config.yml and fill in the following:
# Dry run
dry_run: false
# Logging
log_level: "INFO"
#Plex server configuration
plex:
url: "http://localhost:32400"
token: "YOUR_PLEX_TOKEN"
# TMDb API configuration
tmdb:
api_key: "YOUR_TMDB_API_KEY"
language: "en"
region: "US"
fallback:
- zh
- ja
- fr
# Plex libraries
plex_libraries:
- Movies
- TV Shows
# Metadata & Asset processing
run_basic: true
run_poster: true
run_season: true
run_background: true
cleanup_orphans: true
# Metadata output
directory: "/path/to/metadata/"
# Asset management
path: "/path/to/assets"
# Poster selection preferences
poster_settings:
max_width: 2000
max_height: 3000
min_width: 1000
min_height: 1500
prefer_vote: 5.0
vote_relaxed: 3.5
vote_threshold: 5.0
# Background selection preferences
background_settings:
max_width: 3840
max_height: 2160
min_width: 1920
min_height: 1080
prefer_vote: 5.0
vote_relaxed: 3.5
vote_threshold: 5.0
- Follow this guide: How to find your Plex Token
- Paste your token in the
tokenfield.
- Sign up at TMDb and request an API key: TMDb API Key Guide
- Paste your API key in the
api_keyfield.
Run the script from your terminal:
python metadata_gen.pyNote: All options and behaviors are controlled via your
config.yml. There are no CLI flags—simply edit your config and run the script.
- YAML files are generated in your
directory, one per library. - Assets (posters, season images) are saved in your configured
path. - Logs are written to
metadata_generator.logfor troubleshooting and audit.
When enabled, the script will:
- Remove TMDb cache entries not present in your current Plex libraries.
- Remove metadata entries from YAML files that no longer match any Plex item.
- Delete poster/season asset files not referenced by any current item (with safety checks to avoid accidental deletion).
- Dry-Run Mode: No files are written or deleted—perfect for testing.
- Smart Update: Only writes YAML or downloads assets if something has changed.
- Asset Tracking: Prevents accidental deletion of assets still in use.
Here’s what’s coming next (and how you can help!):
-
Background Poster Download
- 🎨 Download TMDb backgrounds for movies and TV shows. *Done
- User-configurable width, height, vote average, and language preferences. *Done
-
Configurable Asset Types
- 🖼️ Turn season posters and background downloads on/off via config options. *Done
-
Enhanced Episode Metadata
- 🎭 Improved fallbacks to fetch more detailed crew and cast info for episodes.
-
User-Configurable Metadata Limits
- 🔧 Set how many cast/crew members to include in metadata via config.
-
Franchise/Collection Extraction
- 📚 Extract franchise/collection info from TMDb and generate Kometa-compatible collection YAML files.
- Include poster URLs for collections and franchises.
-
Speed Optimizations
- ⚡ Further parallelization and smarter caching for even faster runs. *Done at the best i could
- Add progress bars (e.g., with tqdm) for real-time feedback.
- Generate HTML reports with summary tables and asset previews.
- Use emojis and colorized logs for easier reading in the terminal.
- Add a web dashboard for monitoring and controlling runs (future idea!).
Want to make it even more visual?
Consider adding screenshots, flowcharts, or even short demo videos to this README.
You can also use badges (e.g., build status, Python version) at the top for a more professional look.
MIT License
Enjoy your perfectly organized Plex library! 🍿