Type Definitions

NCMGET exports the following TypeScript types for use in your projects.

SongData

Represents a song's metadata.

interface SongData {
  id: string | number;
  name: string;
  artist: string[];
  album: string;
  pic_id: string | number;
  url_id: string | number;
  lrc_id: string | number;
  source: string;
}
FieldTypeDescription
idstring | numberSong ID
namestringSong name
artiststring[]Array of artist names
albumstringAlbum name
pic_idstring | numberCover image ID
url_idstring | numberAudio URL ID
lrc_idstring | numberLyrics ID
sourcestringData source identifier

Usage:

import { NCMGET, SongData } from 'ncmget';

const ncmget = new NCMGET();
const result = await ncmget.search('淘气的Roy');
const songs: SongData[] = JSON.parse(result);

songs.forEach(song => {
  console.log(`${song.name} - ${song.artist.join(', ')}`);
});

UrlData

Represents an audio URL with metadata.

interface UrlData {
  url: string;
  size?: number;
  br?: number;
}
FieldTypeDescription
urlstringPlayable audio URL
sizenumber (optional)File size in bytes
brnumber (optional)Bitrate in kbps

Usage:

import { NCMGET, UrlData } from 'ncmget';

const ncmget = new NCMGET();
const result = await ncmget.url(3374579108);
const urlData: UrlData = JSON.parse(result);

console.log(`URL: ${urlData.url}`);
console.log(`Bitrate: ${urlData.br}kbps`);
console.log(`Size: ${urlData.size} bytes`);

LrcData

Represents lyrics with optional translation.

interface LrcData {
  lrc: string;
  tlrc: string;
}
FieldTypeDescription
lrcstringOriginal lyrics in LRC format
tlrcstringTranslated lyrics in LRC format

Usage:

import { NCMGET, LrcData } from 'ncmget';

const ncmget = new NCMGET();
const result = await ncmget.lrc(3374579108);
const lrcData: LrcData = JSON.parse(result);

console.log(lrcData.lrc);   // Original lyrics
console.log(lrcData.tlrc);  // Translation

SearchOption

Options for the search method.

interface SearchOption {
  type?: number;
  limit?: number;
  page?: number;
}
FieldTypeDefaultDescription
typenumber1Search type: 1 = song, 10 = album, 100 = artist, 1000 = playlist
limitnumber30Number of results per page
pagenumber1Page number (1-based)

Usage:

import { NCMGET, SearchOption } from 'ncmget';

const ncmget = new NCMGET();

const option: SearchOption = { type: 10, limit: 20, page: 1 };
const result = await ncmget.search('淘气的Roy', option);

ApiConfig

Internal API request configuration. Used to define how an API call should be made.

interface ApiConfig {
  method: "GET" | "POST";
  url: string;
  body: Record<string, unknown> | null;
  encode?: string;
  decode?: string;
  format?: string;
}
FieldTypeDescription
method"GET" | "POST"HTTP method
urlstringRequest URL
bodyRecord<string, unknown> | nullRequest body (for POST)
encodestring (optional)Encoding method: "netease_eapi"
decodestring (optional)Decoding method: "netease_url" or "netease_lrc"
formatstring (optional)Dot-path format string, e.g. "result.songs"

Usage:

This type is primarily used internally by the NCMGET class. You typically don't need to construct ApiConfig objects directly unless you are extending the library.

Headers

HTTP request headers type.

type Headers = Record<string, string>;

A simple key-value map of HTTP headers. Used as the type for the header instance property.

Usage:

import { NCMGET, Headers } from 'ncmget';

const ncmget = new NCMGET();
const headers: Headers = ncmget.header;

console.log(headers['User-Agent']);