Star ✨ on GitHub

SpotifySource

API reference for the SpotifySource in Moonlink.js

SpotifySource Class

The SpotifySource provides integration with the Spotify API, allowing Moonlink.js to search for and load tracks, albums, playlists, and artists from Spotify. It handles authentication using client credentials and API requests internally.

Properties

PropertyTypeDescription
namestringThe name of the source: Spotify.

Methods

match

matchmethod

Match URL

Checks if a given URL or query string matches a Spotify track, album, playlist, or artist URL, or a spsearch: or sprec: query.

Parameters
urlrequiredstring
The URL or query string to check.

Returns & Example

Returnsbooleantrue if the query matches a Spotify pattern, false otherwise.

const isSpotifyLink = source.match('https://open.spotify.com/track/12345');

::

searchmethod

Search Spotify

Searches for tracks on Spotify based on a query. Results are limited by manager.options.spotify.limitLoadSearch.

Parameters
queryrequiredstring
The search query.

Returns & Example

ReturnsPromise<any> — A search result object containing loadType and data.

const results = await source.search('Never Gonna Give You Up');

load

loadmethod

Load Spotify Content

Loads content from a Spotify URL (track, album, playlist, artist) or a sprec: recommendation query. Handles URL normalization and limits results based on manager.options.spotify configurations.

Parameters
rawUrlrequiredstring
The Spotify URL or recommendation query to load.

Returns & Example

ReturnsPromise<any> — A load result object containing loadType and data.

const track = await source.load('https://open.spotify.com/track/12345');
const playlist = await source.load('https://open.spotify.com/playlist/67890');
const recommendations = await source.load('sprec:seed_tracks=12345');

resolve

resolvemethod

Resolve Spotify Content

Resolves Spotify content from a URL. This method is an alias for load.

Parameters
urlrequiredstring
The Spotify URL to resolve.

Returns & Example

ReturnsPromise<any> — A load result object.

const resolvedTrack = await source.resolve('https://open.spotify.com/track/12345');