Quick overview
This scheduled workflow fetches all tracks from a Plex Music library, sends them in batches to a local Ollama LLM for playlist classification, then recreates and populates matching Plex playlists while skipping spoken-word content.
How it works
- Runs weekly on a schedule and queries the Plex server for library sections and the server machine identifier.
- Selects the Plex music library section and paginates through the library to collect and normalize all track metadata.
- Splits the full track list into batches, builds a classification prompt, and sends each batch to Ollama (/api/generate) to assign every track to one of the predefined playlist names or to SKIP_NON_MUSIC.
- Parses and validates the Ollama responses, accumulates an ID-to-playlist map across all batches, and groups track IDs by playlist while excluding SKIP_NON_MUSIC.
- For each playlist group, retrieves existing Plex playlists by name, deletes any matching playlist, and creates a new playlist seeded with the first 50 tracks.
- Chunks the remaining track IDs into sets of 50 and appends them to the newly created Plex playlists via the Plex playlists items API.
Setup
- Provide a Plex HTTP header credential (including X-Plex-Token) and replace MY_HOST_OR_IP in all Plex HTTP Request nodes with your Plex server address.
- Ensure your Plex server is reachable from n8n and that the target library contains a Music section (type "artist") with track items.
- Run Ollama on a reachable host, confirm the model name used in the request (for example, gemma2:9b) is installed, and update the Ollama URL (MY_OLLAMA_HOST_OR_IP:11434) if needed.
- Review or adjust the schedule timing and the predefined playlist names in the prompt to match the playlists you want created in Plex.
Requirements
- This Flow has been tested successfully on the following environment. NAS Ugreen DXP4800PLUS Intel Pentium Gold 8505, 40GB DDR5 RAM
- Inference engine Ollama via IPEX-LLM, offloaded to Intel UHD Graphics (iGPU)
- Concurrency OLLAMA_NUM_PARALLEL=1 (strictly sequential inference)
- Ollama memory allocation 16GB
- Context window OLLAMA_NUM_CTX=8192 (host default)
- Orchestration n8n (self-hosted, Docker)
- Data source Plex Media Server REST API; local SQLite-backed music library
- Library size 16,096 tracks
- Target playlists Deep Focus, Morning Energy, Late Night Drive, Workout Power,
- Chill & Unwind, Nostalgia Trip, Discover Gems, Party Mode
Customization
- Tested with several models such as qwen2.5:7b, Mistral:7b and gemma2:9b (check the "Build Prompt" node for details)
Additional info
While this template provides an out-of-the-box architecture for exhaustive, 100% coverage music classification using local LLMs (like gemma2:9b or mistral:7b), your final playlist accuracy depends heavily on two factors: ID3 Metadata Quality and Personalized Prompt Tuning.