Class SyncLyrics

Constructors

  • Parameters

    • Optionaldata: Data

      The lyrics manager configuration

    Returns SyncLyrics

    let mxmToken;

    const LyricsManager = new SyncLyrics({
    cache: new Map(), // Anything that can store data and has a .set(K, V), .get(K) and .has(K) values
    logLevel: 'none', // One of "none" | "info" | "warn" | "error" | "debug"
    instrumentalLyricsIndicator: "", // Any string
    sources: ["musixmatch", "lrclib", "netease"], // An array with atleast one of those sources
    saveMusixmatchToken: (tokenData) => { // A custom function to save the Musixmatch token, otherwise it'll skip Musixmatch fetch
    mxmToken = tokenData;
    },
    getMusixmatchToken: () => { // A custom function to save the Musixmatch token, otherwise it'll skip Musixmatch fetch
    return mxmToken;
    },
    })

Properties

_fetching: boolean

Whetever it is fetching a song currently

_trackId: null | string

Used for the logging within the different functions and to fetch the track's data from the cache if avaible

cache: Cache<undefined | null | string, undefined | null | CacheLyrics>

Any method that can store data and has .set(), .get() and .has() functions

getMusixmatchToken: undefined | null | (() =>
    | undefined
    | null
    | TokenData
    | Promise<undefined | null | TokenData>)

Function used to fetch the Musixmatch token (required to fetch the lyrics data from Musixmatch)

instrumentalLyricsIndicator: string

The character to use for instrumental lyrics (more than 3 seconds of music without any voice)

logLevel: LogLevel

The level of the logging

lyrics: undefined | null | string

The fetched lyrics, used for the .parse() method in the LineSyncedLyricsData

saveMusixmatchToken: undefined | null | ((tokenData: TokenData) => void | Promise<void>)

Function used to save the Musixmatch token (required to fetch the lyrics data from Musixmatch)

sources: Sources

Array of sources to use, in the order they have to be fetched

Methods

  • Fetches the line synced lyrics of the song from Musixmatch, only if the search result specifies the song has line synced lyrics

    Parameters

    Returns Promise<null | string>

    The Track's Lyrics if avaible

  • Fetches the song's lyrics based on the search results

    Parameters

    • metadata: Metadata

      The song's name, artist, album or duration

    • tokenData: TokenData
    • trackId: string

      The Musixmatch track's track_id

    • commonTrackId: string

      The Musixmatch track's commontrack_id

    • hasLyrics: boolean

      Whetever the search result specifies the song has plain lyrics

    • hasLineSyncedLyrics: boolean

      Whetever the search result specifies the song has line synced lyrics

    • hasWordSyncedLyrics: boolean

      Whetever the search result specifies the song has word synced lyrics

    • lyricsType: LyricType

      The type of lyrics to fetch

    Returns Promise<null | MusixmatchLyricsFetchResult>

    Plain, line synced and word synced lyrics when avaible

  • Fetches the line synced lyrics from Netease

    Parameters

    Returns Promise<null | string>

    The track's line synced lyrics if avaible

  • Fetches the plain lyrics of the song from Musixmatch, only if the search result specifies the song has plain lyrics

    Parameters

    Returns Promise<null | string>

    The Track's Lyrics if avaible

  • Removes useless metadata returned by Netease

    Parameters

    • slyrics: string

      Lyrics returned by Netease

    Returns string

    Netease returned lyrics without extra metadata

  • Logs the text with a purple "DEBUG: " prefix

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing

  • Logs the text with a red "ERROR: " prefix

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing

  • Fetches from the cache or the sources, the song based on the track's metadata or ID

    Parameters

    Returns Promise<LyricsOutput>

    The lyrics of the song when avaible

    const LyricsManager = new SyncLyrics()

    LyricsManager.getLyrics({
    track: "the old me", // Song name
    artist: "Henry Moodie", // Song artist
    album: "good old days", // Song album
    length: 175000, // Song duration, in ms
    }).then(console.log)
  • Converts song's metadata into its ID used in the cache

    Parameters

    Returns string

    Base64 encoded metadata (used as ID in the cache)

    const LyricsManager = new SyncLyrics()

    LyricsManager.getTrackId({
    track: "the old me", // Song name
    artist: "Henry Moodie", // Song artist
    album: "good old days", // Song album
    length: 175000, // Song duration, in ms
    }).then(console.log)
  • Logs the text with a blue "INFO: " prefix

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing

  • Updates or resets the cache

    Parameters

    Returns this

    Updated SyncLyrics instance

  • Updates or resets the instrumental lyrics indicator (character used when there are more than 3 seconds of music without lyrics)

    Parameters

    Returns this

    Updated SyncLyrics instance

  • Updates or removes the saveMusixmatchToken function

    Parameters

    • OptionalsaveMusixmatchToken: ((tokenData: TokenData) => void | Promise<void>)

      The new saveMusixmatchToken function

        • (tokenData): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    Returns this

    Updated SyncLyrics instance

  • Logs the text with a yellow "WARN: " prefix

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing