Playlists

Create, modify, and import playlists, or register a provider that fetches playlists from URLs.

Playlists API for Plugins

The Playlists API has two sides. The consumer API (api.Playlists.*) lets plugins create, read, modify, and import playlists. The provider type (PlaylistProvider) lets plugins register a handler that fetches playlists from URLs (Spotify links, SoundCloud pages, etc.).

circle-info

Access playlists via api.Playlists.* in your plugin's lifecycle hooks. All operations are asynchronous and return Promises.


Core concepts

Index vs. full playlist

Nuclear keeps a lightweight index of all playlists and loads the full playlist data on demand. This matters for two reasons:

  1. getIndex() returns PlaylistIndexEntry[], which contains names, timestamps, artwork, and aggregate stats (item count, total duration), but not the actual track list.

  2. getPlaylist(id) returns the full Playlist with its items array.

Use the index for listing and displaying playlists. Load the full playlist only when you need the tracks.

Playlist items

Each track in a playlist is wrapped in a PlaylistItem:

type PlaylistItem = {
  id: string;          // Unique ID for this item (not the track ID)
  track: Track;        // Full track metadata
  note?: string;       // Optional user note
  addedAtIso: string;  // ISO timestamp
};

A single track can appear multiple times in a playlist, each as a separate PlaylistItem with its own id.

Persistence

Each playlist is stored as a separate JSON file on disk. All mutations through the API persist automatically.


Usage


Playlist providers

Plugins can register a PlaylistProvider that handles URL-based playlist imports. When a user pastes a URL into Nuclear's import dialog, the player asks each registered playlist provider whether it can handle that URL. The first provider that matches gets called to fetch the playlist.

Implementing a provider

A playlist provider needs two methods:

  • matchesUrl(url) returns true if this provider can handle the given URL. This is called synchronously and should be fast (a regex test or hostname check, not a network request).

  • fetchPlaylistByUrl(url) fetches and returns a full Playlist from the URL.

Register it with api.Providers.register() like any other provider, with kind: 'playlists':

circle-exclamation

Types

Playlist

PlaylistIndexEntry

PlaylistItem


Reference

Provider type

Last updated