Socket
Socket
Sign inDemoInstall

genius-fetch

Package Overview
Dependencies
13
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    genius-fetch

Fetch data from Genius


Version published
Weekly downloads
6
decreased by-40%
Maintainers
1
Install size
1.41 MB
Created
Weekly downloads
 

Readme

Source

genius-fetch

Fetch data from Genius . Requires a Genius Access Token for certain functions.

Installation

npm i genius-fetch --save

Initialization

// ESM
import Genius from 'genius-fetch';
// CJS
const Genius = require('genius-fetch');

const client = new Genius({
  // Config options go here
});


// You can change or set a config option after initialization. E.g:

client.config({
  accessToken: ...
  debug: true
  ...
});
Config optionDescription
accessTokenGenius Access Token. Certain API calls require this to be provided.
rateLimiterEnabledWhether to rate limit network requests. Default: true.
rateLimiterOptionsOptions passed to the rate limiter, which is just a wrapper around Bottleneck and thus takes the same Bottleneck settings.

Default: { maxConcurrent: 5, minTime: 100 }
cacheEnabledWhether to cache network responses. Default: true.
cacheTTLThe time-to-live of cache entries (seconds). Default: 3600.
maxCacheEntriesThe maximum number of cache entries. Once reached, older entries will be removed. Default: 200.
debugWhether to log debug messages to the console. Default: false.

Usage

const matchParams = {
  name: 'Evermore',
  artist: 'Taylor Swift',
};
const options = {
  textFormat: TextFormat.Plain,
  obtainFullInfo: true
};
return client.getSongsByBestMatch(matchParams, options).then((result) => {
  // Do something with result
});

API

Each function returns a Promise that resolves to the fetched data.

Fetching by ID

getSongById(id, options)

getAlbumById(id, options)

getArtistById(id, options)

Fetches a resource by ID. Requires Genius Access Token.

OptionDescription
textFormatFormatting to apply, where applicable: TextFormat.HTML, TextFormat.Plain or TextFormat.DOM. Default: TextFormat.HTML.
rawWhether to return raw data. Default: false.

Returns a Promise that resolves to an object representing the requested resource (i.e., Song, Album or Artist).

Fetching by Name

getSongsByName(name, options)

getAlbumsByName(name, options)

getArtistsByName(name, options)

Fetches resources matching name. Genius Access Token required if obtainFullInfo is set to true in options.

OptionDescription
limitThe number of results to return (max: 50). Default: 10.
offsetThe offset from which to return results. Default: 0 (i.e. return from first record).
obtainFullInfoWhether to fetch full info for each result by calling get<Song/Album/Artist>ById(). If false, only snippet info will be returned. If true, you should make sure you have configured the library with the accessToken config option. Default: false.
textFormatFormatting to apply, where applicable: TextFormat.HTML, TextFormat.Plain or TextFormat.DOM. Default: TextFormat.HTML.
rawWhether to return raw data. Default false.

Returns a Promise that resolves to an object with the following properties:

PropertyDescription
qThe name searched.
itemsAn array of objects representing the fetched resources (i.e., Song, Album or Artist).
limitThe number of results requested.
offsetThe offset from which results are returned.

Fetching by Best Match

getSongsByBestMatch(matchParams, options)

Returns an array of songs that best matches the criteria specified by matchParams, ordered by relevance. Requires Genius Access Token if album is specified in matchParams, or obtainFullInfo is set to true in options.

This function performs matching on a "best attempt" basis, and does not guarantee that the results returned will fully match the values specified in matchParams.

Match ParamDescription
nameRequired. The name of the song.
artistArtist
albumAlbum

You must specify name and at least one of artist and album in matchParams.

OptionDescription
limitThe number of results to return (max: 50). Default: 10.
sampleSizeThe number of songs to fetch for best-matching. If it is smaller than limit, it will automatically be set to the same value as limit. Default: 20.
textFormatFormatting to apply, where applicable: TextFormat.HTML, TextFormat.Plain or TextFormat.DOM. Default: TextFormat.HTML.
obtainFullInfo*Whether to fetch full info for each result by calling getSongById(). If false, only snippet info will be returned. If true, you should make sure you have configured the library with the accessToken config option. Default: false.

*If album is specified in matchParams, then obtainFullInfo will be overridden with true. This is because the best-match logic requires full info to be obtained.

getSongByBestMatch(matchParams, options)

Convenience function that calls getSongsByBestMatch() and returns the first result (or null if no result is found).

getAlbumsByBestMatch(matchParams, options)

Returns an array of albums that best matches the criteria specified by matchParams, ordered by relevance. Requires Genius Access Token if releaseYear, releaseMonth or releaseDay is specified in matchParams, or obtainFullInfo is set to true in options.

This function performs matching on a "best attempt" basis, and does not guarantee that the results returned will fully match the values specified in matchParams.

Match ParamDescription
nameRequired. The name of the album.
artistArtist
releaseYearYear of release.
releaseMonthMonth of release.
releaseDayDay of release.

You must specify name and at least one of the other parameters in matchParams.

OptionDescription
limitThe number of results to return (max: 50). Default: 10.
sampleSizeThe number of albums to fetch for best-matching. If it is smaller than limit, it will automatically be set to the same value as limit. Default: 20.
textFormatFormatting to apply, where applicable: TextFormat.HTML, TextFormat.Plain or TextFormat.DOM. Default: TextFormat.HTML.
obtainFullInfo*Whether to fetch full info for each result by calling getSongById(). If false, only snippet info will be returned. If true, you should make sure you have configured the library with the accessToken config option. Default: false.

*If releaseYear, releaseMonth or releaseDay is specified in matchParams, then obtainFullInfo will be overridden with true. This is because the best-match logic requires full info to be obtained.

getAlbumByBestMatch(matchParams, options)

Convenience function that calls getAlbumsByBestMatch() and returns the first result (or null if no result is found).

Util Functions

parseSongEmbed(embedValue)

Parses the contents of the embed link contained in a song resource's embed property.

Returns a Promise that resolves to an object with the following properties:

PropertyDescription
linkElementsArray of <link> elements found in the embed content.
contentPartsArray of HTML elements comprising the 'body' of the embed content.

Running the Examples

First, provide your Genius Access Token in ./examples/accessToken.ts.

Then:

$ npm run example <name of example script (without .ts file extension)>

E.g.

$ npm run example getSongsByName

Changelog

1.0.0

  • Migrate to TypeScript
  • Package as ESM + CJS hybrid module

0.1.0

  • Initial release

License

MIT

Keywords

FAQs

Last updated on 23 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc