Class Spotify

Classdec

Spotify Class, which handles all relevant statistical endpoints from the Spotify API

Param

Spotify client ID

Param

Spotify client secret

Hierarchy

  • Spotify

Constructors

Properties

db: QuickDB
id: string
oauth_token: string | object | Promise<string>
secret: string

Methods

  • Returns Promise<string | object>

  • It takes the client id and secret, encodes them into base64, and sends them to the Spotify API to get an access token.

    Async

    Returns

    The access token is being returned.

    Returns Promise<any>

  • It takes a playlist ID and returns the playlist's data.

    Async

    Returns

    The data from the request.

    Parameters

    • playlist: string

      The Spotify ID of the playlist you want to get.

    Returns Promise<any>

  • Async

    Returns

    Access Token

    Parameters

    • options: SpotifyToken

    Returns Promise<string>

  • It takes the refresh token and sends it to the Spotify API to get a new access token

    Async

    Returns

    The access token.

    Returns Promise<any>

  • Private

    It takes a url, gets an access token, and then makes a request to the url with the access token. You can use async/await to make it easier to read.

    Async

    Returns

    The response body.

    Parameters

    • url: string

      The url you want to request.

    Returns Promise<any>

  • It searches for a song, artist, album, or playlist

    Async

    Example

    const spotify = new Spotify({
    clientID: "clientID",
    clientSecret: "clientSecret",
    });
    const search = await spotify.search({ query: "Never Gonna Give You Up", type: "track", limit: 10 });
    console.log(search);

    Returns

    The search function returns the body of the response.

    Returns

    tracks.href A link to the Web API endpoint returning the full result of the request.

    Returns

    tracks.items The requested data.

    Returns

    tracks.limit The maximum number of items in the response (as set in the query or by default).

    Returns

    tracks.next URL to the next page of items. (null if none)

    Returns

    tracks.offset The offset of the items returned (as set in the query or by default).

    Returns

    tracks.previous URL to the previous set of items (null if none)

    Returns

    tracks.total Total

    Throws

    If the type is not track, artist, album or playlist.

    Throws

    If the limit is not between 1 and 50.

    Parameters

    • options: searchOptions

    Returns Promise<any>

  • It gets the top tracks/artists from the user's account

    Async

    Example

    const spotify = new Spotify({
    clientID: "clientID",
    clientSecret: "clientSecret",
    });
    const topTracks = await spotify.top({ type: "tracks", limit: 10, time: "short_term" });
    console.log(topTracks);

    Returns

    An array of objects.

    Returns

    album.album_type The type of the album: one of "album", "single", or "compilation".

    Returns

    album.artists The artists of the album. Each artist object includes a link in href to more detailed information about the artist.

    Returns

    album.available_markets The markets in which the album is available: ISO 3166-1 alpha-2 country codes. Note that an album is considered available in a market when at least 1 of its tracks is available in that market.

    Returns

    album.external_urls Known external URLs for this album.

    Returns

    album.href A link to the Web API endpoint providing full details of the album.

    Returns

    album.id The Spotify ID for the album.

    Returns

    album.images The cover art for the album in various sizes, widest first.

    Returns

    album.name The name of the album. In case of an album takedown, the value may be an empty string.

    Returns

    album.release_date The date the album was first released, for example "1981-12-15". Depending on the precision, it might be shown as "1981" or "1981-12".

    Returns

    album.release_date_precision The precision with which release_date value is known: "year", "month", or "day".

    Returns

    album.total_tracks The total number of tracks in the album.

    Returns

    album.type The object type: "album"

    Returns

    album.uri The Spotify URI for the album.

    Returns

    artists The artists who performed the track. Each artist object includes a link in href to more detailed information about the artist.

    Returns

    available_markets The markets in which the track is available: ISO 3166-1 alpha-2 country codes. Note that an album is considered available in a market when at least 1 of its tracks is available in that market.

    Returns

    disc_number The disc number (usually 1 unless the album consists of more than one disc).

    Returns

    duration_ms The track length in milliseconds.

    Returns

    explicit Whether or not the track has explicit lyrics ( true = yes it does; false = no it does not OR unknown).

    Returns

    external_ids Known external IDs for the track.

    Returns

    external_urls Known external URLs for this track.

    Returns

    href A link to the Web API endpoint providing full details of the track.

    Returns

    id The Spotify ID for the track.

    Returns

    is_local Whether or not the track is from a local file.

    Returns

    name The name of the track.

    Returns

    popularity The popularity of the track. The value will be between 0 and 100, with 100 being the most popular. The popularity is calculated by algorithm and is based, in the most part, on the total number of plays the track has had and how recent those plays are.

    Returns

    preview_url A link to a 30 second preview (MP3 format) of the track. Can be null.

    Returns

    track_number The number of the track. If an album has several discs, the track number is the number on the specified disc.

    Returns

    type The object type: "track".

    Returns

    uri The Spotify URI for the track.

    Throws

    If the type is not tracks or artists.

    Throws

    If the time is not short_term, medium_term or long_term.

    Throws

    If the limit is not between 1 and 50.

    Throws

    If the user is not logged in.

    Throws

    If the user has no top tracks/artists.

    Parameters

    • options: top

    Returns Promise<any>

Generated using TypeDoc