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.