musicxmatch-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

🎵 Musixmatch API

musicxmatch-api is an npm package that provides easy access to MusixMatch API endpoints. It supports searching tracks, getting track details, lyrics, artists, albums, and more. This package handles the necessary signing and authentication required by MusixMatch.

Time I spent on this project so far wakatime

Took me 1 hr 28 mins 56 secs to build this package. image

✨ Features

  • Fetch lyrics, tracks, albums, and artists
  • Automatically fetches app signature from Musixmatch
  • Proxy support built-in (currently not used internally)
  • Fully typed (TypeScript support)

📦 Installation

npm install musixmatch-api
pnpm install musixmatch-api
yarn add musixmatch-api
bun install musixmatch-api

Requires Node.js 16+

Usage

Here's how you can use the MusixMatchAPI class to interact with the MusixMatch API:

Importing the Package

import { MusixMatchAPI } from "musicxmatch-api";

Creating an Instance

const musixMatchAPI = new MusixMatchAPI();

Available Methods

searchTracks(options: { query?: string; track?: string; artist?: string; page: number; }): Promise<SearchTracksResponse>

Search for tracks based on the provided options.

const tracks = await musixMatchAPI.searchTracks({
  query: "love",
  track: "Shape of You",
  artist: "Ed Sheeran",
  page: 1,
});

getTrack(trackId?: string | null, trackIsrc?: string | null): Promise<GetTrackResponse>

Get track details by track ID or ISRC.

const track = await musixMatchAPI.getTrack("123456");

getTrackLyrics(trackId?: string | null, trackIsrc?: string | null): Promise<GetLyricsResponse>

Get lyrics of a track by track ID or ISRC.

const lyrics = await musixMatchAPI.getTrackLyrics("123456");

searchArtist(query: string, page?: number): Promise<SearchArtistsResponse>

Search for artists by name.

const artist = await musixMatchAPI.searchArtist("Queen");

getArtist(artistId: string): Promise<GetArtistResponse>

Get artist details by artist ID.

const artist = await musixMatchAPI.getArtist("118");

getArtistAlbums(artistId: string, page?: number): Promise<GetArtistAlbumsResponse>

Get albums of an artist by artist ID.

const albums = await musixMatchAPI.getArtistAlbums("118");

getAlbum(albumId: string): Promise<GetAlbumResponse>

Get album details by album ID.

const album = await musixMatchAPI.getAlbum("32541950");

getAlbumTracks(albumId: string, page?: number): Promise<GetAlbumTracksResponse>

Get tracks of an album by album ID.

const tracks = await musixMatchAPI.getAlbumTracks("32541950");

getTrackLyricsTranslation(trackId: string, language: string): Promise<GetTrackLyricsTranslationResponse>

Get lyrics translation of a track by track ID and language.

const translation = await musixMatchAPI.getTrackLyricsTranslation("123456", "es");

rawRequest(endpoint: string): Promise<any>

Make a raw request to any MusixMatch API endpoint.

const response = await musixMatchAPI.rawRequest("track.get?app_id=community-app-v1.0&format=json&track_id=123456");

Example

import { MusixMatchAPI } from "musicxmatch-api";

const musixMatchAPI = new MusixMatchAPI();

async function fetchTrackDetails() {
  try {
    const track = await musixMatchAPI.getTrack("123456");
    console.log(track);
  } catch (error) {
    console.error("Error fetching track details:", error);
  }
}

fetchTrackDetails();

License

This package is licensed under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.

Package Sidebar

Install

npm i musicxmatch-api

Weekly Downloads

4

Version

1.0.1

License

ISC

Unpacked Size

59.9 kB

Total Files

23

Last publish

Collaborators

  • visa2code