See llms.txt for all machine-readable content.

Back to Templates

Classify Plex music into smart playlists with Ollama and local LLMs

Last update

Last update 13 hours ago

Categories

Share


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

  1. Runs weekly on a schedule and queries the Plex server for library sections and the server machine identifier.
  2. Selects the Plex music library section and paginates through the library to collect and normalize all track metadata.
  3. 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.
  4. 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.
  5. 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.
  6. 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

  1. 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.
  2. Ensure your Plex server is reachable from n8n and that the target library contains a Music section (type "artist") with track items.
  3. 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.
  4. 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.