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.
This source is automatically loaded if disableNativeSources is not set to true in the Manager options. You must provide clientId and clientSecret in the Manager's spotify options for this source to function.
Properties
| Property | Type | Description |
|---|---|---|
name | string | The name of the source: Spotify. |
Methods
match
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
Returns & Example
Returns
• boolean — true if the query matches a Spotify pattern, false otherwise.
const isSpotifyLink = source.match('https://open.spotify.com/track/12345');
::
search
Search Spotify
Searches for tracks on Spotify based on a query. Results are limited by manager.options.spotify.limitLoadSearch.
Parameters
Returns & Example
Returns
• Promise<any> — A search result object containing loadType and data.
const results = await source.search('Never Gonna Give You Up');
load
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
Returns & Example
Returns
• Promise<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
Resolve Spotify Content
Resolves Spotify content from a URL. This method is an alias for load.
Parameters
Returns & Example
Returns
• Promise<any> — A load result object.
const resolvedTrack = await source.resolve('https://open.spotify.com/track/12345');