Giter Site home page Giter Site logo

spotify's Introduction

spotifyx

Fast-paced and versatile Spotify API wrapper for Node.

Covers:

  • Search API
  • Browse API
  • Albums API
  • Artists API
  • Tracks API
  • Shows API
  • Episodes API
  • User API
  • Markets API

Installation and Usage

Installation

Using NPM:

npm install --save spotifyx

Using Yarn:

yarn add spotifyx

Usage

CommonJS

const Spotify = require("spotifyx");

ES6

import Spotify from "spotifyx";

Simple Example

import Spotify from "spotifyx";

(async () => {
    const client = new Spotify({
        clientId: "a-cool-id",
        clientSecret: "a-cool-secret",
    });

    await client.login();

    console.log(await client.search("Null Magma", ["artist"]));
})();

Documentation

Key:

  • ๐Ÿ„ฒ โ€“ Class declaration
  • ๐Ÿ„ฟ โ€“ Property
  • ๐Ÿ„ผ โ€“ Method

Most typedefs are from Spotify's documentation.

๐Ÿ„ฒ Spotify

๐Ÿ„ฒ Spotify

Constructs a new Spotify API client.

Parameters:

  • credentials โ€“ Client credentials to log in
    • clientId โ€“ Client ID
    • clientSecret โ€“ Client secret
    • redirectUrl? โ€“ URL to redirect to

Returns:

  • Spotify โ€“ The newly created client

Example:

const client = new Spotify({
    clientId: "a-cool-id",
    clientSecret: "a-cool-secret",
});

Properties

๐Ÿ„ฟ Spotify#token

readonly string

The client's current access token


๐Ÿ„ฟ Spotify#browse

Browser

The client's Spotify browse API


๐Ÿ„ฟ Spotify#artists

Artists

The client's Spotify artists API


๐Ÿ„ฟ Spotify#albums

Albums

The client's Spotify albums API


๐Ÿ„ฟ Spotify#tracks

Tracks

The client's Spotify tracks API


๐Ÿ„ฟ Spotify#episodes

Episodes

The client's Spotify episodes API


๐Ÿ„ฟ Spotify#shows

Shows

The client's Spotify shows API


Methods

๐Ÿ„ผ Spotify#login

Logs the client in and creates an access token.

Parameters:

Returns:

  • string โ€“ The newly created access token

Example:

await client.login();

๐Ÿ„ผ Spotify#search

Searches Spotify using Spotify's search API.

Parameters:

  • query โ€“ Search query
  • types โ€“ Object types to search for
  • options? โ€“ Search options
    • market? โ€“ Market to search within
    • limit? โ€“ Search results limit
    • offset? โ€“ Search results offset
    • includeExternal? โ€“ Include externals in results

Returns:

  • SearchResponse โ€“ Search results

Example:

const results = await client.search("Null Magma", ["artist"]);

๐Ÿ„ผ Spotify#user

Obtains a user from Spotify using an ID.

Parameters:

  • id โ€“ The user's ID

Returns:

  • PublicUserObject? โ€“ User obtained from the user ID, or undefined if no user was found

Example:

const user = await client.user("a-cool-id");

๐Ÿ„ผ Spotify#markets

Gets all the markets.

Parameters:

Returns:

  • string[] โ€“ All markets

Example:

const markets = await client.markets();
๐Ÿ„ฒ Browser

๐Ÿ„ฒ Browser

Wrapper for Spotify's browse API.

private


Methods

๐Ÿ„ผ Browser#newReleases

Fetches newest releases.

Parameters:

  • options? โ€“ Fetch options
    • country? โ€“ Country code
    • limit? โ€“ Fetch limit
    • offset? โ€“ Fetch offset

Returns:

  • BrowseNewReleasesResponse โ€“ Fetched new releases

Example:

const releases = await client.browse.newReleases({
    limit: 25,
    offset: 25,
});

๐Ÿ„ผ Browser#featuredPlaylists

Fetches featured playlists.

Parameters:

  • options? โ€“ Fetch options
    • country? โ€“ Country code
    • locale? โ€“ Locale
    • timestamp? โ€“ Timestamp
    • limit? โ€“ Fetch limit
    • offset? โ€“ Fetch offset

Returns:

  • BrowseFeaturedPlaylistsResponse โ€“ Fetched featured playlists

Example:

const playlists = await client.browse.featuredPlaylists();

๐Ÿ„ผ Browser#allCategories

Fetches all categories.

Parameters:

  • options? โ€“ Fetch options
    • country? โ€“ Country code
    • locale? โ€“ Locale
    • limit? โ€“ Fetch limit
    • offset? โ€“ Fetch offset

Returns:

  • BrowseAllCategoriesResponse โ€“ Fetched categories

Example:

const categories = await client.browse.allCategories();

๐Ÿ„ผ Browser#category

Fetches a category.

Parameters:

  • category โ€“ The category
  • options? โ€“ Fetch options
    • country? โ€“ Country code
    • locale? โ€“ Locale

Returns:

  • BrowseCategoryResponse โ€“ Fetched categories

Example:

const category = await client.browse.category("party");

๐Ÿ„ผ Browser#categoryPlaylists

Fetches a category's playlists.

Parameters:

  • category โ€“ The category
  • options? โ€“ Fetch options
    • country? โ€“ Country code
  • limit? โ€“ Fetch limit
  • offset? โ€“ Fetch offset

Returns:

  • PagingObject<SimplifiedPlaylistObject> โ€“ Fetched playlists

Example:

const playlists = await client.browse.categoryPlaylists("party");

๐Ÿ„ผ Browser#recommendations

Fetches a category's playlists.

