musicartistinfo
v1.0.1
Published
This project is a lightweight npm library designed to interact with the Deezer API, providing simple and reusable functions to retrieve artist-related information.
Readme
musicArtistInfo
A lightweight npm library for interacting with the Deezer API to fetch artist-related data, including artist IDs, top songs, and artist details such as fan count and number of albums. This library uses asynchronous JavaScript functions with the Fetch API for efficient, non-blocking operations.
Installation
To install the library, run:
npm install musicArtistInfoUsage
Import the library in your project:
const musicArtistInfo = require('musicArtistInfo');The library provides two types of functions:
- Functions ending with
Func: These return data for programmatic use and are typically used internally by other functions. - Functions without
Func: These are user-facing, logging results directly to the console for quick testing or debugging.
Below is a detailed explanation of each function.
Functions
getIdByNameFunc(name)
Description: Retrieves the Deezer artist ID for a given artist name. This function is designed for internal use by other functions.
Parameters:
name(string): The name of the artist (e.g., "Ariana Grande").
Returns: A promise resolving to the artist's ID (number).
Example:
musicArtistInfo.getIdByNameFunc("Ariana Grande").then(id => console.log(id));
// Returns: 1562681getIdByName(name)
Description: User-facing function that fetches and logs the artist's ID and name from the Deezer API.
Parameters:
name(string): The name of the artist.
Output: Logs an object containing the artist's name and ID to the console.
Example:
musicArtistInfo.getIdByName("Ariana Grande");
// Logs: { name: "Ariana Grande", id: 1562681 }topPopularSongsByIdFunc(id, count)
Description: Retrieves the top count songs for an artist by their Deezer ID. Designed for internal use.
Parameters:
id(number): The artist's Deezer ID.count(number): The number of top songs to retrieve.
Returns: A promise resolving to an array of objects, each containing the song title and album name.
Example:
musicArtistInfo.topPopularSongsByIdFunc(1562681, 2).then(songs => console.log(songs));
// Returns: [{ title: "Song 1", albumName: "Album 1" }, { title: "Song 2", albumName: "Album 2" }]topPopularSongsById(id, count)
Description: User-facing function that fetches and logs the top count songs for an artist by their Deezer ID.
Parameters:
id(number): The artist's Deezer ID.count(number): The number of top songs to retrieve.
Output: Logs an array of objects containing song titles and album names to the console.
Example:
musicArtistInfo.topPopularSongsById(1562681, 3);
// Logs: [{ title: "Song 1", albumName: "Album 1" }, { title: "Song 2", albumName: "Album 2" }, { title: "Song 3", albumName: "Album 3" }]topPopularSongsByNameFunc(name, n)
Description: Retrieves the top n songs for an artist by their name. Uses getIdByNameFunc and topPopularSongsByIdFunc internally.
Parameters:
name(string): The name of the artist.n(number): The number of top songs to retrieve.
Returns: A promise resolving to an array of objects, each containing the song title and album name.
Example:
musicArtistInfo.topPopularSongsByNameFunc("Ariana Grande", 2).then(songs => console.log(songs[0].title));
// Returns: "Song 1"topPopularSongsByName(name, n)
Description: User-facing function that fetches and logs the top n songs for an artist by their name.
Parameters:
name(string): The name of the artist.n(number): The number of top songs to retrieve.
Output: Logs an array of objects containing song titles and album names to the console.
Example:
musicArtistInfo.topPopularSongsByName("Ariana Grande", 3);
// Logs: [{ title: "Song 1", albumName: "Album 1" }, { title: "Song 2", albumName: "Album 2" }, { title: "Song 3", albumName: "Album 3" }]artistInfoByNameFunc(name)
Description: Retrieves detailed information about an artist by their name. Designed for internal use.
Parameters:
name(string): The name of the artist.
Returns: A promise resolving to an object containing the artist's ID, name, number of fans, and number of albums.
Example:
musicArtistInfo.artistInfoByNameFunc("Ariana Grande").then(info => console.log(info.nb_fan));
// Returns: Number of fans (e.g., 12345678)artistInfoByName(name)
Description: User-facing function that fetches and logs detailed information about an artist by their name.
Parameters:
name(string): The name of the artist.
Output: Logs an object containing the artist's ID, name, number of fans, and number of albums to the console.
Example:
musicArtistInfo.artistInfoByName("Ariana Grande");
// Logs: { id: 1562681, name: "Ariana Grande", nb_fan: 12345678, nb_album: 7 }Example Usage
// Fetch and log artist info
musicArtistInfo.artistInfoByName("Ariana Grande");
// Fetch and log top 3 songs
musicArtistInfo.topPopularSongsByName("Ariana Grande", 3);
// Programmatic use of returned data
musicArtistInfo.topPopularSongsByNameFunc("Ariana Grande", 2).then(songs => {
console.log(songs[0].title); // Logs the title of the first song
});Notes
- The library assumes a stable internet connection to access the Deezer API.
- Ensure proper error handling in production code, as the Deezer API may return errors for invalid artist names or IDs.
- The
Funcversions are ideal for building more complex applications, while the non-Funcversions are convenient for quick testing.
Author
This project was created by Viggo ponturo Nygaard.
