AutoPlayUtils
Table of Contents
Class Definition
export abstract class AutoPlayUtils {}
AutoPlayUtils is an abstract utility class. All members are static — it cannot be instantiated directly.
Methods
buildTracksFromResponse()
static buildTracksFromResponse<T>(recommendedResult: LavalinkResponse, requester?: T): Track[]Converts a raw
LavalinkResponseinto an array ofTrackobjects, withisAutoplayset totrueon each. Handles all load types.Parameters
Parameter Type Description Optional recommendedResultLavalinkResponseThe raw response from Lavalink. requesterT The user to set as the requester on each built track. Returns
Type Description Track[]The built tracks with isAutoplay: true.
getRecommendedTracks()
static async getRecommendedTracks(track: Track): Promise<Track[]>Returns recommended tracks for the given track. Uses Last.fm if a
lastFmApiKeyis configured on the manager; otherwise iterates throughautoPlaySearchPlatformsin priority order, querying each enabled source until results are found.Parameters
Parameter Type Description Optional trackTrackThe currently playing track to base recommendations on. Returns
Type Description Promise< Track[]>Recommended tracks, or an empty array if none could be found.
getRecommendedTracksFromLastFm()
static async getRecommendedTracksFromLastFm(track: Track, apiKey: string): Promise<Track[]>Fetches recommended tracks via the Last.fm API using
track.getSimilar. Falls back toartist.getTopTracksif no similar tracks are returned.Parameters
Parameter Type Description Optional trackTrackThe track to find similar tracks for. apiKeystring The Last.fm API key. Returns
Type Description Promise< Track[]>Recommended tracks, or an empty array if the request fails.
getRecommendedTracksFromSource()
static async getRecommendedTracksFromSource(track: Track, platform: AutoPlayPlatform): Promise<Track[]>Fetches recommended tracks from the specified platform using its native recommendation API (e.g.
sprec:,dzrec:, YouTube mix playlists, SoundCloud recommended page). If the track URI does not belong to the target platform, it is first resolved via a search query.Parameters
Parameter Type Description Optional trackTrackThe track to base recommendations on. platformAutoPlayPlatformThe platform to fetch recommendations from. Returns
Type Description Promise< Track[]>Recommended tracks, or an empty array if the platform is unsupported or the request fails.
init()
static async init(manager: Manager): Promise<void>Initializes the static
Managerreference used byAutoPlayUtils. Called internally by the manager.Parameters
Parameter Type Description Optional managerManagerThe Manager instance.