searchtify

1.2.7 • Public • Published

searchtify

a search package for spotify that requires no credentials!



disclaimer

the point of this package is NOT to provide some sort of "clean" API for spotify searching. maybe in the future.

the point of this package is to provide a wrapper for spotify's complex API. they are constantly changing parameters and endpoints. it's actually kind of annoying.



usage

usage is relatively simple:

import Spotify from 'searchtify';

const spotify = new Spotify();

const search = await spotify.search('Blinding Lights');
console.log(search.tracksV2.items[0].item.data);

and its album:

// uri format: spotify:album:4yP0hdKOZPNshxUOjY0cZj
const album = await spotify.getAlbum(search.tracksV2.items[0].item.data.albumOfTrack.uri);
console.log(album);

or, for example, an artist:

// uri format: spotify:artist:1Xyo4u8uXC1ZmMpatF05PJ
const artist = await spotify.getArtist(search.tracksV2.items[0].item.data.artists.items[0].uri);
console.log(artist);

search consists of:

  • albumsV2
  • artists
  • audiobooks
  • chipOrder
    • this is not actual data, just the order of the tabs spotify puts on their bar
  • episodes
  • genres
  • playlists
  • podcasts
  • topResultsV2
    • has a "featured" prop with an item array as well
  • tracksV2
  • users

all of these consist of the following props:

  1. an array named items with various data related to the item
  2. a number named totalCount with the totals if you were to increase the limit

searching also allows you to pass various search parameters:

const search2 = await spotify.search('Hurry Up Tomorrow', { limit: 25 });
console.log(search2.tracksV2.items);

notable parameters include:

  • limit - number - the limit of results for each items array
  • offset - number - the offset to start at
  • numberOfTopResults - number - the number of items in topResultsV2

there are also various boolean parameters that explain themselves:

  • includeAudiobooks
  • includeArtistHasConcertsField
  • includePreReleases
  • includeLocalConcertsField
  • includeAuthors

if there's something you need from here, enable it as part of the search parameters

you can also search for the things on the homepage:

const popular = await spotify.getPopular();
console.log(popular[0].data.title.translatedBaseText + ':');
console.log(popular[0].sectionItems.items[0].content.data);

the structure of the response is the homepage categories and data going down.

getPopular accepts one argument, which is a timezone in the format of "America/New_York".

it defaults to the user's timezone.

you can log in by specifying a sp_dc cookie in the login function. the cookie should be everything after the sp_dc= and everything before the semicolon (;).

await spotify.login(`XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`);

please put the cookie in a secure place, as it grants full access to your spotify account. the login function returns the result of the below whoAmI function:

const iAm = await spotify.whoAmI();
console.log('i am', iAm.name);

this tells you who the name of the account as well as some basic information (avatar, etc).

you can use the synchronous isLoggedIn to find out if you're logged in:

const isLoggedIn = spotify.isLoggedIn();
if (isLoggedIn) console.log('hi, i am', (await spotify.whoAmI()).name);
else console.log('i am not logged in :(');

this package may lead to your spotify account being banned. not my fault, use responsibly.

you can also set a custom user agent using setUserAgent:

spotify.setUserAgent('putting something like this in the useragent will probably flag your IP');

[!NOTE] as of 1.2.0, the accessToken and clientToken will automatically refresh, meaning searchtify can be used in 24/7 programs rather than snippets.



made with ❤️

Package Sidebar

Install

npm i searchtify

Weekly Downloads

103

Version

1.2.7

License

none

Unpacked Size

16 kB

Total Files

4

Last publish

Collaborators

  • xthonk