Parameters:

  • seeds โ€“ Seeds
    • artists โ€“ Seed artists
    • genres โ€“ Seed genres
    • tracks - Seed tracks
  • options? โ€“ Fetch options
    • Not available

Returns:

  • BrowseRecommendationsResponse โ€“ Fetched category platlists

Example:

Not available


๐Ÿ„ผ Browser#recommendationGenres

Fetches recommendation genres.

Parameters:

Returns:

  • string[] โ€“ Fetched genres

Example:

const genres = await client.browse.recommendationGenres();
๐Ÿ„ฒ Artists

๐Ÿ„ฒ Artists

Wrapper for Spotify's artists API.

private


Methods

๐Ÿ„ผ Artists#get

Retrieves an artist or multiple artists.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.

Returns:

If a single ID is used:

  • ArtistsSingleArtistResponse โ€“ The artist retrieved

If an array of IDs is used:

  • ArtistsMultipleArtistsResponse โ€“ The artists retrieved

Example:

const artists = await client.artists.get(["a-id", "another-id"]);

๐Ÿ„ผ Artists#topTracks

Retrieves an artist's top tracks.

Parameters:

  • id โ€“ Artist ID

Returns:

  • ArtistsTopTracksResponse โ€“ The artist's top tracks

Example:

const topTracks = await client.artists.topTracks("an-id");

๐Ÿ„ผ Artists#related

Retrieves an artist's related artists.

Parameters:

  • id โ€“ Artist ID

Returns:

  • ArtistsRelatedArtistsResponse โ€“ The artist's related artists

Example:

const related = await client.artists.related("an-id");

๐Ÿ„ผ Artists#albums

Retrieves an artist's albums.

Parameters:

  • id โ€“ Artist ID

Returns:

  • ArtistsAlbumsResponse โ€“ The artist's albums

Example:

const albums = await client.artists.albums("an-id");
๐Ÿ„ฒ Albums

๐Ÿ„ฒ Shows

Wrapper for Spotify's shows API.

private


Methods

๐Ÿ„ผ Albums#get

Retrieves an album or multiple albums.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.
  • options? โ€“ Fetch options
    • market? โ€“ Country code

Returns:

If a single ID is used:

  • AlbumsSingleAlbumResponse โ€“ The album retrieved

If an array of IDs is used:

  • AlbumsMultipleAlbumsResponse โ€“ The albums retrieved

Example:

const albums = await client.albums.get(["an-id", "another-id"]);

๐Ÿ„ผ Albums#tracks

Retrieves an album's tracks.

Parameters:

  • id โ€“ The album's ID
  • options? โ€“ Fetch options
    • market โ€“ Country code
    • limit โ€“ Fetch limit
    • offset โ€“ Fetch offset

Returns:

  • AlbumsTracksResponse โ€“ The album's tracks

Example:

const tracks = await client.albums.tracks("an-id");
๐Ÿ„ฒ Tracks

๐Ÿ„ฒ Tracks

Wrapper for Spotify's tracks API.

private


Methods

๐Ÿ„ผ Tracks#get

Retrieves a track or multiple tracks.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.
  • options? โ€“ Fetch options
    • market? โ€“ Country code

Returns:

If a single ID is used:

  • TracksSingleTrackResponse โ€“ The track retrieved

If an array of IDs is used:

  • TracksMultipleTracksResponse โ€“ The tracks retrieved

๐Ÿ„ผ Tracks#audioFeatures

Retrieves a track or multiple tracks' audio features.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.
  • options? โ€“ Fetch options
    • market? โ€“ Country code

Returns:

If a single ID is used:

  • TracksSingleTrackAudioFeatureResponse โ€“ The audio feature retrieved

If an array of IDs is used:

  • TracksMultipleTracksAudioFeaturesResponse โ€“ The audio features retrieved

๐Ÿ„ผ Tracks#audioAnalysis

Retrieves a track's audio analysis

Parameters:

  • id โ€“ Track ID

Returns:

  • AudioAnalysisObject โ€“ The audio analysis
๐Ÿ„ฒ Episodes

๐Ÿ„ฒ Episodes

Wrapper for Spotify's episodes API.

private


Methods

๐Ÿ„ผ Episodes#get

Retrieves an episode or multiple episodes.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.
  • options? โ€“ Fetch options
    • market? โ€“ Country code

Returns:

If a single ID is used:

  • EpisodesSingleEpisodeResponse โ€“ The episode retrieved

If an array of IDs is used:

  • EpisodesMultipleEpisodesResponse โ€“ The episodes retrieved
๐Ÿ„ฒ Shows

๐Ÿ„ฒ Shows

Wrapper for Spotify's shows API.

private


Methods

๐Ÿ„ผ Shows#get

Retrieves a show or multiple shows.

Parameters:

  • ids โ€“ Can either be an ID or array of IDs.
  • options? โ€“ Fetch options
    • market? โ€“ Country code

Returns:

If a single ID is used:

  • ShowsSingleShowResponse โ€“ The show retrieved

If an array of IDs is used:

  • ShowsMultipleShowsResponse โ€“ The shows retrieved

Example:

const shows = await client.shows.get(["an-id", "another-id"]);

๐Ÿ„ผ Shows#episodes

Retrieves a show's episodes.

Parameters:

  • id โ€“ The show's ID

Returns:

  • ShowsEpisodesResponse โ€“ The episodes retrieved

Example:

const episodes = await client.shows.episodes("an-id");

Future features

  • Include other three authorization flows
  • Use refresh tokens
  • Spotify user auth service
    • Authorization scopes
    • Access to user-related APIs
    • Access to other APIs

spotify's People

Contributors

kelsny avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.