AI-powered Plex playlist generator using mood-based queries
Project description
PlexMix
AI-powered Plex playlist generator using mood-based queries
PlexMix syncs your Plex music library to a local SQLite database, generates semantic embeddings for tracks, and uses AI to create personalized playlists based on mood descriptions.
Features
- โจ Simple Setup - Only requires a Google API key to get started
- ๐ต Smart Sync - Syncs Plex music library with incremental updates
- ๐ค AI-Powered - Uses Google Gemini, OpenAI GPT, or Anthropic Claude
- ๐ท๏ธ AI Tagging - Automatically generates tags, environments, and instruments for tracks
- ๐ Semantic Search - FAISS vector similarity search for intelligent track matching
- ๐จ Mood-Based - Generate playlists from natural language descriptions
- โก Fast - Local database with optimized indexes and full-text search
- ๐ฏ Flexible - Filter by genre, year, rating, artist, environment, and instrument
Quick Start
# Install dependencies
poetry install
# Run setup wizard
poetry run plexmix config init
# Sync your Plex library (generates embeddings automatically)
poetry run plexmix sync full
# Generate AI tags for tracks (enhances search quality)
poetry run plexmix tags generate
# Create a playlist
poetry run plexmix create "upbeat morning energy"
# With filters
poetry run plexmix create "chill evening vibes" --genre jazz --year-min 2010 --limit 30
# Filter by environment and instrument
poetry run plexmix create "focus music" --environment study --instrument piano
# Use alternative AI provider
poetry run plexmix create "workout motivation" --provider openai
# If you encounter issues (e.g., "0 candidate tracks")
poetry run plexmix doctor
Installation
From Source (Recommended)
git clone https://github.com/izzoa/plexmix.git
cd plexmix
poetry install
From PyPI (Coming Soon)
pip install plexmix
Configuration
PlexMix uses Google Gemini by default for both AI playlist generation and embeddings, requiring only a single API key!
Required
- Plex Server: URL and authentication token
- Google API Key: For Gemini AI and embeddings (Get one here)
Optional Alternative Providers
- OpenAI API Key: For GPT models and text-embedding-3-small
- Anthropic API Key: For Claude models
- Local Embeddings: sentence-transformers (free, offline, no API key needed)
Getting a Plex Token
- Open Plex Web App
- Play any media item
- Click the three dots (...) โ Get Info
- View XML
- Copy the
X-Plex-Tokenfrom the URL
Usage
Configuration Commands
# Interactive setup wizard
plexmix config init
# Show current configuration
plexmix config show
Sync Commands
# Full sync with embedding generation
plexmix sync full
# Sync without embeddings
plexmix sync full --no-embeddings
Database Health Check
# Diagnose and fix database issues
plexmix doctor
What does doctor do?
- Detects orphaned embeddings (embeddings that reference deleted tracks)
- Shows database health status (track count, embeddings, orphans)
- Interactively removes orphaned data
- Regenerates missing embeddings
- Rebuilds vector index
When to use:
- After "No tracks found matching criteria" errors
- When playlist generation finds 0 candidates
- After database corruption or manual track deletion
- Periodic maintenance to keep database healthy
Tag Generation
# Generate AI tags for all untagged tracks
plexmix tags generate
# Use alternative AI provider
plexmix tags generate --provider openai
# Skip embedding regeneration (faster, but tags won't be in search)
plexmix tags generate --no-regenerate-embeddings
What are tags? AI-generated metadata (per track) that enhances semantic search:
- Tags (3-5): Mood descriptors like energetic, melancholic, upbeat, chill, intense
- Environments (1-3): Best-fit contexts like work, study, focus, relax, party, workout, sleep, driving, social
- Instruments (1-3): Most prominent instruments like piano, guitar, saxophone, drums, bass, synth, vocals, strings
All metadata is automatically included in embeddings for more accurate mood-based playlist generation.
Playlist Generation
# Basic playlist (prompts for track count)
plexmix create "happy upbeat summer vibes"
# Specify track count
plexmix create "rainy day melancholy" --limit 25
# Filter by genre
plexmix create "energetic workout" --genre rock --limit 40
# Filter by year range
plexmix create "90s nostalgia" --year-min 1990 --year-max 1999
# Filter by environment (work, study, focus, relax, party, workout, sleep, driving, social)
plexmix create "workout energy" --environment workout
# Filter by instrument (piano, guitar, saxophone, drums, etc.)
plexmix create "piano jazz" --instrument piano
# Use specific AI provider
plexmix create "chill study session" --provider claude
# Custom playlist name
plexmix create "morning coffee" --name "Perfect Morning Mix"
# Don't create in Plex (save locally only)
plexmix create "test playlist" --no-create-in-plex
Architecture
PlexMix uses a two-stage retrieval system with AI-enhanced tagging:
- AI Tagging โ Tracks receive:
- 3-5 descriptive tags (mood, energy, tempo, emotion)
- 1-3 environments (work, study, focus, relax, party, workout, sleep, driving, social)
- 1-3 instruments (piano, guitar, saxophone, drums, bass, synth, vocals, strings, etc.)
- SQL Filters โ Filter tracks by genre, year, rating, artist, environment, instrument
- FAISS Similarity Search โ Retrieve top-K candidates using semantic embeddings (includes all metadata)
- LLM Selection โ AI provider selects final tracks matching the mood
Technology Stack
- Language: Python 3.10+
- CLI: Typer with Rich console output
- Database: SQLite with FTS5 full-text search
- Vector Search: FAISS (CPU) with cosine similarity
- AI Providers: Google Gemini (default), OpenAI GPT, Anthropic Claude
- Embeddings: Google Gemini (3072d), OpenAI (1536d), Local (384-768d)
- Plex Integration: PlexAPI
Project Structure
plexmix/
โโโ src/plexmix/
โ โโโ ai/ # AI provider implementations
โ โ โโโ base.py # Abstract base class
โ โ โโโ gemini_provider.py
โ โ โโโ openai_provider.py
โ โ โโโ claude_provider.py
โ โ โโโ tag_generator.py # AI-based tag generation
โ โโโ cli/ # Command-line interface
โ โ โโโ main.py # Typer CLI app
โ โโโ config/ # Configuration management
โ โ โโโ settings.py # Pydantic settings
โ โ โโโ credentials.py # Keyring integration
โ โโโ database/ # Database layer
โ โ โโโ models.py # Pydantic models
โ โ โโโ sqlite_manager.py # SQLite CRUD
โ โ โโโ vector_index.py # FAISS index
โ โโโ plex/ # Plex integration
โ โ โโโ client.py # PlexAPI wrapper
โ โ โโโ sync.py # Sync engine
โ โโโ playlist/ # Playlist generation
โ โ โโโ generator.py # Core generation logic
โ โโโ utils/ # Utilities
โ โโโ embeddings.py # Embedding providers
โ โโโ logging.py # Logging setup
โโโ tests/ # Test suite
Database Schema
PlexMix stores all music metadata locally:
- artists: Artist information
- albums: Album details with artist relationships
- tracks: Track metadata with full-text search, AI-generated tags (3-5), environments (1-3), and instruments (1-3)
- embeddings: Vector embeddings for semantic search (includes all AI-generated metadata)
- playlists: Generated playlist metadata
- sync_history: Synchronization audit log
Embedding Providers
| Provider | Model | Dimensions | API Key Required |
|---|---|---|---|
| Google Gemini (default) | gemini-embedding-001 | 3072 | Yes |
| OpenAI | text-embedding-3-small | 1536 | Yes |
| Local | all-MiniLM-L6-v2 | 384 | No |
AI Providers
| Provider | Model | Context | Notes |
|---|---|---|---|
| Google Gemini (default) | gemini-2.5-flash | ~1M tokens | Fast, accurate, cost-effective |
| OpenAI | gpt-5-mini | ~400K tokens | Latest model, high quality |
| OpenAI | gpt-5-nano | ~400K tokens | Fastest, most efficient |
| OpenAI | gpt-4o-mini | ~128K tokens | Previous generation |
| Anthropic | claude-sonnet-4-5 | ~200K tokens | Latest model, excellent reasoning |
| Anthropic | claude-3-5-haiku-20241022 | ~200K tokens | Fast, efficient |
Development
Setup Development Environment
# Clone repository
git clone https://github.com/izzoa/plexmix.git
cd plexmix
# Install with development dependencies
poetry install
# Run tests
poetry run pytest
# Format code
poetry run black src/
# Lint
poetry run ruff src/
# Type check
poetry run mypy src/
Running Tests
poetry run pytest
poetry run pytest --cov=plexmix --cov-report=html
Troubleshooting
"No music libraries found"
- Ensure your Plex server has a music library
- Verify your Plex token is correct
- Check server URL is accessible
"Failed to generate embeddings"
- Verify API keys are configured correctly
- Check internet connection
- Try local embeddings:
--embedding-provider local
"No tracks found matching criteria"
- First, try:
plexmix doctorto check for database issues - Ensure library is synced:
plexmix sync full - Check filters aren't too restrictive
- Verify embeddings were generated
"0 candidate tracks" or "No orphaned embeddings"
- This usually means embeddings reference old track IDs
- Solution: Run
plexmix doctorto detect and fix orphaned embeddings - The doctor will clean up orphaned data and regenerate embeddings
Performance Tips
- Use local embeddings for faster offline operation
- Run sync during off-peak hours for large libraries
- Adjust candidate pool size based on library size
- Use filters to narrow search space
Roadmap
- Docker support
- Web UI dashboard
- Multi-library support
- Playlist templates
- Smart shuffle and ordering
- Export/import playlists (M3U, JSON)
- Audio feature analysis integration
Contributing
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE for details
Acknowledgments
- Built with Typer and Rich
- Plex integration via python-plexapi
- Vector search powered by FAISS
- AI providers: Google, OpenAI, Anthropic
Made with โค๏ธ for music lovers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plexmix-0.1.0.tar.gz.
File metadata
- Download URL: plexmix-0.1.0.tar.gz
- Upload date:
- Size: 34.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
024f05e4a2accb05917565a48aa4f91ef68179938385bdbdcc382a3d609a2c4d
|
|
| MD5 |
cf68dafa741ed9e842379de995611673
|
|
| BLAKE2b-256 |
ace1c1b56a644bcd247b83c271af62d1fec906ea734b73169da8b934d954e01b
|
Provenance
The following attestation bundles were made for plexmix-0.1.0.tar.gz:
Publisher:
publish.yml on izzoa/plexmix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
plexmix-0.1.0.tar.gz -
Subject digest:
024f05e4a2accb05917565a48aa4f91ef68179938385bdbdcc382a3d609a2c4d - Sigstore transparency entry: 581066730
- Sigstore integration time:
-
Permalink:
izzoa/plexmix@9efe3a6f70bd074b295f747a1d7903a0296ee26b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/izzoa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9efe3a6f70bd074b295f747a1d7903a0296ee26b -
Trigger Event:
release
-
Statement type:
File details
Details for the file plexmix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: plexmix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 39.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d839c2933ef0149e2c561e54abb0125967189d968dd80d7f281bf5e9059c036c
|
|
| MD5 |
2953a4230e0c9560bf1e859c720d31cb
|
|
| BLAKE2b-256 |
934cc5defcb3137e0610560600c5d27aff24c5e280b3b2ddade56869f5482faf
|
Provenance
The following attestation bundles were made for plexmix-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on izzoa/plexmix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
plexmix-0.1.0-py3-none-any.whl -
Subject digest:
d839c2933ef0149e2c561e54abb0125967189d968dd80d7f281bf5e9059c036c - Sigstore transparency entry: 581066735
- Sigstore integration time:
-
Permalink:
izzoa/plexmix@9efe3a6f70bd074b295f747a1d7903a0296ee26b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/izzoa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9efe3a6f70bd074b295f747a1d7903a0296ee26b -
Trigger Event:
release
-
Statement type: