spotify-recommendation
v1.0.1
Published
A module generates recommendations from tracks, artists, etc...
Downloads
9
Maintainers
Readme
What is this?
This module generates recommended songs for you using Spotify's Web API
Installation
npm install spotify-recommendation
// or
yarn add spotify-recommendation
Usage
const spotify-recommendation = require('spotify-recommendation')
// or
import { generateRecommendations, getAudioFeatures, getArtistGenres } from 'spotify-recommendation'
spotify-recommendation.generateRecommendations(accessToken, trackId, artists, limit)
// or
generateRecommendations(accessToken, trackId, artistGenres, limit)
Parameters
- accessToken* (string) - Access token you get by logging in user
- trackId* (array, max
100
) - artists (optional, array, max
100
) - limit (optional, number, default
100
)
Functions
generateRecommendations - This function generates recommendations based on given tracks and artists.
getAudioFeatures - This function returns audio features of given songs. (acousticness, danceability, energy, loudness, speechiness, tempo)
getArtistGenres - Returns the two most prevalent genres among artists.
All functions returns promise so you can use them like
generateRecommendations(accessToken, trackIds, artists, 50).then((data) => {
console.log(data);
recommendedSongs = data;
}
Returned Data
- generateRecommendations
{
album: {
album_type: 'ALBUM',
artists: [ [Object] ],
available_markets: [
'AR', 'AU', 'AT', 'BE', 'BO', 'BR', 'BG', 'CA', 'CL', 'CO',
'CR', 'CY', 'CZ', 'DK', 'DO', 'DE', 'EC', 'EE', 'SV', 'FI',
'FR', 'GR', 'GT', 'HN', 'HK', 'HU', 'IS', 'IE', 'IT', 'LV',
'LT', 'LU', 'MY', 'MT', 'MX', 'NL', 'NZ', 'NI', 'NO', 'PA',
'PY', 'PE', 'PH', 'PL', 'PT', 'SG', 'SK', 'ES', 'SE', 'CH',
'TW', 'TR', 'UY', 'US', 'GB', 'AD', 'LI', 'MC', 'ID', 'JP',
'TH', 'VN', 'RO', 'IL', 'ZA', 'SA', 'AE', 'BH', 'QA', 'OM',
'KW', 'EG', 'MA', 'DZ', 'TN', 'LB', 'JO', 'PS', 'IN', 'BY',
'KZ', 'MD', 'UA', 'AL', 'BA', 'HR', 'ME', 'MK', 'RS', 'SI',
'KR', 'BD', 'PK', 'LK', 'GH', 'KE', 'NG', 'TZ', 'UG', 'AG',
],
external_urls: {
spotify: 'https://open.spotify.com/album/3BIiOsLIJBsH9UJYFRqfxs'
},
href: 'https://api.spotify.com/v1/albums/3BIiOsLIJBsH9UJYFRqfxs',
id: '3BIiOsLIJBsH9UJYFRqfxs',
images: [ [Object], [Object], [Object] ],
name: 'Ölüm Dansı',
release_date: '2023-08-04',
release_date_precision: 'day',
total_tracks: 13,
type: 'album',
uri: 'spotify:album:3BIiOsLIJBsH9UJYFRqfxs'
},
artists: [
{
external_urls: [Object],
href: 'https://api.spotify.com/v1/artists/0PhqM7UAxtvWYi5j4MwxSl',
id: '0PhqM7UAxtvWYi5j4MwxSl',
name: 'Dolu Kadehi Ters Tut',
type: 'artist',
uri: 'spotify:artist:0PhqM7UAxtvWYi5j4MwxSl'
}
],
available_markets: [
'AR', 'AU', 'AT', 'BE', 'BO', 'BR', 'BG', 'CA', 'CL', 'CO',
'CR', 'CY', 'CZ', 'DK', 'DO', 'DE', 'EC', 'EE', 'SV', 'FI',
'FR', 'GR', 'GT', 'HN', 'HK', 'HU', 'IS', 'IE', 'IT', 'LV',
'LT', 'LU', 'MY', 'MT', 'MX', 'NL', 'NZ', 'NI', 'NO', 'PA',
'PY', 'PE', 'PH', 'PL', 'PT', 'SG', 'SK', 'ES', 'SE', 'CH',
'TW', 'TR', 'UY', 'US', 'GB', 'AD', 'LI', 'MC', 'ID', 'JP',
'TH', 'VN', 'RO', 'IL', 'ZA', 'SA', 'AE', 'BH', 'QA', 'OM',
'KW', 'EG', 'MA', 'DZ', 'TN', 'LB', 'JO', 'PS', 'IN', 'BY',
'KZ', 'MD', 'UA', 'AL', 'BA', 'HR', 'ME', 'MK', 'RS', 'SI',
'KR', 'BD', 'PK', 'LK', 'GH', 'KE', 'NG', 'TZ', 'UG', 'AG',
],
disc_number: 1,
duration_ms: 217546,
explicit: false,
external_ids: { isrc: 'QM4TX2382181' },
external_urls: { spotify: 'https://open.spotify.com/track/1udlzg1P1Tqh4WGouHwXJA' },
href: 'https://api.spotify.com/v1/tracks/1udlzg1P1Tqh4WGouHwXJA',
id: '1udlzg1P1Tqh4WGouHwXJA',
is_local: false,
name: 'Ölüm Dansı',
popularity: 46,
preview_url: 'https://p.scdn.co/mp3-preview/140047a779bf0a63c64eb3f724a03f5eee8246ce?cid=a338ac7473534abcb3c7b9eacfdd3989',
track_number: 13,
type: 'track',
uri: 'spotify:track:1udlzg1P1Tqh4WGouHwXJA'
}
- getAudioFeatures
{
acousticness: 0.28753,
danceability: 0.533,
energy: 0.70733,
loudness: -6.58,
speechiness: 0.044,
tempo: 128.29433
}
- getArtistGenres
["turkish rock", "alternative rock"];