Quick overview
A scheduled workflow that (1) fetches all tracks from a Plex Music library, (2) sends them in batches to a local Ollama LLM for playlist classification, (3) recreates and populates matching Plex playlists.
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.
- Parses and validates the Ollama responses, accumulates an ID-to-playlist map across all batches, and groups track IDs by playlist.
- 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 (check the workflow instruction for more details).
- 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) to match with your local IP.
- 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 a Ugreen NAS DXP4800PLUS Intel Pentium Gold 8505, 40GB DDR5 RAM with 16 GB allocated to Ollama (should be able to run on similar hardware with the same of higher specs).
- Ollama instance (self-hosted, Docker).
- n8n Orchestration (self-hosted, Docker).
- Plex Media Server (self-hosted, Docker).
- Plex Media Server Library size 16k+ tracks.
- Plex Media Server Target playlists Deep Focus, Morning Energy, Late Night Drive, Workout Power, Chill & Unwind, Nostalgia Trip, Discover Gems, Party Mode, Audiobooks & Podcasts.
Customization
- Tested with several models such as qwen2.5:7b, Mistral:7b and gemma2:9b (check the "Build Prompt" node for details). Can be integrated with Cloud based LLMs but has not yet been tested.
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, Personalized Prompt Tuning.