genius-lyrics-scrape
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "genius-lyrics-scrape", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Genius Lyrics Scraper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,3 +1,6 @@ | ||
const constants = require('../util/constants.js') | ||
const scrapeLyrics = require('./functions/scrapeLyrics.js') | ||
const searchAPI = require('./functions/searchAPI.js') | ||
const getArtist = require('./functions/getArtist.js') | ||
const getSongByArtist = require('./functions/getSongByArtist.js') | ||
@@ -33,2 +36,3 @@ /** | ||
* @param {String} query | ||
* @returns {Promise<import('../structures/SearchResult')>} | ||
*/ | ||
@@ -38,4 +42,24 @@ searchAPI (query) { | ||
} | ||
/** | ||
* Gets Genius Artist info by ID | ||
* @param {Number} id The Artist's Genius ID | ||
* @returns {Promise<import('../structures/Artist.js')>} Artist | ||
*/ | ||
getArtist (id) { | ||
return getArtist(id, this.token) | ||
} | ||
/** | ||
* Gets the list of song created by the artist | ||
* @param {Number} id The Artist's Genius ID | ||
* @param {Object} [opts] Optional options | ||
* @returns {Promise<import('../structures/Song')[]>} | ||
*/ | ||
getSongByArtist (id, opts) { | ||
opts = Object.assign(constants.getSongByArtistDefaultOpts, opts) | ||
return getSongByArtist(id, opts, this.token) | ||
} | ||
} | ||
module.exports = Client |
@@ -8,13 +8,16 @@ /** | ||
* @constructor | ||
* @param {Number} id The Genius ID of the artist | ||
* @param {String} name The name of the artist | ||
* @param {String} imageURL The URL of the artist avatar | ||
* @param {Boolean} verified Whether this artist page is verified | ||
* @param {Object} artistData Artist Object from Genius API | ||
*/ | ||
constructor (id, name, imageURL, verified) { | ||
constructor (artistData) { | ||
if (typeof artistData.songs === 'undefined') { artistData.songs = [] } | ||
this._setup(artistData) | ||
} | ||
_setup (artistData) { | ||
/** | ||
* The Genius ID of the artist | ||
* The ID for the artist | ||
* @type {Number} | ||
*/ | ||
this.id = id | ||
this.id = artistData.id | ||
@@ -25,3 +28,3 @@ /** | ||
*/ | ||
this.name = name | ||
this.name = artistData.name | ||
@@ -32,3 +35,3 @@ /** | ||
*/ | ||
this.avatar = imageURL | ||
this.avatar = artistData.image_url | ||
@@ -39,3 +42,51 @@ /** | ||
*/ | ||
this.verified = verified | ||
this.verified = artistData.is_verified | ||
if (typeof artistData.alternate_names === 'undefined') artistData.alternate_names = [] | ||
artistData.alternate_names.unshift(this.name) | ||
/** | ||
* Artist alternative name (aliases) including their primary name | ||
* @type {String[]} | ||
*/ | ||
this.names = artistData.alternate_names | ||
/** | ||
* The Artist's follower count on Genius | ||
* @type {Number|null} | ||
*/ | ||
this.followerCount = artistData.follower_count | ||
/** | ||
* Whether this Artist page is a Genius meme | ||
* @type {Boolean} | ||
*/ | ||
this.meme = artistData.is_meme_verified | ||
/** | ||
* Genius URL of the artist | ||
* @type {String} | ||
*/ | ||
this.url = artistData.url | ||
/** | ||
* Artist's social media usernames | ||
* @type {Object} | ||
*/ | ||
this.social = { | ||
/** | ||
* Artist's Facebook username | ||
* @type {String|null} | ||
*/ | ||
facebook: artistData.facebook_name, | ||
/** | ||
* Artist's Instagram username | ||
* @type {String|null} | ||
*/ | ||
instagram: artistData.instagram_name, | ||
/** | ||
* Artist's Twitter username | ||
* @type {String|null} | ||
*/ | ||
twitter: artistData.twitter_name | ||
} | ||
} | ||
@@ -42,0 +93,0 @@ } |
@@ -31,3 +31,5 @@ const Song = require('./Song.js') | ||
data.forEach((v) => { | ||
this.result.push(new Song(v)) | ||
if (v.type !== 'song') return | ||
this.result.push(new Song(v.result)) | ||
}) | ||
@@ -34,0 +36,0 @@ } |
@@ -11,7 +11,8 @@ const scrapeLyrics = require('../client/functions/scrapeLyrics.js') | ||
* Constructs | ||
* @param {GeniusHits} hits Genius API Hits | ||
* @param {GeniusHitsResult} result Genius API Hits | ||
* @constructor | ||
*/ | ||
constructor (hits) { | ||
constructor (result) { | ||
// console.log(hits) | ||
if (hits.type === 'song' && excludedArtists.every(e => hits.result.primary_artist.name !== e)) this._setup(hits) | ||
if (excludedArtists.every(e => result.primary_artist.name !== e)) this._setup(result) | ||
} | ||
@@ -21,10 +22,7 @@ | ||
* Class setup function | ||
* @param {GeniusHits} hits Genius Hits | ||
* @param {GeniusHitsResult} hits Genius Hits | ||
* @private | ||
* @returns {void} | ||
*/ | ||
_setup (hits) { | ||
const res = hits.result | ||
const artist = res.primary_artist | ||
_setup (result) { | ||
/** | ||
@@ -34,3 +32,3 @@ * The ID of the song | ||
*/ | ||
this.songID = res.id | ||
this.songID = result.id | ||
@@ -43,3 +41,3 @@ /** | ||
*/ | ||
this.fullTitle = res.full_title | ||
this.fullTitle = result.full_title | ||
@@ -50,3 +48,3 @@ /** | ||
*/ | ||
this.title = res.title | ||
this.title = result.title | ||
@@ -58,3 +56,3 @@ /** | ||
*/ | ||
this.titleFeatured = res.title_with_featured | ||
this.titleFeatured = result.title_with_featured | ||
@@ -65,3 +63,3 @@ /** | ||
*/ | ||
this.primaryArtist = new Artist(artist.id, artist.name, artist.image_url, artist.is_verified) | ||
this.primaryArtist = new Artist(result.primary_artist) | ||
@@ -72,3 +70,3 @@ /** | ||
*/ | ||
this.songArt = res.song_art_image_url | ||
this.songArt = result.song_art_image_url | ||
@@ -79,3 +77,3 @@ /** | ||
*/ | ||
this.headerImage = res.header_image_url | ||
this.headerImage = result.header_image_url | ||
@@ -86,3 +84,3 @@ /** | ||
*/ | ||
this.url = res.url | ||
this.url = result.url | ||
} | ||
@@ -95,3 +93,3 @@ | ||
*/ | ||
async lyrics () { | ||
get scrapeLyrics () { | ||
return scrapeLyrics(this.url) | ||
@@ -98,0 +96,0 @@ } |
@@ -28,1 +28,12 @@ /** | ||
] | ||
/** | ||
* Default options for getSongByArtist() | ||
* @typedef {Object} getSongByArtistOptions | ||
* @property {'popularity'|'title'} sort How should the result be sorted | ||
* @property {Number} per_page Amount of song that should be returned | ||
*/ | ||
exports.getSongByArtistDefaultOpts = { | ||
sort: 'popularity', | ||
per_page: 20 | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53945
18
472