Skip to main content

ruvyrias / Exports / AppleMusic

Installation

// Just import the class from Ruvyrias
const { AppleMusic } = require('ruvyrias');

Example usage basic bot

const { Client, GatewayIntentBits } = require('discord.js');
const { AppleMusic } = require('ruvyrias');
const applemusic = new AppleMusic({
countryCode: 'us',
apiKey: 'your-api-key'
});

const RuvyriasOptions = {
library: 'discord.js',
defaultPlatform: 'amsearch',
plugins: [applemusic],
};

const nodes = [
{
name: 'local-node',
host: 'localhost',
port: 2333,
password: 'youshallnotpass',
},
];

// The entire code of a bot can be found at the main page, i'll not repeat all things here
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
],
});

client.ruvyrias = new Ruvyrias(client, nodes, RuvyriasOptions);

/**
* You can use the source property to search by name or it will use the defaultPlatform to search by name
* Links will work directly, and it serves to any platform, but plugins has to be loaded before (unless you have lavaSrc)
*/
const res = await client.ruvyrias.resolve({ query: 'alan walker alone', source: 'amsearch', requester: message.author });

Class: AppleMusic

Represents the Apple Music class, extending the base Plugin class.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new AppleMusic(options): AppleMusic

Parameters

NameType
optionsOmit<AppleMusicOptions, "token" | "fetchURL">

Returns

AppleMusic

Overrides

Plugin.constructor

Defined in

plugins/applemusic/AppleMusic.ts:91

Properties

_resolve

Private _resolve: (__namedParameters: ResolveOptions) => any

Type declaration

▸ («destructured»): any

Parameters
NameType
«destructured»ResolveOptions
Returns

any

Defined in

plugins/applemusic/AppleMusic.ts:90


baseURL

Private baseURL: "https://api.music.apple.com/v1/"

Defined in

plugins/applemusic/AppleMusic.ts:87


name

Readonly name: string

The name of the plugin.

Inherited from

Plugin.name

Defined in

src/Plugin.ts:8


options

Private options: AppleMusicOptions

Defined in

plugins/applemusic/AppleMusic.ts:89


ruvyrias

Private ruvyrias: Ruvyrias

Defined in

plugins/applemusic/AppleMusic.ts:88

Methods

buildResponse

buildResponse(loadType, tracks, playlistName?, exceptionMsg?): object

Builds a response object based on the specified parameters.

Parameters

NameTypeDescription
loadTypeloadTypeThe load type of the response.
tracksanyThe tracks associated with the response.
playlistName?stringThe name of the playlist (optional).
exceptionMsg?stringThe exception message (optional).

Returns

object

  • The constructed response object.

Defined in

plugins/applemusic/AppleMusic.ts:315


buildUnresolved

buildUnresolved(track, requester): Promise<Track>

Builds an unresolved track using the provided Apple Music track object and requester.

Parameters

NameTypeDescription
trackAppleMusicTrackThe Apple Music track object.
requesteranyThe requester for the track.

Returns

Promise<Track>

  • An unresolved Track instance representing the Apple Music track.

Defined in

plugins/applemusic/AppleMusic.ts:277


check

check(url): boolean

Checks if the provided URL matches the Apple Music regex pattern.

Parameters

NameTypeDescription
urlstringThe URL to check.

Returns

boolean

  • True if the URL matches the Apple Music regex pattern, false otherwise.

Defined in

plugins/applemusic/AppleMusic.ts:121


getAlbum

getAlbum(url, requester): Promise<object>

Fetches data for an album from Apple Music.

Parameters

NameTypeDescription
urlstringThe URL of the album.
requesteranyThe requester of the data.

Returns

Promise<object>

  • A promise that resolves to the album data.

Defined in

plugins/applemusic/AppleMusic.ts:229


getArtist

getArtist(url, requester): Promise<object>

Fetches data for an artist from Apple Music.

Parameters

NameTypeDescription
urlstringThe URL of the artist.
requesteranyThe requester of the data.

Returns

Promise<object>

  • A promise that resolves to the artist data.

Defined in

plugins/applemusic/AppleMusic.ts:203


getData

getData(params): Promise<any>

Fetches data from the Apple Music API based on the provided parameters.

Parameters

NameTypeDescription
paramsstringThe parameters to be included in the API request URL.

Returns

Promise<any>

  • A promise that resolves to the fetched data from the Apple Music API.

Defined in

plugins/applemusic/AppleMusic.ts:130


getPlaylist

getPlaylist(url, requester): Promise<object>

Fetches data for a playlist from Apple Music.

Parameters

NameTypeDescription
urlstringThe URL of the playlist.
requesteranyThe requester of the data.

Returns

Promise<object>

  • A promise that resolves to the playlist data.

Defined in

plugins/applemusic/AppleMusic.ts:177


load

load(ruvyrias): Promise<void>

Overrides the load method of the Plugin class, enabling the Apple Music plugin to interact with the Ruvyrias instance.

Parameters

NameTypeDescription
ruvyriasRuvyriasThe Ruvyrias instance.

Returns

Promise<void>

Overrides

Plugin.load

Defined in

plugins/applemusic/AppleMusic.ts:110


resolve

resolve(options): Promise<unknown>

Resolves a track, album, playlist, or artist from Apple Music based on the provided query, source, and requester.

Parameters

NameTypeDescription
optionsResolveOptionsThe options for resolving a track.

Returns

Promise<unknown>

  • A promise that resolves to the result of the Apple Music resolution.

Defined in

plugins/applemusic/AppleMusic.ts:148


searchSong

searchSong(query, requester): Promise<object | AppleMusicTrack>

Searches for a song on Apple Music.

Parameters

NameTypeDescription
querystringThe search query.
requesteranyThe requester of the data.

Returns

Promise<object | AppleMusicTrack>

  • A promise that resolves to the search results.

Defined in

plugins/applemusic/AppleMusic.ts:255