EasySpotifyTS - A Spotify Web Api TS Wrapper
This is a Javascript library written in Typescript that wraps Spotify Web API to make your spotify responses and requests benefit from autocompletion. It's still not published and in development. See features list to check what else I plan to add to this library.
Installation and Usage
This library is lightweight and only have one external dependency, which is axios, a powerful HTTP requests library. Also, if you like type hints, or intellisense, with easy-spotify-ts you have them for responses that come from Spotify Web API.
NodeJS Environment
Install easy-spotify-ts, and then just import and use the library:
terminal
$ npm install easy-spotify-ts --save
app.js
const { EasySpotify, EasySpotifyConfig } = require("easy-spotify-ts");
import { EasySpotify, EasySpotifyConfig } from 'easy-spotify-ts';
const spotify = new EasySpotify(new EasySpotifyConfig("your-api-token"));
spotify.getAlbums(["382ObEPsp2rxGrnsizN5TX", "1A2GTWGtFfWp7KSQTwWOyo"], {market: "ES"}).then((albums) => {
console.log(albums);
}).catch((error) => {
console.log(error);
});
Methods available
getAlbum(id: string, options?: GetAlbumOptions): Promise<Album>
This method returns an album object with the provided id.
Check official documentation page
const album = await spotify.getAlbum("382ObEPsp2rxGrnsizN5TX", {market: "ES"});
getAlbums(ids: string[], options?: GetAlbumOptions): Promise<Album[]>
This method returns an array of album objects with the provided ids.
Check official documentation page
const albums = await spotify.getAlbums(["382ObEPsp2rxGrnsizN5TX", "1A2GTWGtFfWp7KSQTwWOyo"], {market: "ES"});
getAlbumTracks(id: string, options?: GetAlbumTracksOptions): Promise<PagingTracks>
This method returns a paging object with the tracks for an album given it's id. Tracks are in items property.
Check official documentation page
const tracks = await spotify.getAlbumTracks("1A2GTWGtFfWp7KSQTwWOyo", {limit: 10, offset: 1, market: "ES"});
getArtist(id: string): Promise<Artist>
This method returns an complete artist object for the given id.
Check official documentation page
const artist = await spotify.getArtist("0OdUWJ0sBjDrqHygGUXeCF");
getArtists(id: string[]): Promise<Artist[]>
This method returns an array of artist objects for the given ids.
Check official documentation page
const artists = await spotify.getArtists(["0oSGxfWSnnOXhD2fKuz2Gy,3dBVyJ7JuOMt4GE9607Qin"]);
getArtistAlbums(id: string, options?: GetArtistAlbumsOptions): Promise<PagingAlbums>
This method returns an array of simplified album objects for the given artist id.
Check official documentation page
const artistAlbums = await spotify.getArtistAlbums("4aawyAB9vmqN3uQ7FjRGTy", {
include_groups: "appears_on",
limit: 3,
offset: 0,
market: "ES"
});
getArtistTopTracks(id: string, options?: GetAlbumOptions): Promise<Track[]>
This method returns an array of up to 10 top Track objects for the given artist id.
Check official documentation page
const topTracks = await spotfiy.getArtistTopTracks("43ZHCT0cAZBISjO8DG9PnE", {market: "SE"});
getArtistRelatedArtists(id: string): Promise<Artist[]>
This method returns an array of related artists for the given artist id.
Check official documentation page
const relatedArtists = await spotfiy.getArtistRelatedArtists("43ZHCT0cAZBISjO8DG9PnE");
searchAlbums(query: string, options?: OptionalRequestParams): Promise<PagingAlbums>
This method returns an paging object of albums for the given query.
Check official documentation page
const albums = await spotify.searchAlbums("Rock", {limit: 2});
searchArtists(query: string, options?: OptionalRequestParams): Promise<PagingArtists>
This method returns an paging object of artists for the given query.
Check official documentation page
const artists = await spotify.searchArtists("Elvis", {limit: 2});
searchPlaylists(query: string, options?: OptionalRequestParams): Promise<PagingPlaylists>
This method returns an paging object of playlists for the given query.
Check official documentation page
const playlists = await spotify.searchPlaylists("abba", {limit: 2, market: "US"});
searchTracks(query: string, options?: OptionalRequestParams): Promise<PagingTracks>
This method returns an paging object of tracks for the given query.
Check official documentation page
const tracks = await spotify.searchTracks("love", {limit: 2});
search(query: string, options: SearchRequestParams): Promise<PagingSearch>
This method returns an object that may contain albums, artists, playlists or tracks paging object. Under options,
you should define the type as comma-separated list of wich ones you want (in singular).
Check official documentation page
const result = await spotify.search("love", {type: "artist,playlist", limit: 2});
getBrowseCategory(id: string, options?: { country?: string, locale?: string }): Promise<Category>
This method returns a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
Check official documentation page
const result = await spotify.getBrowseCategory("party", {country: "US"});
getBrowseCategoryPlaylists(id: string, options: { country?: string, limit?: number, offset?: number }): Promise<PagingPlaylists>
This method returns a paged list of Spotify playlists tagged with a particular category.
Check official documentation page
const result = await spotify.getBrowseCategoryPlaylists("party", {country: "US"});
getBrowseListOfCategories(options: {locale?: string, country?: string, offset?: number, limit?: number}): Promise<PagingCategories>
This method returns a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
Check official documentation page
const result = await spotify.getBrowseListOfCategories({country: "US", limit: 10});
getBrowseFeaturedPlaylists(options: {locale?: string, country?: string, timestamp?: Date, limit?: number, offset?: number}): Promise<FeaturedPlaylists>
This method returns a list of Spotify featured playlists (shown, for example, on a Spotify player’s ‘Browse’ tab).
Check official documentation page
const result = await spotify.getBrowseFeaturedPlaylists({country: "US", limit: 10});
getBrowseNewReleases(options: {country?: string, limit?: number, offset?: number}): Promise<FeaturedAlbums>
This method returns a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
Check official documentation page
const result = await spotify.getBrowseNewReleases({country: "US", limit: 10});
getBrowseRecommendations(query: RecommendationsQuery): Promise<PagingCategories>
This method can create a playlist-style listening experience based on seed artists, tracks and genres. There is a huge query options to use,
I suggest you to really check the documentation, though, each target_*
field has a hint when you type that should help you know what you're
doing.
Check official documentation page
const result = await spotify.getBrowseRecommendations(
{
limit: 10,
seed_tracks: ["4NHQUGzhtTLFvgF5SZesLK", "1VBflYyxBhnDc9uVib98rw"],
target_loudness: 0.2,
min_instrumentalness: 0.4,
max_instrumentalness: 0.9,
}
);
Features to implement
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details