From 7b05d6c00598da2e31119179089aef8390b2b0f5 Mon Sep 17 00:00:00 2001 From: Stef-00012 Date: Mon, 18 Nov 2024 16:03:03 +0100 Subject: [PATCH] Automated Push --- .gitignore | 4 +- dist/index.js | 906 ------------------ dist/index.min.js | 50 - docs/classes/SyncLyrics.html | 74 +- docs/functions/normalize.html | 4 +- docs/index.html | 4 +- docs/interfaces/Cache.html | 10 +- .../interfaces/CacheLineSyncedLyricsData.html | 6 +- docs/interfaces/CacheLyrics.html | 8 +- docs/interfaces/Data.html | 14 +- docs/interfaces/FormattedLyric.html | 6 +- docs/interfaces/LineSyncedLyricsData.html | 8 +- docs/interfaces/LrcLibFetchResult.html | 10 +- docs/interfaces/Lyrics.html | 8 +- docs/interfaces/LyricsOutput.html | 14 +- docs/interfaces/Metadata.html | 16 +- docs/interfaces/MusixmatchFetchResult.html | 10 +- .../MusixmatchLyricsFetchResult.html | 8 +- docs/interfaces/MusixmatchSearchResult.html | 12 +- docs/interfaces/NeteaseFetchResult.html | 10 +- docs/interfaces/PlainLyricsData.html | 6 +- docs/interfaces/TokenData.html | 10 +- docs/interfaces/WordSyncedLyrics.html | 10 +- docs/interfaces/WordSyncedLyricsData.html | 6 +- docs/interfaces/WordSyncedLyricsLine.html | 6 +- docs/modules.html | 4 +- docs/sitemap.xml | 58 +- docs/types/LogLevel.html | 2 +- docs/types/LyricType.html | 2 +- docs/types/Sources.html | 4 +- docs/variables/logLevels.html | 2 +- docs/variables/lyricType-1.html | 2 +- docs/variables/sources-1.html | 2 +- package.json | 2 +- types/index.d.ts | 157 --- 35 files changed, 171 insertions(+), 1284 deletions(-) delete mode 100644 dist/index.js delete mode 100644 dist/index.min.js delete mode 100644 types/index.d.ts diff --git a/.gitignore b/.gitignore index 045f43b..16e3c3c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ node_modules biome.json /reminder.txt release.js -# /dist -# /types \ No newline at end of file +/dist +/types \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d5de91e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,906 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SyncLyrics = exports.logLevels = exports.lyricType = exports.sources = void 0; -exports.normalize = normalize; -const util_1 = require("util"); -const sleep = (0, util_1.promisify)(setTimeout); -exports.sources = ["musixmatch", "lrclib", "netease"]; -exports.lyricType = ["plain", "lineSynced", "wordSynced"]; -exports.logLevels = { - debug: 4, - error: 3, - warn: 2, - info: 1, - none: 0, -}; -class SyncLyrics { - constructor(data) { - if (typeof (data === null || data === void 0 ? void 0 : data.logLevel) === "string" && - !Object.keys(exports.logLevels).includes(data.logLevel)) - throw new Error(`SyncLyrics: logLevel must be one of "${Object.keys(exports.logLevels).join('" | "')}"`); - if ((data === null || data === void 0 ? void 0 : data.instrumentalLyricsIndicator) && - typeof data.instrumentalLyricsIndicator !== "string") - throw new Error("SyncLyrics: instrumentalLyricsIndicator must be a string"); - if ((data === null || data === void 0 ? void 0 : data.sources) && - (!Array.isArray(data.sources) || data.sources.length <= 0)) - throw new Error('SyncLyrics: sources must be an array with atleast one of "musixmatch" | "lrclib" | "netease"'); - if ((data === null || data === void 0 ? void 0 : data.cache) && - (typeof data.cache.get !== "function" || - typeof data.cache.set !== "function" || - typeof data.cache.has !== "function")) - throw new Error("SyncLyrics: cache must have .get, .set and .has methods"); - if ((data === null || data === void 0 ? void 0 : data.saveMusixmatchToken) && - typeof data.saveMusixmatchToken !== "function") - throw new Error("SyncLyrics: saveMusixmatchToken must be a function"); - if ((data === null || data === void 0 ? void 0 : data.getMusixmatchToken) && - typeof data.getMusixmatchToken !== "function") - throw new Error("SyncLyrics: getMusixmatchToken must be a function"); - this.logLevel = (data === null || data === void 0 ? void 0 : data.logLevel) || "none"; - this.instrumentalLyricsIndicator = (data === null || data === void 0 ? void 0 : data.instrumentalLyricsIndicator) || ""; - this.sources = (data === null || data === void 0 ? void 0 : data.sources) || ["musixmatch", "lrclib", "netease"]; - this.cache = (data === null || data === void 0 ? void 0 : data.cache) || new Map(); - this.saveMusixmatchToken = data === null || data === void 0 ? void 0 : data.saveMusixmatchToken; - this.getMusixmatchToken = data === null || data === void 0 ? void 0 : data.getMusixmatchToken; - this.lyrics = null; - this._trackId = null; - this._fetching = false; - this._fetchLineSyncedLyricsMusixmatch = - this._fetchLineSyncedLyricsMusixmatch.bind(this); - this._fetchWordSyncedLyricsMusixmatch = - this._fetchWordSyncedLyricsMusixmatch.bind(this); - this._fetchPlainLyricsMusixmatch = - this._fetchPlainLyricsMusixmatch.bind(this); - this._searchLyricsMusixmatch = this._searchLyricsMusixmatch.bind(this); - this._fetchLyricsMusixmatch = this._fetchLyricsMusixmatch.bind(this); - this.getMusixmatchUsertoken = this.getMusixmatchUsertoken.bind(this); - this.fetchLyricsMusixmatch = this.fetchLyricsMusixmatch.bind(this); - this._searchLyricsNetease = this._searchLyricsNetease.bind(this); - this._parseNeteaseLyrics = this._parseNeteaseLyrics.bind(this); - this._fetchLyricsNetease = this._fetchLyricsNetease.bind(this); - this.fetchLyricsNetease = this.fetchLyricsNetease.bind(this); - this.fetchLyricsLrclib = this.fetchLyricsLrclib.bind(this); - this.parseLyrics = this.parseLyrics.bind(this); - this._getLyrics = this._getLyrics.bind(this); - this.getTrackId = this.getTrackId.bind(this); - this.getLyrics = this.getLyrics.bind(this); - this.debugLog = this.debugLog.bind(this); - this.errorLog = this.errorLog.bind(this); - this.infoLog = this.infoLog.bind(this); - this.warnLog = this.warnLog.bind(this); - } - getMusixmatchUsertoken(cookies) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e, _f; - this.infoLog("Getting Musixmatch token..."); - if (!this.saveMusixmatchToken || !this.getMusixmatchToken) { - this.infoLog("Musixmatch token functions are not avaible, skipping..."); - return null; - } - const tokenData = yield this.getMusixmatchToken(); - if (tokenData) - return tokenData; - this.infoLog("Fetching the token from the API..."); - const url = "https://apic-desktop.musixmatch.com/ws/1.1/token.get?user_language=en&app_id=web-desktop-app-v1.0"; - try { - const res = yield fetch(url, { - redirect: "manual", - headers: { - cookie: cookies, - }, - }); - if (res.status === 301) { - this.debugLog("Successfully received the 'set-cookie' redirect response"); - const setCookie = res.headers - .getSetCookie() - .map((cookie) => cookie.split(";").shift()) - .filter((cookie) => cookie.split("=").pop() !== "unknown") - .join("; "); - this.debugLog("Re-fetching with the cookies..."); - return yield this.getMusixmatchUsertoken(setCookie); - } - if (!res.ok) { - this.warnLog(`The usertoken API request failed with the status ${res.status} (${res.statusText})`); - return null; - } - const data = yield res.json(); - if (((_b = (_a = data === null || data === void 0 ? void 0 : data.message) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.status_code) === 401 && - ((_d = (_c = data === null || data === void 0 ? void 0 : data.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.hint) === "captcha") { - this.warnLog("Musixmatch usertoken endpoint is being ratelimited, retrying in 10 seconds..."); - yield sleep(10000); - this.infoLog("Retrying to fetch the Musixmatch usertken..."); - return yield this.getMusixmatchUsertoken(cookies); - } - const usertoken = (_f = (_e = data === null || data === void 0 ? void 0 : data.message) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.user_token; - if (!usertoken) { - this.infoLog("The API response did not include the usertoken"); - return null; - } - const json = { - cookies, - usertoken, - expiresAt: new Date(Date.now() + 10 * 60 * 1000).getTime(), - }; - yield this.saveMusixmatchToken(json); - this.infoLog("Successfully fetched the usertoken"); - return json; - } - catch (e) { } - }); - } - _searchLyricsMusixmatch(metadata, tokenData) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s; - if (!metadata || !tokenData) - return null; - const duration = Number.parseFloat(metadata.length) / 1000; - const searchParams = new URLSearchParams({ - app_id: "web-desktop-app-v1.0", - usertoken: tokenData.usertoken, - q_track: metadata.track || "", - q_artist: metadata.artist || "", - q_album: metadata.album || "", - page_size: 20, - page: 1, - q_duration: duration || "", - s_track_rating: "asc", - }); - const url = `https://apic-desktop.musixmatch.com/ws/1.1/track.search?${searchParams}`; - try { - this.debugLog("Musixmatch search fetch URL:", url); - const res = yield fetch(url, { - headers: { - cookie: tokenData.cookies, - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Musixmatch - Search]`); - return null; - } - const data = yield res.json(); - if (((_b = (_a = data === null || data === void 0 ? void 0 : data.message) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.status_code) === 401 && - ((_d = (_c = data === null || data === void 0 ? void 0 : data.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.hint) === "captcha") { - this.warnLog("The usertoken has been temporary blocked for too many requests (captcha) [Musixmatch - Search]"); - return null; - } - this.debugLog("Musixmatch search results:", (_f = (_e = data === null || data === void 0 ? void 0 : data.message) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.track_list); - if (((_j = (_h = (_g = data === null || data === void 0 ? void 0 : data.message) === null || _g === void 0 ? void 0 : _g.body) === null || _h === void 0 ? void 0 : _h.track_list) === null || _j === void 0 ? void 0 : _j.length) <= 0) { - this.infoLog("No songs were found [Musixmatch - Search]"); - return null; - } - const track = (_m = (_l = (_k = data === null || data === void 0 ? void 0 : data.message) === null || _k === void 0 ? void 0 : _k.body) === null || _l === void 0 ? void 0 : _l.track_list) === null || _m === void 0 ? void 0 : _m.find((listItem) => { - var _a, _b, _c, _d; - return ((_a = listItem.track.track_name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === - ((_b = metadata.track) === null || _b === void 0 ? void 0 : _b.toLowerCase()) && - ((_c = listItem.track.artist_name) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes((_d = metadata.artist) === null || _d === void 0 ? void 0 : _d.toLowerCase())); - }); - this.debugLog("Musixmatch search filtered track:", track); - if (!track) { - this.infoLog("No songs were found with the current name and artist [Musixmatch - Search]"); - return null; - } - this.debugLog(track); - const commonTrackId = (_o = track === null || track === void 0 ? void 0 : track.track) === null || _o === void 0 ? void 0 : _o.commontrack_id; - const trackId = (_p = track === null || track === void 0 ? void 0 : track.track) === null || _p === void 0 ? void 0 : _p.track_id; - const hasLyrics = (_q = track === null || track === void 0 ? void 0 : track.track) === null || _q === void 0 ? void 0 : _q.has_lyrics; - const hasLineSyncedLyrics = (_r = track === null || track === void 0 ? void 0 : track.track) === null || _r === void 0 ? void 0 : _r.has_subtitles; - const hasWordSyncedLyrics = (_s = track === null || track === void 0 ? void 0 : track.track) === null || _s === void 0 ? void 0 : _s.has_richsync; - if (!hasLyrics && !hasLineSyncedLyrics && !hasWordSyncedLyrics) - return null; - this.debugLog("Musixmatch commontrack_id", commonTrackId); - this.debugLog("Musixmatch track_id", trackId); - return { - commonTrackId, - trackId, - hasLyrics, - hasLineSyncedLyrics, - hasWordSyncedLyrics, - }; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Search]", e); - return null; - } - }); - } - _fetchPlainLyricsMusixmatch(tokenData, commonTrackId) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e, _f, _g, _h; - if (!tokenData || !commonTrackId) - return null; - const searchParams = new URLSearchParams({ - app_id: "web-desktop-app-v1.0", - usertoken: tokenData.usertoken, - commontrack_id: commonTrackId, - }); - const url = `https://apic-desktop.musixmatch.com/ws/1.1/track.lyrics.get?${searchParams}`; - try { - this.debugLog("Musixmatch lyrics fetch URL:", url); - const res = yield fetch(url, { - headers: { - cookie: tokenData.cookies, - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Musixmatch - Lyrics]`); - return null; - } - const data = yield res.json(); - if (((_b = (_a = data === null || data === void 0 ? void 0 : data.message) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.status_code) === 401 && - ((_d = (_c = data === null || data === void 0 ? void 0 : data.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.hint) === "captcha") { - this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Lyrics]"); - return null; - } - this.debugLog("Musixmatch track data:", (_e = data === null || data === void 0 ? void 0 : data.message) === null || _e === void 0 ? void 0 : _e.body); - const lyrics = (_h = (_g = (_f = data === null || data === void 0 ? void 0 : data.message) === null || _f === void 0 ? void 0 : _f.body) === null || _g === void 0 ? void 0 : _g.lyrics) === null || _h === void 0 ? void 0 : _h.lyrics_body; - if (!lyrics) { - this.infoLog("Missing Lyrics [Musixmatch - Lyrics]"); - return null; - } - this.infoLog("Successfully fetched and cached the plain lyrics [Musixmatch]"); - return lyrics; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Lyrics]", e); - return null; - } - }); - } - _fetchLineSyncedLyricsMusixmatch(tokenData, commonTrackId) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e, _f, _g, _h; - if (!tokenData || !commonTrackId) - return null; - const searchParams = new URLSearchParams({ - app_id: "web-desktop-app-v1.0", - usertoken: tokenData.usertoken, - commontrack_id: commonTrackId, - }); - const url = `https://apic-desktop.musixmatch.com/ws/1.1/track.subtitle.get?${searchParams}`; - try { - this.debugLog("Musixmatch synced lyrics fetch URL:", url); - const res = yield fetch(url, { - headers: { - cookie: tokenData.cookies, - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Musixmatch - Synced Lyrics]`); - return null; - } - const data = yield res.json(); - if (((_b = (_a = data === null || data === void 0 ? void 0 : data.message) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.status_code) === 401 && - ((_d = (_c = data === null || data === void 0 ? void 0 : data.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.hint) === "captcha") { - this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Synced Lyrics]"); - return null; - } - this.debugLog("Musixmatch track data:", (_e = data === null || data === void 0 ? void 0 : data.message) === null || _e === void 0 ? void 0 : _e.body); - const lyrics = (_h = (_g = (_f = data === null || data === void 0 ? void 0 : data.message) === null || _f === void 0 ? void 0 : _f.body) === null || _g === void 0 ? void 0 : _g.subtitle) === null || _h === void 0 ? void 0 : _h.subtitle_body; - if (!lyrics) { - this.infoLog("Missing Lyrics [Musixmatch - Synced Lyrics]"); - return null; - } - this.infoLog("Successfully fetched and cached the synced lyrics [Musixmatch]"); - return lyrics; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Synced Lyrics]", e); - return null; - } - }); - } - _fetchWordSyncedLyricsMusixmatch(tokenData, trackId) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e, _f, _g, _h; - if (!tokenData || !trackId) - return null; - const searchParams = new URLSearchParams({ - app_id: "web-desktop-app-v1.0", - usertoken: tokenData.usertoken, - track_id: trackId, - }); - const url = `https://apic-desktop.musixmatch.com/ws/1.1/track.richsync.get?${searchParams}`; - try { - this.debugLog("Musixmatch lyrics fetch URL:", url); - const res = yield fetch(url, { - headers: { - cookie: tokenData.cookies, - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Musixmatch - Word Synced Lyrics]`); - return null; - } - const data = yield res.json(); - if (((_b = (_a = data === null || data === void 0 ? void 0 : data.message) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.status_code) === 401 && - ((_d = (_c = data === null || data === void 0 ? void 0 : data.message) === null || _c === void 0 ? void 0 : _c.header) === null || _d === void 0 ? void 0 : _d.hint) === "captcha") { - this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Word Synced Lyrics]"); - return null; - } - this.debugLog("Musixmatch track data:", (_e = data === null || data === void 0 ? void 0 : data.message) === null || _e === void 0 ? void 0 : _e.body); - let lyrics = (_h = (_g = (_f = data === null || data === void 0 ? void 0 : data.message) === null || _f === void 0 ? void 0 : _f.body) === null || _g === void 0 ? void 0 : _g.richsync) === null || _h === void 0 ? void 0 : _h.richsync_body; - if (!lyrics || lyrics.length <= 0) { - this.infoLog("Missing Lyrics [Musixmatch - Word Synced Lyrics]"); - return null; - } - lyrics = JSON.parse(lyrics); - const parsedLyrics = lyrics.map((line) => { - const start = line.ts; - const end = line.te; - const lyric = line.x; - const syncedLyric = line.l.map((word) => ({ - character: word.c, - time: word.o, - })); - return { - end, - lyric, - start, - syncedLyric, - }; - }); - this.infoLog("Successfully fetched and cached the synced lyrics [Musixmatch]"); - return parsedLyrics; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Word Synced Lyrics]", e); - return null; - } - }); - } - _fetchLyricsMusixmatch(metadata, tokenData, trackId, commonTrackId, hasLyrics, hasLineSyncedLyrics, hasWordSyncedLyrics, lyricsType) { - return __awaiter(this, void 0, void 0, function* () { - if (!metadata || - (!commonTrackId && !trackId) || - !tokenData || - (!hasLyrics && !hasLineSyncedLyrics && !hasWordSyncedLyrics)) - return null; - const lyricsData = { - plain: null, - lineSynced: null, - wordSynced: null, - }; - if (hasLyrics && commonTrackId && lyricsType.includes("plain")) - lyricsData.plain = yield this._fetchPlainLyricsMusixmatch(tokenData, commonTrackId); - if (hasLineSyncedLyrics && - commonTrackId && - lyricsType.includes("lineSynced")) - lyricsData.lineSynced = yield this._fetchLineSyncedLyricsMusixmatch(tokenData, commonTrackId); - if (hasWordSyncedLyrics && - commonTrackId && - lyricsType.includes("wordSynced")) - lyricsData.wordSynced = yield this._fetchWordSyncedLyricsMusixmatch(tokenData, trackId); - return lyricsData; - }); - } - _searchLyricsNetease(metadata) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b, _c, _d, _e; - const searchParams = new URLSearchParams({ - limit: 10, - type: 1, - keywords: `${metadata.track} ${metadata.artist}`, - }); - const url = `https://music.xianqiao.wang/neteaseapiv2/search?${searchParams}`; - try { - this.debugLog("Netease search fetch URL:", url); - const res = yield fetch(url, { - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0", - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Netease - Search]`); - return null; - } - const data = yield res.json(); - if (!((_a = data === null || data === void 0 ? void 0 : data.result) === null || _a === void 0 ? void 0 : _a.songs) || ((_c = (_b = data === null || data === void 0 ? void 0 : data.result) === null || _b === void 0 ? void 0 : _b.songs) === null || _c === void 0 ? void 0 : _c.length) <= 0) { - this.infoLog("No songs were found [Netease - Search]"); - return null; - } - const track = (_e = (_d = data === null || data === void 0 ? void 0 : data.result) === null || _d === void 0 ? void 0 : _d.songs) === null || _e === void 0 ? void 0 : _e.find((listItem) => { - var _a, _b; - return ((_a = listItem.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = metadata.track) === null || _b === void 0 ? void 0 : _b.toLowerCase()) && - (listItem.artists.some((artist) => { - var _a, _b, _c; - return (_b = (_a = artist.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes((_c = metadata.artist) === null || _c === void 0 ? void 0 : _c.toLowerCase()); - }) || - listItem.artists.some((artist) => { - var _a, _b, _c, _d, _e; - return (_c = (_b = (_a = artist.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.replace(/-/g, " ")) === null || _c === void 0 ? void 0 : _c.includes((_e = (_d = metadata.artist) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === null || _e === void 0 ? void 0 : _e.replace(/-/g, " ")); - })); - }); - this.debugLog("Netease search filtered track:", track); - if (!track) { - this.infoLog("No songs were found with the current name and artist [Netease - Search]"); - return null; - } - const trackId = track.id; - this.debugLog("Neteasw track ID", trackId); - return trackId; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Netease - Search]", e); - return null; - } - }); - } - _fetchLyricsNetease(metadata, trackId) { - return __awaiter(this, void 0, void 0, function* () { - var _a; - if (!metadata || !trackId) - return null; - const searchParams = new URLSearchParams({ - id: trackId, - }); - const url = `https://music.xianqiao.wang/neteaseapiv2/lyric?${searchParams}`; - try { - this.debugLog("Netease lyrics fetch URL:", url); - const res = yield fetch(url, { - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0", - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [Netease - Lyrics]`); - return null; - } - const data = yield res.json(); - this.debugLog("Netease track data:", data); - let lyrics = (_a = data === null || data === void 0 ? void 0 : data.lrc) === null || _a === void 0 ? void 0 : _a.lyric; - if (!lyrics) { - this.infoLog("Missing Lyrics [Netease - Lyrics]"); - return null; - } - lyrics = this._parseNeteaseLyrics(lyrics); - this.infoLog("Successfully fetched and cached the synced lyrics [Netease]"); - return lyrics; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [Netease - Lyrics]", e); - return null; - } - }); - } - _parseNeteaseLyrics(slyrics) { - const lines = slyrics.split(/\r?\n/).map((line) => line.trim()); - const lyrics = []; - const creditInfo = [ - "\\s?作?\\s*词|\\s?作?\\s*曲|\\s?编\\s*曲?|\\s?监\\s*制?", - ".*编写|.*和音|.*和声|.*合声|.*提琴|.*录|.*工程|.*工作室|.*设计|.*剪辑|.*制作|.*发行|.*出品|.*后期|.*混音|.*缩混", - "原唱|翻唱|题字|文案|海报|古筝|二胡|钢琴|吉他|贝斯|笛子|鼓|弦乐| 人声 ", - "lrc|publish|vocal|guitar|program|produce|write|mix", - ]; - const creditInfoRegExp = new RegExp(`^(${creditInfo.join("|")}).*(:|:)`, "i"); - for (let i = 0; i < lines.length; i++) { - const line = lines[i]; - const matchResult = line.match(/(\[.*?\])|([^\[\]]+)/g); - if (!matchResult || matchResult.length === 1) { - continue; - } - let textIndex = -1; - for (let j = 0; j < matchResult.length; j++) { - if (!matchResult[j].endsWith("]")) { - textIndex = j; - break; - } - } - let text = ""; - if (textIndex > -1) { - text = matchResult.splice(textIndex, 1)[0]; - text = text.charAt(0).toUpperCase() + normalize(text.slice(1)); - } - const time = matchResult[0]; - if (!creditInfoRegExp.test(text)) { - lyrics.push(`${time} ${text || ""}`); - } - } - return lyrics.join("\n"); - } - fetchLyricsLrclib(metadata, lyricsType) { - return __awaiter(this, void 0, void 0, function* () { - var _a, _b; - if (!metadata) - return null; - if (!lyricsType.includes("plain") && !lyricsType.includes("lineSynced")) - return null; - this.infoLog(`Fetching the lyrics for "${metadata.track}" from "${metadata.album}" from "${metadata.artist}" (${this._trackId}) [LRCLIB]`); - const searchParams = new URLSearchParams({ - track_name: metadata.track, - artist_name: metadata.artist, - album_name: metadata.album, - q: metadata.track, - }); - const url = `https://lrclib.net/api/search?${searchParams}`; - try { - const res = yield fetch(url, { - headers: { - "Lrclib-Client": "SyncLyrics (https://github.com/Stef-00012/SyncLyrics)", - "User-Agent": "SyncLyrics (https://github.com/Stef-00012/SyncLyrics)", - }, - }); - if (!res.ok) { - this.warnLog(`Lyrics fetch request failed with status ${res.status} (${res.statusText}) [LRCLIB]`); - return null; - } - const data = yield res.json(); - this.debugLog("lrclib.net results:", data); - const match = data.find((d) => { - var _a, _b, _c, _d; - return ((_a = d.artistName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes((_b = metadata.artist) === null || _b === void 0 ? void 0 : _b.toLowerCase())) && - ((_c = d.trackName) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === ((_d = metadata.track) === null || _d === void 0 ? void 0 : _d.toLowerCase()); - }); - this.debugLog("lrclib filtered track:", match); - if (!match || - ((!match.syncedLyrics || ((_a = match.syncedLyrics) === null || _a === void 0 ? void 0 : _a.length) <= 0) && - (!match.plainLyrics || ((_b = match.plainLyrics) === null || _b === void 0 ? void 0 : _b.length) <= 0))) { - this.infoLog("The fetched song does not have lyrics [LRCLIB]"); - return null; - } - this.infoLog("Successfully fetched and cached the lyrics [LRCLIB]"); - return { - source: "lrclib.net", - plain: match === null || match === void 0 ? void 0 : match.plainLyrics, - lineSynced: match === null || match === void 0 ? void 0 : match.syncedLyrics, - wordSynced: null, - }; - } - catch (e) { - this.errorLog("Something went wrong while fetching the lyrics [LRCLIB]", e); - return null; - } - }); - } - fetchLyricsMusixmatch(metadata, lyricsType) { - return __awaiter(this, void 0, void 0, function* () { - if (!metadata) - return null; - const tokenData = yield this.getMusixmatchUsertoken(); - this.debugLog("Musixmatch token data:", tokenData); - if (!tokenData) - return null; - this.infoLog(`Fetching the lyrics for "${metadata.track}" from "${metadata.album}" from "${metadata.artist}" (${this._trackId}) [Musixmatch]`); - const trackData = yield this._searchLyricsMusixmatch(metadata, tokenData); - if (!trackData || - (!trackData.hasLyrics && - !trackData.hasLineSyncedLyrics && - !trackData.hasWordSyncedLyrics) || - (!trackData.commonTrackId && !trackData.trackId)) { - this.infoLog("Missing both commontrack_id and track_id [Musixmatch - Search]"); - return null; - } - const lyrics = yield this._fetchLyricsMusixmatch(metadata, tokenData, trackData.trackId, trackData.commonTrackId, trackData.hasLyrics, trackData.hasLineSyncedLyrics, trackData.hasWordSyncedLyrics, lyricsType); - return Object.assign({ source: "Musixmatch" }, lyrics); - }); - } - fetchLyricsNetease(metadata, lyricsType) { - return __awaiter(this, void 0, void 0, function* () { - if (!metadata) - return null; - if (!lyricsType.includes("lineSynced")) - return null; - const trackId = yield this._searchLyricsNetease(metadata); - if (!trackId) { - this.infoLog("Missing track ID [Netease - Search]"); - return null; - } - const lyrics = yield this._fetchLyricsNetease(metadata, trackId); - return { - source: "Netease", - lineSynced: lyrics, - plain: null, - wordSynced: null, - }; - }); - } - _getLyrics(metadata, lyricsType) { - return __awaiter(this, void 0, void 0, function* () { - const sourcesTypes = { - musixmatch: ["plain", "line", "word"], - lrclib: ["plain", "line"], - netease: ["line"], - }; - const avaibleSources = { - musixmatch: this.fetchLyricsMusixmatch, - lrclib: this.fetchLyricsLrclib, - netease: this.fetchLyricsNetease, - }; - let userSources = this.sources || [ - "musixmatch", - "lrclib", - "netease", - ]; - const lyricsData = { - plain: { - source: null, - lyrics: null, - }, - lineSynced: { - source: null, - lyrics: null, - }, - wordSynced: { - source: null, - lyrics: null, - }, - }; - if (this._fetching) - return lyricsData; - this._fetching = true; - if (userSources.every((source) => !Object.keys(avaibleSources).includes(source))) - userSources = ["musixmatch", "lrclib", "netease"]; - sourcesLoop: for (const source of userSources) { - this.infoLog(`Trying to fetch the lyrics from the source "${source}"`); - if (source === "musixmatch" && - (!this.saveMusixmatchToken || !this.getMusixmatchToken)) { - this.infoLog("Musixmatch token functions are not avaible, skipping..."); - continue; - } - let sourceSkip = 0; - const avaibleTypes = sourcesTypes[source]; - for (const type of avaibleTypes) { - if (type === "plain" && - (lyricsData.plain.lyrics || !lyricsType.includes("plain"))) - sourceSkip++; - if (type === "line" && - (lyricsData.lineSynced.lyrics || !lyricsType.includes("lineSynced"))) - sourceSkip++; - if (type === "word" && - (lyricsData.wordSynced.lyrics || !lyricsType.includes("wordSynced"))) - sourceSkip++; - if (sourceSkip >= avaibleTypes.length) - continue sourcesLoop; - } - if (!Object.keys(avaibleSources).includes(source)) { - this.infoLog(`The source "${source}" doesn't exist, skipping...`); - continue; - } - const lyrics = yield avaibleSources[source](metadata, lyricsType); - if (!lyrics) - continue; - if ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.plain) && !lyricsData.plain.lyrics) { - lyricsData.plain.lyrics = lyrics.plain; - lyricsData.plain.source = lyrics.source; - } - if ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.lineSynced) && !lyricsData.lineSynced.lyrics) { - lyricsData.lineSynced.lyrics = lyrics.lineSynced; - lyricsData.lineSynced.source = lyrics.source; - } - if ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.wordSynced) && !lyricsData.wordSynced.lyrics) { - lyricsData.wordSynced.lyrics = lyrics.wordSynced; - lyricsData.wordSynced.source = lyrics.source; - } - } - this._fetching = false; - return lyricsData; - }); - } - getLyrics(metadata, skipCache) { - return __awaiter(this, void 0, void 0, function* () { - if (!(metadata === null || metadata === void 0 ? void 0 : metadata.track) && - !(metadata === null || metadata === void 0 ? void 0 : metadata.artist) && - !(metadata === null || metadata === void 0 ? void 0 : metadata.album) && - !(metadata === null || metadata === void 0 ? void 0 : metadata.trackId)) - throw new Error("SyncLyrics (getlyrics): At least one of track, artist, album or trackId must be present"); - this._trackId = - metadata.trackId || - btoa(unescape(encodeURIComponent(`${metadata.track || ""}----${metadata.artist || ""}----${metadata.album || ""}`))); - let lyricsFetchType = Array.isArray(metadata.lyricsType) - ? metadata.lyricsType - : ["plain", "lineSynced", "wordSynced"]; - if (lyricsFetchType.length <= 0) - lyricsFetchType = ["plain", "lineSynced", "wordSynced"]; - const cachedLyrics = skipCache ? null : this.cache.get(this._trackId); - if (metadata.trackId && !cachedLyrics) { - const decodedId = atob(metadata.trackId); - const splitId = decodedId.split("----"); - const track = splitId.shift() || ""; - const artist = splitId.shift() || ""; - const album = splitId.shift() || ""; - return yield this.getLyrics({ - track, - artist, - album, - lyricsType: lyricsFetchType, - }, skipCache); - } - const lyrics = cachedLyrics || (yield this._getLyrics(metadata, lyricsFetchType)); - if (!skipCache && - (!this.cache.has(this._trackId) || - ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.plain.lyrics) && !(cachedLyrics === null || cachedLyrics === void 0 ? void 0 : cachedLyrics.plain.lyrics)) || - ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.lineSynced.lyrics) && !(cachedLyrics === null || cachedLyrics === void 0 ? void 0 : cachedLyrics.lineSynced.lyrics)) || - ((lyrics === null || lyrics === void 0 ? void 0 : lyrics.wordSynced.lyrics) && !(cachedLyrics === null || cachedLyrics === void 0 ? void 0 : cachedLyrics.wordSynced.lyrics)))) - this.cache.set(this._trackId, lyrics || { - plain: { - lyrics: null, - source: null, - }, - lineSynced: { - lyrics: null, - source: null, - }, - wordSynced: { - lyrics: null, - source: null, - }, - }); - if (!lyrics) - return { - trackId: this._trackId, - lyrics: { - plain: { - lyrics: null, - source: null, - }, - lineSynced: { - lyrics: null, - source: null, - parse: this.parseLyrics, - }, - wordSynced: { - lyrics: null, - source: null, - }, - }, - track: metadata.track, - artist: metadata.artist, - album: metadata.album, - cached: false, - }; - this.lyrics = lyrics.lineSynced.lyrics; - return { - trackId: this._trackId, - lyrics: Object.assign(Object.assign({}, lyrics), { lineSynced: Object.assign(Object.assign({}, lyrics.lineSynced), { parse: this.parseLyrics }) }), - track: metadata.track, - artist: metadata.artist, - album: metadata.album, - cached: !!cachedLyrics, - }; - }); - } - parseLyrics(lyrics = this.lyrics) { - const lyricsSplit = lyrics === null || lyrics === void 0 ? void 0 : lyrics.split("\n"); - if (!lyricsSplit) - return null; - const formattedLyrics = []; - let lastTime; - for (const index in lyricsSplit) { - const lyricText = lyricsSplit[index].split(" "); - const time = lyricText.shift().replace(/[\[\]]/g, ""); - const text = lyricText.join(" "); - const minutes = time.split(":")[0]; - const seconds = time.split(":")[1]; - const totalSeconds = Number.parseFloat(minutes) * 60 + Number.parseFloat(seconds); - const instrumentalLyricIndicator = this.instrumentalLyricsIndicator || " "; - if (index === "0" && totalSeconds > 3 && instrumentalLyricIndicator) { - formattedLyrics.push({ - time: 0, - text: instrumentalLyricIndicator, - }); - } - if (text.length > 0) { - lastTime = time; - formattedLyrics.push({ - time: totalSeconds, - text: text, - }); - continue; - } - if (instrumentalLyricIndicator && (!lastTime || lastTime - time > 3)) { - lastTime = time; - formattedLyrics.push({ - time: totalSeconds, - text: instrumentalLyricIndicator, - }); - } - } - return formattedLyrics; - } - getTrackId(metadata) { - if (metadata.trackId) - return metadata.trackId; - return btoa(unescape(encodeURIComponent(`${metadata.track || ""}----${metadata.artist || ""}----${metadata.album || ""}`))); - } - setLogLevel(newLogLevel) { - if (!newLogLevel) { - this.logLevel = "none"; - return this; - } - if (!Object.keys(exports.logLevels).includes(newLogLevel)) - throw new Error(`SyncLyrics: logLevel must be one of "${Object.keys(exports.logLevels).join('" | "')}"`); - this.logLevel = newLogLevel; - return this; - } - setInstrumentalLyricsIndicator(newInstrumentalLyricsIndicator) { - if (!newInstrumentalLyricsIndicator) { - this.instrumentalLyricsIndicator = ""; - return this; - } - if (typeof newInstrumentalLyricsIndicator !== "string") - throw new Error("SyncLyrics: instrumentalLyricsIndicator must be a string"); - this.instrumentalLyricsIndicator = newInstrumentalLyricsIndicator; - return this; - } - setSources(newSources) { - if (!newSources) { - this.sources = ["musixmatch", "lrclib", "netease"]; - return this; - } - if (!Array.isArray(newSources) || newSources.length <= 0) - throw new Error('SyncLyrics: sources must be an array with atleast one of "musixmatch" | "lrclib" | "netease"'); - this.sources = newSources; - return this; - } - setCache(newCache) { - if (!newCache) { - this.cache = new Map(); - return this; - } - if (typeof newCache.get !== "function" || - typeof newCache.set !== "function" || - typeof newCache.has !== "function") - throw new Error("SyncLyrics: cache must have .get, .set and .has methods"); - this.cache = newCache; - return this; - } - setSaveMusixmatchToken(saveMusixmatchToken) { - if (typeof saveMusixmatchToken !== "function") - throw new Error("SyncLyrics: saveMusixmatchToken must be a function"); - this.saveMusixmatchToken = saveMusixmatchToken; - return this; - } - setGetMusixmatchToken(getMusixmatchToken) { - if (typeof getMusixmatchToken !== "function") - throw new Error("SyncLyrics: getMusixmatchToken must be a function"); - this.getMusixmatchToken = getMusixmatchToken; - return this; - } - warnLog(...args) { - if ((exports.logLevels[this.logLevel] || 0) < exports.logLevels.warn) - return; - console.warn("\x1b[33;1mWARNING:\x1b[0m", ...args); - } - debugLog(...args) { - if ((exports.logLevels[this.logLevel] || 0) < exports.logLevels.debug) - return; - console.debug("\x1b[35;1mDEBUG:\x1b[0m", ...args); - } - errorLog(...args) { - if ((exports.logLevels[this.logLevel] || 0) < exports.logLevels.debug) - return; - console.debug("\x1b[35;1mDEBUG:\x1b[0m", ...args); - } - infoLog(...args) { - if ((exports.logLevels[this.logLevel] || 0) < exports.logLevels.info) - return; - console.info("\x1b[34;1mINFO:\x1b[0m", ...args); - } -} -exports.SyncLyrics = SyncLyrics; -function normalize(string) { - return string - .replace(/(/g, "(") - .replace(/)/g, ")") - .replace(/【/g, "[") - .replace(/】/g, "]") - .replace(/。/g, ". ") - .replace(/;/g, "; ") - .replace(/:/g, ": ") - .replace(/?/g, "? ") - .replace(/!/g, "! ") - .replace(/、|,/g, ", ") - .replace(/‘|’|′|'/g, "'") - .replace(/“|”/g, '"') - .replace(/〜/g, "~") - .replace(/·|・/g, "•") - .replace(/\s+/g, " ") - .trim(); -} diff --git a/dist/index.min.js b/dist/index.min.js deleted file mode 100644 index c27bf11..0000000 --- a/dist/index.min.js +++ /dev/null @@ -1,50 +0,0 @@ -var __awaiter=this&&this.__awaiter||function(a,f,d,b){function c(e){return e instanceof d?e:new d(function(g){g(e)})}return new (d||=Promise)(function(e,g){function h(p){try{n(b.next(p))}catch(m){g(m)}}function l(p){try{n(b["throw"](p))}catch(m){g(m)}}function n(p){p.done?e(p.value):c(p.value).then(h,l)}n((b=b.apply(a,f||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0});exports.SyncLyrics=exports.logLevels=exports.lyricType=exports.sources=void 0;exports.normalize=normalize; -const util_1=require("util"),sleep=(0,util_1.promisify)(setTimeout);exports.sources=["musixmatch","lrclib","netease"];exports.lyricType=["plain","lineSynced","wordSynced"];exports.logLevels={debug:4,error:3,warn:2,info:1,none:0}; -class SyncLyrics{constructor(a){if("string"===typeof(null===a||void 0===a?void 0:a.logLevel)&&!Object.keys(exports.logLevels).includes(a.logLevel))throw Error(`SyncLyrics: logLevel must be one of "${Object.keys(exports.logLevels).join('" | "')}"`);if((null===a||void 0===a?0:a.instrumentalLyricsIndicator)&&"string"!==typeof a.instrumentalLyricsIndicator)throw Error("SyncLyrics: instrumentalLyricsIndicator must be a string");if((null===a||void 0===a?0:a.sources)&&(!Array.isArray(a.sources)||0>=a.sources.length))throw Error('SyncLyrics: sources must be an array with atleast one of "musixmatch" | "lrclib" | "netease"'); -if((null===a||void 0===a?0:a.cache)&&("function"!==typeof a.cache.get||"function"!==typeof a.cache.set||"function"!==typeof a.cache.has))throw Error("SyncLyrics: cache must have .get, .set and .has methods");if((null===a||void 0===a?0:a.saveMusixmatchToken)&&"function"!==typeof a.saveMusixmatchToken)throw Error("SyncLyrics: saveMusixmatchToken must be a function");if((null===a||void 0===a?0:a.getMusixmatchToken)&&"function"!==typeof a.getMusixmatchToken)throw Error("SyncLyrics: getMusixmatchToken must be a function"); -this.logLevel=(null===a||void 0===a?void 0:a.logLevel)||"none";this.instrumentalLyricsIndicator=(null===a||void 0===a?void 0:a.instrumentalLyricsIndicator)||"\uf001";this.sources=(null===a||void 0===a?void 0:a.sources)||["musixmatch","lrclib","netease"];this.cache=(null===a||void 0===a?void 0:a.cache)||new Map;this.saveMusixmatchToken=null===a||void 0===a?void 0:a.saveMusixmatchToken;this.getMusixmatchToken=null===a||void 0===a?void 0:a.getMusixmatchToken;this._trackId=this.lyrics=null;this._fetching= -!1;this._fetchLineSyncedLyricsMusixmatch=this._fetchLineSyncedLyricsMusixmatch.bind(this);this._fetchWordSyncedLyricsMusixmatch=this._fetchWordSyncedLyricsMusixmatch.bind(this);this._fetchPlainLyricsMusixmatch=this._fetchPlainLyricsMusixmatch.bind(this);this._searchLyricsMusixmatch=this._searchLyricsMusixmatch.bind(this);this._fetchLyricsMusixmatch=this._fetchLyricsMusixmatch.bind(this);this.getMusixmatchUsertoken=this.getMusixmatchUsertoken.bind(this);this.fetchLyricsMusixmatch=this.fetchLyricsMusixmatch.bind(this); -this._searchLyricsNetease=this._searchLyricsNetease.bind(this);this._parseNeteaseLyrics=this._parseNeteaseLyrics.bind(this);this._fetchLyricsNetease=this._fetchLyricsNetease.bind(this);this.fetchLyricsNetease=this.fetchLyricsNetease.bind(this);this.fetchLyricsLrclib=this.fetchLyricsLrclib.bind(this);this.parseLyrics=this.parseLyrics.bind(this);this._getLyrics=this._getLyrics.bind(this);this.getTrackId=this.getTrackId.bind(this);this.getLyrics=this.getLyrics.bind(this);this.debugLog=this.debugLog.bind(this); -this.errorLog=this.errorLog.bind(this);this.infoLog=this.infoLog.bind(this);this.warnLog=this.warnLog.bind(this)}getMusixmatchUsertoken(a){return __awaiter(this,void 0,void 0,function*(){var f,d,b,c,e,g;this.infoLog("Getting Musixmatch token...");if(!this.saveMusixmatchToken||!this.getMusixmatchToken)return this.infoLog("Musixmatch token functions are not avaible, skipping..."),null;const h=yield this.getMusixmatchToken();if(h)return h;this.infoLog("Fetching the token from the API...");try{const l= -yield fetch("https://apic-desktop.musixmatch.com/ws/1.1/token.get?user_language=en&app_id=web-desktop-app-v1.0",{redirect:"manual",headers:{cookie:a}});if(301===l.status){this.debugLog("Successfully received the 'set-cookie' redirect response");const k=l.headers.getSetCookie().map(q=>q.split(";").shift()).filter(q=>"unknown"!==q.split("=").pop()).join("; ");this.debugLog("Re-fetching with the cookies...");return yield this.getMusixmatchUsertoken(k)}if(!l.ok)return this.warnLog(`The usertoken API request failed with the status ${l.status} (${l.statusText})`), -null;const n=yield l.json();if(401===(null===(d=null===(f=null===n||void 0===n?void 0:n.message)||void 0===f?void 0:f.header)||void 0===d?void 0:d.status_code)&&"captcha"===(null===(c=null===(b=null===n||void 0===n?void 0:n.message)||void 0===b?void 0:b.header)||void 0===c?void 0:c.hint))return this.warnLog("Musixmatch usertoken endpoint is being ratelimited, retrying in 10 seconds..."),yield sleep(1E4),this.infoLog("Retrying to fetch the Musixmatch usertken..."),yield this.getMusixmatchUsertoken(a); -const p=null===(g=null===(e=null===n||void 0===n?void 0:n.message)||void 0===e?void 0:e.body)||void 0===g?void 0:g.user_token;if(!p)return this.infoLog("The API response did not include the usertoken"),null;const m={cookies:a,usertoken:p,expiresAt:(new Date(Date.now()+6E5)).getTime()};yield this.saveMusixmatchToken(m);this.infoLog("Successfully fetched the usertoken");return m}catch(l){}})}_searchLyricsMusixmatch(a,f){return __awaiter(this,void 0,void 0,function*(){var d,b,c,e,g,h,l,n,p,m,k,q,y,r, -v,w,z;if(!a||!f)return null;var x=Number.parseFloat(a.length)/1E3;x=`https://apic-desktop.musixmatch.com/ws/1.1/track.search?${new URLSearchParams({app_id:"web-desktop-app-v1.0",usertoken:f.usertoken,q_track:a.track||"",q_artist:a.artist||"",q_album:a.album||"",page_size:20,page:1,q_duration:x||"",s_track_rating:"asc"})}`;try{this.debugLog("Musixmatch search fetch URL:",x);const A=yield fetch(x,{headers:{cookie:f.cookies}});if(!A.ok)return this.warnLog(`Lyrics fetch request failed with status ${A.status} (${A.statusText}) [Musixmatch - Search]`), -null;const u=yield A.json();if(401===(null===(b=null===(d=null===u||void 0===u?void 0:u.message)||void 0===d?void 0:d.header)||void 0===b?void 0:b.status_code)&&"captcha"===(null===(e=null===(c=null===u||void 0===u?void 0:u.message)||void 0===c?void 0:c.header)||void 0===e?void 0:e.hint))return this.warnLog("The usertoken has been temporary blocked for too many requests (captcha) [Musixmatch - Search]"),null;this.debugLog("Musixmatch search results:",null===(h=null===(g=null===u||void 0===u?void 0: -u.message)||void 0===g?void 0:g.body)||void 0===h?void 0:h.track_list);if(0>=(null===(p=null===(n=null===(l=null===u||void 0===u?void 0:u.message)||void 0===l?void 0:l.body)||void 0===n?void 0:n.track_list)||void 0===p?void 0:p.length))return this.infoLog("No songs were found [Musixmatch - Search]"),null;const t=null===(q=null===(k=null===(m=null===u||void 0===u?void 0:u.message)||void 0===m?void 0:m.body)||void 0===k?void 0:k.track_list)||void 0===q?void 0:q.find(F=>{var B,C,D,E;return(null===(B= -F.track.track_name)||void 0===B?void 0:B.toLowerCase())===(null===(C=a.track)||void 0===C?void 0:C.toLowerCase())&&(null===(D=F.track.artist_name)||void 0===D?void 0:D.toLowerCase().includes(null===(E=a.artist)||void 0===E?void 0:E.toLowerCase()))});this.debugLog("Musixmatch search filtered track:",t);if(!t)return this.infoLog("No songs were found with the current name and artist [Musixmatch - Search]"),null;this.debugLog(t);const G=null===(y=null===t||void 0===t?void 0:t.track)||void 0===y?void 0: -y.commontrack_id,H=null===(r=null===t||void 0===t?void 0:t.track)||void 0===r?void 0:r.track_id,I=null===(v=null===t||void 0===t?void 0:t.track)||void 0===v?void 0:v.has_lyrics,J=null===(w=null===t||void 0===t?void 0:t.track)||void 0===w?void 0:w.has_subtitles,K=null===(z=null===t||void 0===t?void 0:t.track)||void 0===z?void 0:z.has_richsync;if(!I&&!J&&!K)return null;this.debugLog("Musixmatch commontrack_id",G);this.debugLog("Musixmatch track_id",H);return{commonTrackId:G,trackId:H,hasLyrics:I,hasLineSyncedLyrics:J, -hasWordSyncedLyrics:K}}catch(A){return this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Search]",A),null}})}_fetchPlainLyricsMusixmatch(a,f){return __awaiter(this,void 0,void 0,function*(){var d,b,c,e,g,h,l,n;if(!a||!f)return null;const p=`https://apic-desktop.musixmatch.com/ws/1.1/track.lyrics.get?${new URLSearchParams({app_id:"web-desktop-app-v1.0",usertoken:a.usertoken,commontrack_id:f})}`;try{this.debugLog("Musixmatch lyrics fetch URL:",p);const m=yield fetch(p,{headers:{cookie:a.cookies}}); -if(!m.ok)return this.warnLog(`Lyrics fetch request failed with status ${m.status} (${m.statusText}) [Musixmatch - Lyrics]`),null;const k=yield m.json();if(401===(null===(b=null===(d=null===k||void 0===k?void 0:k.message)||void 0===d?void 0:d.header)||void 0===b?void 0:b.status_code)&&"captcha"===(null===(e=null===(c=null===k||void 0===k?void 0:k.message)||void 0===c?void 0:c.header)||void 0===e?void 0:e.hint))return this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Lyrics]"), -null;this.debugLog("Musixmatch track data:",null===(g=null===k||void 0===k?void 0:k.message)||void 0===g?void 0:g.body);const q=null===(n=null===(l=null===(h=null===k||void 0===k?void 0:k.message)||void 0===h?void 0:h.body)||void 0===l?void 0:l.lyrics)||void 0===n?void 0:n.lyrics_body;if(!q)return this.infoLog("Missing Lyrics [Musixmatch - Lyrics]"),null;this.infoLog("Successfully fetched and cached the plain lyrics [Musixmatch]");return q}catch(m){return this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Lyrics]", -m),null}})}_fetchLineSyncedLyricsMusixmatch(a,f){return __awaiter(this,void 0,void 0,function*(){var d,b,c,e,g,h,l,n;if(!a||!f)return null;const p=`https://apic-desktop.musixmatch.com/ws/1.1/track.subtitle.get?${new URLSearchParams({app_id:"web-desktop-app-v1.0",usertoken:a.usertoken,commontrack_id:f})}`;try{this.debugLog("Musixmatch synced lyrics fetch URL:",p);const m=yield fetch(p,{headers:{cookie:a.cookies}});if(!m.ok)return this.warnLog(`Lyrics fetch request failed with status ${m.status} (${m.statusText}) [Musixmatch - Synced Lyrics]`), -null;const k=yield m.json();if(401===(null===(b=null===(d=null===k||void 0===k?void 0:k.message)||void 0===d?void 0:d.header)||void 0===b?void 0:b.status_code)&&"captcha"===(null===(e=null===(c=null===k||void 0===k?void 0:k.message)||void 0===c?void 0:c.header)||void 0===e?void 0:e.hint))return this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Synced Lyrics]"),null;this.debugLog("Musixmatch track data:",null===(g=null===k||void 0===k?void 0:k.message)|| -void 0===g?void 0:g.body);const q=null===(n=null===(l=null===(h=null===k||void 0===k?void 0:k.message)||void 0===h?void 0:h.body)||void 0===l?void 0:l.subtitle)||void 0===n?void 0:n.subtitle_body;if(!q)return this.infoLog("Missing Lyrics [Musixmatch - Synced Lyrics]"),null;this.infoLog("Successfully fetched and cached the synced lyrics [Musixmatch]");return q}catch(m){return this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Synced Lyrics]",m),null}})}_fetchWordSyncedLyricsMusixmatch(a, -f){return __awaiter(this,void 0,void 0,function*(){var d,b,c,e,g,h,l,n;if(!a||!f)return null;const p=`https://apic-desktop.musixmatch.com/ws/1.1/track.richsync.get?${new URLSearchParams({app_id:"web-desktop-app-v1.0",usertoken:a.usertoken,track_id:f})}`;try{this.debugLog("Musixmatch lyrics fetch URL:",p);const m=yield fetch(p,{headers:{cookie:a.cookies}});if(!m.ok)return this.warnLog(`Lyrics fetch request failed with status ${m.status} (${m.statusText}) [Musixmatch - Word Synced Lyrics]`),null;const k= -yield m.json();if(401===(null===(b=null===(d=null===k||void 0===k?void 0:k.message)||void 0===d?void 0:d.header)||void 0===b?void 0:b.status_code)&&"captcha"===(null===(e=null===(c=null===k||void 0===k?void 0:k.message)||void 0===c?void 0:c.header)||void 0===e?void 0:e.hint))return this.warnLog("The usertoken has been temporary blocked for too many requests (captcha)... [Musixmatch - Word Synced Lyrics]"),null;this.debugLog("Musixmatch track data:",null===(g=null===k||void 0===k?void 0:k.message)|| -void 0===g?void 0:g.body);let q=null===(n=null===(l=null===(h=null===k||void 0===k?void 0:k.message)||void 0===h?void 0:h.body)||void 0===l?void 0:l.richsync)||void 0===n?void 0:n.richsync_body;if(!q||0>=q.length)return this.infoLog("Missing Lyrics [Musixmatch - Word Synced Lyrics]"),null;q=JSON.parse(q);const y=q.map(r=>{const v=r.ts,w=r.te,z=r.x;r=r.l.map(x=>({character:x.c,time:x.o}));return{end:w,lyric:z,start:v,syncedLyric:r}});this.infoLog("Successfully fetched and cached the synced lyrics [Musixmatch]"); -return y}catch(m){return this.errorLog("Something went wrong while fetching the lyrics [Musixmatch - Word Synced Lyrics]",m),null}})}_fetchLyricsMusixmatch(a,f,d,b,c,e,g,h){return __awaiter(this,void 0,void 0,function*(){if(!a||!b&&!d||!f||!c&&!e&&!g)return null;const l={plain:null,lineSynced:null,wordSynced:null};c&&b&&h.includes("plain")&&(l.plain=yield this._fetchPlainLyricsMusixmatch(f,b));e&&b&&h.includes("lineSynced")&&(l.lineSynced=yield this._fetchLineSyncedLyricsMusixmatch(f,b));g&&b&&h.includes("wordSynced")&& -(l.wordSynced=yield this._fetchWordSyncedLyricsMusixmatch(f,d));return l})}_searchLyricsNetease(a){return __awaiter(this,void 0,void 0,function*(){var f,d,b,c,e;const g=`https://music.xianqiao.wang/neteaseapiv2/search?${new URLSearchParams({limit:10,type:1,keywords:`${a.track} ${a.artist}`})}`;try{this.debugLog("Netease search fetch URL:",g);const h=yield fetch(g,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"}});if(!h.ok)return this.warnLog(`Lyrics fetch request failed with status ${h.status} (${h.statusText}) [Netease - Search]`), -null;const l=yield h.json();if(null===(f=null===l||void 0===l?void 0:l.result)||void 0===f||!f.songs||0>=(null===(b=null===(d=null===l||void 0===l?void 0:l.result)||void 0===d?void 0:d.songs)||void 0===b?void 0:b.length))return this.infoLog("No songs were found [Netease - Search]"),null;const n=null===(e=null===(c=null===l||void 0===l?void 0:l.result)||void 0===c?void 0:c.songs)||void 0===e?void 0:e.find(m=>{var k,q;return(null===(k=m.name)||void 0===k?void 0:k.toLowerCase())===(null===(q=a.track)|| -void 0===q?void 0:q.toLowerCase())&&(m.artists.some(y=>{var r,v,w;return null===(v=null===(r=y.name)||void 0===r?void 0:r.toLowerCase())||void 0===v?void 0:v.includes(null===(w=a.artist)||void 0===w?void 0:w.toLowerCase())})||m.artists.some(y=>{var r,v,w,z,x;return null===(w=null===(v=null===(r=y.name)||void 0===r?void 0:r.toLowerCase())||void 0===v?void 0:v.replace(/-/g," "))||void 0===w?void 0:w.includes(null===(x=null===(z=a.artist)||void 0===z?void 0:z.toLowerCase())||void 0===x?void 0:x.replace(/-/g, -" "))}))});this.debugLog("Netease search filtered track:",n);if(!n)return this.infoLog("No songs were found with the current name and artist [Netease - Search]"),null;const p=n.id;this.debugLog("Neteasw track ID",p);return p}catch(h){return this.errorLog("Something went wrong while fetching the lyrics [Netease - Search]",h),null}})}_fetchLyricsNetease(a,f){return __awaiter(this,void 0,void 0,function*(){var d;if(!a||!f)return null;const b=`https://music.xianqiao.wang/neteaseapiv2/lyric?${new URLSearchParams({id:f})}`; -try{this.debugLog("Netease lyrics fetch URL:",b);const c=yield fetch(b,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"}});if(!c.ok)return this.warnLog(`Lyrics fetch request failed with status ${c.status} (${c.statusText}) [Netease - Lyrics]`),null;const e=yield c.json();this.debugLog("Netease track data:",e);let g=null===(d=null===e||void 0===e?void 0:e.lrc)||void 0===d?void 0:d.lyric;if(!g)return this.infoLog("Missing Lyrics [Netease - Lyrics]"), -null;g=this._parseNeteaseLyrics(g);this.infoLog("Successfully fetched and cached the synced lyrics [Netease]");return g}catch(c){return this.errorLog("Something went wrong while fetching the lyrics [Netease - Lyrics]",c),null}})}_parseNeteaseLyrics(a){a=a.split(/\r?\n/).map(e=>e.trim());const f=[],d=RegExp("^(\\s?\u4f5c?\\s*\u8bcd|\\s?\u4f5c?\\s*\u66f2|\\s?\u7f16\\s*\u66f2?|\\s?\u76d1\\s*\u5236?|.*\u7f16\u5199|.*\u548c\u97f3|.*\u548c\u58f0|.*\u5408\u58f0|.*\u63d0\u7434|.*\u5f55|.*\u5de5\u7a0b|.*\u5de5\u4f5c\u5ba4|.*\u8bbe\u8ba1|.*\u526a\u8f91|.*\u5236\u4f5c|.*\u53d1\u884c|.*\u51fa\u54c1|.*\u540e\u671f|.*\u6df7\u97f3|.*\u7f29\u6df7|\u539f\u5531|\u7ffb\u5531|\u9898\u5b57|\u6587\u6848|\u6d77\u62a5|\u53e4\u7b5d|\u4e8c\u80e1|\u94a2\u7434|\u5409\u4ed6|\u8d1d\u65af|\u7b1b\u5b50|\u9f13|\u5f26\u4e50| \u4eba\u58f0 |lrc|publish|vocal|guitar|program|produce|write|mix).*(:|\uff1a)", -"i");for(let e=0;e{var n,p,m,k;return(null===(n=l.artistName)||void 0===n?void 0:n.toLowerCase().includes(null===(p=a.artist)||void 0===p?void 0:p.toLowerCase()))&&(null===(m=l.trackName)||void 0===m?void 0:m.toLowerCase())===(null===(k=a.track)||void 0===k?void 0:k.toLowerCase())});this.debugLog("lrclib filtered track:",h);if(!h||(!h.syncedLyrics||0>=(null===(d=h.syncedLyrics)||void 0===d?void 0:d.length))&&(!h.plainLyrics||0>=(null===(b=h.plainLyrics)||void 0===b?void 0:b.length)))return this.infoLog("The fetched song does not have lyrics [LRCLIB]"), -null;this.infoLog("Successfully fetched and cached the lyrics [LRCLIB]");return{source:"lrclib.net",plain:null===h||void 0===h?void 0:h.plainLyrics,lineSynced:null===h||void 0===h?void 0:h.syncedLyrics,wordSynced:null}}catch(e){return this.errorLog("Something went wrong while fetching the lyrics [LRCLIB]",e),null}})}fetchLyricsMusixmatch(a,f){return __awaiter(this,void 0,void 0,function*(){if(!a)return null;var d=yield this.getMusixmatchUsertoken();this.debugLog("Musixmatch token data:",d);if(!d)return null; -this.infoLog(`Fetching the lyrics for "${a.track}" from "${a.album}" from "${a.artist}" (${this._trackId}) [Musixmatch]`);const b=yield this._searchLyricsMusixmatch(a,d);if(!b||!b.hasLyrics&&!b.hasLineSyncedLyrics&&!b.hasWordSyncedLyrics||!b.commonTrackId&&!b.trackId)return this.infoLog("Missing both commontrack_id and track_id [Musixmatch - Search]"),null;d=yield this._fetchLyricsMusixmatch(a,d,b.trackId,b.commonTrackId,b.hasLyrics,b.hasLineSyncedLyrics,b.hasWordSyncedLyrics,f);return Object.assign({source:"Musixmatch"}, -d)})}fetchLyricsNetease(a,f){return __awaiter(this,void 0,void 0,function*(){if(!a||!f.includes("lineSynced"))return null;const d=yield this._searchLyricsNetease(a);return d?{source:"Netease",lineSynced:yield this._fetchLyricsNetease(a,d),plain:null,wordSynced:null}:(this.infoLog("Missing track ID [Netease - Search]"),null)})}_getLyrics(a,f){return __awaiter(this,void 0,void 0,function*(){const d={musixmatch:["plain","line","word"],lrclib:["plain","line"],netease:["line"]},b={musixmatch:this.fetchLyricsMusixmatch, -lrclib:this.fetchLyricsLrclib,netease:this.fetchLyricsNetease};var c=this.sources||["musixmatch","lrclib","netease"];const e={plain:{source:null,lyrics:null},lineSynced:{source:null,lyrics:null},wordSynced:{source:null,lyrics:null}};if(this._fetching)return e;this._fetching=!0;c.every(g=>!Object.keys(b).includes(g))&&(c=["musixmatch","lrclib","netease"]);a:for(const g of c){this.infoLog(`Trying to fetch the lyrics from the source "${g}"`);if(!("musixmatch"!==g||this.saveMusixmatchToken&&this.getMusixmatchToken)){this.infoLog("Musixmatch token functions are not avaible, skipping..."); -continue}c=0;const h=d[g];for(const l of h)if("plain"!==l||!e.plain.lyrics&&f.includes("plain")||c++,"line"!==l||!e.lineSynced.lyrics&&f.includes("lineSynced")||c++,"word"!==l||!e.wordSynced.lyrics&&f.includes("wordSynced")||c++,c>=h.length)continue a;if(Object.keys(b).includes(g)){if(c=yield b[g](a,f))(null===c||void 0===c?0:c.plain)&&!e.plain.lyrics&&(e.plain.lyrics=c.plain,e.plain.source=c.source),(null===c||void 0===c?0:c.lineSynced)&&!e.lineSynced.lyrics&&(e.lineSynced.lyrics=c.lineSynced,e.lineSynced.source= -c.source),(null===c||void 0===c?0:c.wordSynced)&&!e.wordSynced.lyrics&&(e.wordSynced.lyrics=c.wordSynced,e.wordSynced.source=c.source)}else this.infoLog(`The source "${g}" doesn't exist, skipping...`)}this._fetching=!1;return e})}getLyrics(a,f){return __awaiter(this,void 0,void 0,function*(){if(!((null===a||void 0===a?0:a.track)||(null===a||void 0===a?0:a.artist)||(null===a||void 0===a?0:a.album)||(null===a||void 0===a?0:a.trackId)))throw Error("SyncLyrics (getlyrics): At least one of track, artist, album or trackId must be present"); -this._trackId=a.trackId||btoa(unescape(encodeURIComponent(`${a.track||""}----${a.artist||""}----${a.album||""}`)));var d=Array.isArray(a.lyricsType)?a.lyricsType:["plain","lineSynced","wordSynced"];0>=d.length&&(d=["plain","lineSynced","wordSynced"]);var b=f?null:this.cache.get(this._trackId);if(a.trackId&&!b){var c=atob(a.trackId).split("----");b=c.shift()||"";const e=c.shift()||"";c=c.shift()||"";return yield this.getLyrics({track:b,artist:e,album:c,lyricsType:d},f)}d=b||(yield this._getLyrics(a, -d));!f&&(!this.cache.has(this._trackId)||(null===d||void 0===d?0:d.plain.lyrics)&&(null===b||void 0===b||!b.plain.lyrics)||(null===d||void 0===d?0:d.lineSynced.lyrics)&&(null===b||void 0===b||!b.lineSynced.lyrics)||(null===d||void 0===d?0:d.wordSynced.lyrics)&&(null===b||void 0===b||!b.wordSynced.lyrics))&&this.cache.set(this._trackId,d||{plain:{lyrics:null,source:null},lineSynced:{lyrics:null,source:null},wordSynced:{lyrics:null,source:null}});if(!d)return{trackId:this._trackId,lyrics:{plain:{lyrics:null, -source:null},lineSynced:{lyrics:null,source:null,parse:this.parseLyrics},wordSynced:{lyrics:null,source:null}},track:a.track,artist:a.artist,album:a.album,cached:!1};this.lyrics=d.lineSynced.lyrics;return{trackId:this._trackId,lyrics:Object.assign(Object.assign({},d),{lineSynced:Object.assign(Object.assign({},d.lineSynced),{parse:this.parseLyrics})}),track:a.track,artist:a.artist,album:a.album,cached:!!b}})}parseLyrics(a=this.lyrics){a=null===a||void 0===a?void 0:a.split("\n");if(!a)return null;const f= -[];let d;for(const g in a){var b=a[g].split(" ");const h=b.shift().replace(/[\[\]]/g,"");b=b.join(" ");var c=h.split(":")[0],e=h.split(":")[1];c=60*Number.parseFloat(c)+Number.parseFloat(e);e=this.instrumentalLyricsIndicator||"\uf001 ";"0"===g&&3=a.length)throw Error('SyncLyrics: sources must be an array with atleast one of "musixmatch" | "lrclib" | "netease"');this.sources=a;return this}setCache(a){if(!a)return this.cache=new Map,this;if("function"!==typeof a.get||"function"!==typeof a.set||"function"!==typeof a.has)throw Error("SyncLyrics: cache must have .get, .set and .has methods");this.cache=a;return this}setSaveMusixmatchToken(a){if("function"!==typeof a)throw Error("SyncLyrics: saveMusixmatchToken must be a function"); -this.saveMusixmatchToken=a;return this}setGetMusixmatchToken(a){if("function"!==typeof a)throw Error("SyncLyrics: getMusixmatchToken must be a function");this.getMusixmatchToken=a;return this}warnLog(...a){(exports.logLevels[this.logLevel]||0)SyncLyrics | SyncLyrics - v2.5.6

Class SyncLyrics

Constructors

constructor +SyncLyrics | SyncLyrics - v2.5.7

Class SyncLyrics

Constructors

Properties

_fetching _trackId cache @@ -38,20 +38,20 @@

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

    +

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

    +
  • Fetches the line synced lyrics from Netease

    +
  • 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

    +
  • 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

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

    +
  • Removes useless metadata returned by Netease

    +
  • Removes useless metadata returned by Netease

    Parameters

    • slyrics: string

      Lyrics returned by Netease

    Returns string

    Netease returned lyrics without extra metadata

    -
  • Searchs the Netease catalog with the data provided in the metadata

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

    +
  • 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

    +
  • 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

    +
  • Logs the text with a blue "INFO: " prefix

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing

    -
  • Updates or resets the cache

    +
  • Updates or resets the cache

    Parameters

    Returns this

    Updated SyncLyrics instance

    -
  • Updates or removes the getMusixmatchToken function

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

    +
  • 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 resets the log level

    +
  • Updates or removes the saveMusixmatchToken function

    +
  • 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

    -
  • Updates or resets the sources

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

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

    Parameters

    • Rest...args: any

      Text to log

    Returns void

    Nothing

    -
+
diff --git a/docs/functions/normalize.html b/docs/functions/normalize.html index 9a1f39d..bd7d678 100644 --- a/docs/functions/normalize.html +++ b/docs/functions/normalize.html @@ -1,4 +1,4 @@ -normalize | SyncLyrics - v2.5.6

Function normalize

  • Parses special characters (Usually returned by Netease) into common characters

    +normalize | SyncLyrics - v2.5.7

    Function normalize

    • Parses special characters (Usually returned by Netease) into common characters

      Parameters

      • string: string

        The string to parse

      Returns string

      Parsed string with common characters

      -
    +
diff --git a/docs/index.html b/docs/index.html index 5cc1499..b31099c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -SyncLyrics - v2.5.6

SyncLyrics - v2.5.6

@stef-0012/synclyrics (SyncLyrics)

SyncLyrics allows you to get the plain, line synced and word synced lyrics of any song avaible on Musixmatch, LrcLib.net or Netease.

+SyncLyrics - v2.5.7

SyncLyrics - v2.5.7

@stef-0012/synclyrics (SyncLyrics)

SyncLyrics allows you to get the plain, line synced and word synced lyrics of any song avaible on Musixmatch, LrcLib.net or Netease.

Installation: npm i @stef-0012/synclyrics.

Usage

const { SyncLyrics } = require("@stef-0012/synclyrics");

let mxmToken; // This is just for the custom save/get functions example

const LyricsManager = new SyncLyrics({
/* Each of those options is optional */
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;
},
})

LyricsManager.getLyrics({
/* Each of those options is optional but atleast one is required excluded length */
track: "the old me", // Song name
artist: "Henry Moodie", // Song artist
album: "good old days", // Song album
length: 175000, // Song duration, in ms
}).then(data => {
console.log(data)
}) // Array of objects with time as seconds and text of each line

// or

const trackId = LyricsManager.getTrackId({
/* Each of those options is optional but atleast one is required excluded length */
track: "the old me", // Song name
artist: "Henry Moodie", // Song artist
album: "good old days", // Song album
length: 175000, // Song duration, in ms
})

LyricsManager.getLyrics({
trackId: trackId
}).then(data => {
console.log(data)
})
@@ -9,4 +9,4 @@

Example Parse Output

[
{
time: 0.14,
text: 'Fifth of November, when I walked you home'
},
{
time: 8.06,
text: `That's when I nearly said it, but then said, "Forget it," and froze`
},
{
time: 15.55,
text: "Do you remember? You probably don't"
},
{
time: 23.44,
text: "'Cause the sparks in the sky took a hold of your eyes while we spoke"
},
// ..... (rest of the lyrics)
]
-
+
diff --git a/docs/interfaces/Cache.html b/docs/interfaces/Cache.html index 1ba4448..bb83439 100644 --- a/docs/interfaces/Cache.html +++ b/docs/interfaces/Cache.html @@ -1,8 +1,8 @@ -Cache | SyncLyrics - v2.5.6

Interface Cache<K, V>

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

-
interface Cache<K, V> {
    get(key: K): undefined | null | V;
    has(key: K): boolean;
    set(key: K, value: V): void;
    [key: string]: any;
}

Type Parameters

  • K
  • V

Indexable

  • [key: string]: any

Methods

get +Cache | SyncLyrics - v2.5.7

Interface Cache<K, V>

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

+
interface Cache<K, V> {
    get(key: K): undefined | null | V;
    has(key: K): boolean;
    set(key: K, value: V): void;
    [key: string]: any;
}

Type Parameters

  • K
  • V

Indexable

  • [key: string]: any

Methods

Methods

  • Function used to get the song's data to the cache

    -

    Parameters

    • key: K

    Returns undefined | null | V

  • Function to check if the cache has the song's data

    -

    Parameters

    • key: K

    Returns boolean

  • Function used to set the song's data to the cache

    -

    Parameters

    • key: K
    • value: V

    Returns void

+

Parameters

  • key: K

Returns undefined | null | V

  • Function to check if the cache has the song's data

    +

    Parameters

    • key: K

    Returns boolean

  • Function used to set the song's data to the cache

    +

    Parameters

    • key: K
    • value: V

    Returns void

diff --git a/docs/interfaces/CacheLineSyncedLyricsData.html b/docs/interfaces/CacheLineSyncedLyricsData.html index 5360a74..b5380dc 100644 --- a/docs/interfaces/CacheLineSyncedLyricsData.html +++ b/docs/interfaces/CacheLineSyncedLyricsData.html @@ -1,5 +1,5 @@ -CacheLineSyncedLyricsData | SyncLyrics - v2.5.6

Interface CacheLineSyncedLyricsDataPrivate

interface CacheLineSyncedLyricsData {
    lyrics: undefined | null | string;
    source: undefined | null | string;
}

Properties

lyrics +CacheLineSyncedLyricsData | SyncLyrics - v2.5.7

Interface CacheLineSyncedLyricsDataPrivate

interface CacheLineSyncedLyricsData {
    lyrics: undefined | null | string;
    source: undefined | null | string;
}

Properties

Properties

lyrics: undefined | null | string

Line synced lyrics in the LRC format

-
source: undefined | null | string

Lyrics source

-
+
source: undefined | null | string

Lyrics source

+
diff --git a/docs/interfaces/CacheLyrics.html b/docs/interfaces/CacheLyrics.html index eb5d7c0..252386d 100644 --- a/docs/interfaces/CacheLyrics.html +++ b/docs/interfaces/CacheLyrics.html @@ -1,7 +1,7 @@ -CacheLyrics | SyncLyrics - v2.5.6

Interface CacheLyricsPrivate

interface CacheLyrics {
    lineSynced: CacheLineSyncedLyricsData;
    plain: PlainLyricsData;
    wordSynced: WordSyncedLyricsData;
}

Properties

lineSynced +CacheLyrics | SyncLyrics - v2.5.7

Interface CacheLyricsPrivate

interface CacheLyrics {
    lineSynced: CacheLineSyncedLyricsData;
    plain: PlainLyricsData;
    wordSynced: WordSyncedLyricsData;
}

Properties

+
diff --git a/docs/interfaces/Data.html b/docs/interfaces/Data.html index 284cb79..e7e9918 100644 --- a/docs/interfaces/Data.html +++ b/docs/interfaces/Data.html @@ -1,13 +1,13 @@ -Data | SyncLyrics - v2.5.6

Interface Data

interface Data {
    cache?: Cache<undefined | null | string, undefined | null | CacheLyrics>;
    getMusixmatchToken?: (() =>
        | undefined
        | null
        | TokenData
        | Promise<undefined | null | TokenData>);
    instrumentalLyricsIndicator?: string;
    logLevel?: LogLevel;
    saveMusixmatchToken?: ((tokenData: TokenData) => void | Promise<void>);
    sources?: Sources;
}

Properties

cache? +Data | SyncLyrics - v2.5.7

Interface Data

interface Data {
    cache?: Cache<undefined | null | string, undefined | null | CacheLyrics>;
    getMusixmatchToken?: (() =>
        | undefined
        | null
        | TokenData
        | Promise<undefined | null | TokenData>);
    instrumentalLyricsIndicator?: string;
    logLevel?: LogLevel;
    saveMusixmatchToken?: ((tokenData: TokenData) => void | Promise<void>);
    sources?: Sources;
}

Properties

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

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

-
getMusixmatchToken?: (() =>
    | 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

-
saveMusixmatchToken?: ((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

-
+
getMusixmatchToken?: (() =>
    | 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

+
saveMusixmatchToken?: ((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

+
diff --git a/docs/interfaces/FormattedLyric.html b/docs/interfaces/FormattedLyric.html index df01281..1d5eb5f 100644 --- a/docs/interfaces/FormattedLyric.html +++ b/docs/interfaces/FormattedLyric.html @@ -1,5 +1,5 @@ -FormattedLyric | SyncLyrics - v2.5.6

Interface FormattedLyric

interface FormattedLyric {
    text: string;
    time: number;
}

Properties

text +FormattedLyric | SyncLyrics - v2.5.7

Interface FormattedLyric

interface FormattedLyric {
    text: string;
    time: number;
}

Properties

Properties

text: string

Lyric's text

-
time: number

When the lyric starts

-
+
time: number

When the lyric starts

+
diff --git a/docs/interfaces/LineSyncedLyricsData.html b/docs/interfaces/LineSyncedLyricsData.html index e972be3..6b0be30 100644 --- a/docs/interfaces/LineSyncedLyricsData.html +++ b/docs/interfaces/LineSyncedLyricsData.html @@ -1,7 +1,7 @@ -LineSyncedLyricsData | SyncLyrics - v2.5.6

Interface LineSyncedLyricsData

interface LineSyncedLyricsData {
    lyrics: undefined | null | string;
    parse: ((lyrics?: null | string) => null | FormattedLyric[]);
    source: undefined | null | string;
}

Properties

lyrics +LineSyncedLyricsData | SyncLyrics - v2.5.7

Interface LineSyncedLyricsData

interface LineSyncedLyricsData {
    lyrics: undefined | null | string;
    parse: ((lyrics?: null | string) => null | FormattedLyric[]);
    source: undefined | null | string;
}

Properties

Properties

lyrics: undefined | null | string

Line synced lyrics in the LRC format

-
parse: ((lyrics?: null | string) => null | FormattedLyric[])

Function to parse the returned lyrics into FormattedLyric

-
source: undefined | null | string

Lyrics source

-
+
parse: ((lyrics?: null | string) => null | FormattedLyric[])

Function to parse the returned lyrics into FormattedLyric

+
source: undefined | null | string

Lyrics source

+
diff --git a/docs/interfaces/LrcLibFetchResult.html b/docs/interfaces/LrcLibFetchResult.html index 4874806..a800923 100644 --- a/docs/interfaces/LrcLibFetchResult.html +++ b/docs/interfaces/LrcLibFetchResult.html @@ -1,9 +1,9 @@ -LrcLibFetchResult | SyncLyrics - v2.5.6

Interface LrcLibFetchResultPrivate

interface LrcLibFetchResult {
    lineSynced: null | string;
    plain: null | string;
    source: "lrclib.net";
    wordSynced: null;
}

Properties

lineSynced +LrcLibFetchResult | SyncLyrics - v2.5.7

Interface LrcLibFetchResultPrivate

interface LrcLibFetchResult {
    lineSynced: null | string;
    plain: null | string;
    source: "lrclib.net";
    wordSynced: null;
}

Properties

lineSynced: null | string

Line synced lyrics if avaible

-
plain: null | string

Plain lyrics if avaible

-
source
wordSynced

Always null as lrclib.net does not support word synced lyrics

-
+
plain: null | string

Plain lyrics if avaible

+
source
wordSynced

Always null as lrclib.net does not support word synced lyrics

+
diff --git a/docs/interfaces/Lyrics.html b/docs/interfaces/Lyrics.html index aca01a3..2bcf421 100644 --- a/docs/interfaces/Lyrics.html +++ b/docs/interfaces/Lyrics.html @@ -1,7 +1,7 @@ -Lyrics | SyncLyrics - v2.5.6

Interface Lyrics

interface Lyrics {
    lineSynced: LineSyncedLyricsData;
    plain: PlainLyricsData;
    wordSynced: WordSyncedLyricsData;
}

Properties

lineSynced +Lyrics | SyncLyrics - v2.5.7

Interface Lyrics

interface Lyrics {
    lineSynced: LineSyncedLyricsData;
    plain: PlainLyricsData;
    wordSynced: WordSyncedLyricsData;
}

Properties

+
diff --git a/docs/interfaces/LyricsOutput.html b/docs/interfaces/LyricsOutput.html index 14f7e53..7aa20b5 100644 --- a/docs/interfaces/LyricsOutput.html +++ b/docs/interfaces/LyricsOutput.html @@ -1,13 +1,13 @@ -LyricsOutput | SyncLyrics - v2.5.6

Interface LyricsOutput

interface LyricsOutput {
    album: undefined | string;
    artist: undefined | string;
    cached: boolean;
    lyrics: Lyrics;
    track: undefined | string;
    trackId: string;
}

Properties

album +LyricsOutput | SyncLyrics - v2.5.7

Interface LyricsOutput

interface LyricsOutput {
    album: undefined | string;
    artist: undefined | string;
    cached: boolean;
    lyrics: Lyrics;
    track: undefined | string;
    trackId: string;
}

Properties

album: undefined | string

Song's album

-
artist: undefined | string

Song's artist(s)

-
cached: boolean

Whetever the song data was retrieved from the cache rather than the APIs

-
lyrics: Lyrics

Object with track's avaible lyrics

-
track: undefined | string

Song's name

-
trackId: string

Fetched track's ID

-
+
artist: undefined | string

Song's artist(s)

+
cached: boolean

Whetever the song data was retrieved from the cache rather than the APIs

+
lyrics: Lyrics

Object with track's avaible lyrics

+
track: undefined | string

Song's name

+
trackId: string

Fetched track's ID

+
diff --git a/docs/interfaces/Metadata.html b/docs/interfaces/Metadata.html index 2f7aefe..b86e9fd 100644 --- a/docs/interfaces/Metadata.html +++ b/docs/interfaces/Metadata.html @@ -1,14 +1,14 @@ -Metadata | SyncLyrics - v2.5.6

Interface Metadata

Song's metadata

-
interface Metadata {
    album?: string;
    artist?: string;
    length?: number;
    lyricsType?: LyricType;
    track?: string;
    trackId?: string;
}

Properties

album? +Metadata | SyncLyrics - v2.5.7

Interface Metadata

Song's metadata

+
interface Metadata {
    album?: string;
    artist?: string;
    length?: number;
    lyricsType?: LyricType;
    track?: string;
    trackId?: string;
}

Properties

album?: string

Song's album

-
artist?: string

Song's artist(s)

-
length?: number

Song's duration (in ms)

-
lyricsType?: LyricType

An array of lyric types to fetch

-
track?: string

Song's name

-
trackId?: string

Song's ID (returned by getTrackId)

-
+
artist?: string

Song's artist(s)

+
length?: number

Song's duration (in ms)

+
lyricsType?: LyricType

An array of lyric types to fetch

+
track?: string

Song's name

+
trackId?: string

Song's ID (returned by getTrackId)

+
diff --git a/docs/interfaces/MusixmatchFetchResult.html b/docs/interfaces/MusixmatchFetchResult.html index 5ec4070..d00c4e7 100644 --- a/docs/interfaces/MusixmatchFetchResult.html +++ b/docs/interfaces/MusixmatchFetchResult.html @@ -1,9 +1,9 @@ -MusixmatchFetchResult | SyncLyrics - v2.5.6

Interface MusixmatchFetchResultPrivate

interface MusixmatchFetchResult {
    lineSynced?: null | string;
    plain?: null | string;
    source: "Musixmatch";
    wordSynced?: null | WordSyncedLyrics[];
}

Properties

lineSynced? +MusixmatchFetchResult | SyncLyrics - v2.5.7

Interface MusixmatchFetchResultPrivate

interface MusixmatchFetchResult {
    lineSynced?: null | string;
    plain?: null | string;
    source: "Musixmatch";
    wordSynced?: null | WordSyncedLyrics[];
}

Properties

lineSynced?: null | string

Line synced lyrics if avaible

-
plain?: null | string

Plain lyrics if avaible

-
source

Musixmatch

-
wordSynced?: null | WordSyncedLyrics[]

Line synced lyrics if avaible

-
+
plain?: null | string

Plain lyrics if avaible

+
source

Musixmatch

+
wordSynced?: null | WordSyncedLyrics[]

Line synced lyrics if avaible

+
diff --git a/docs/interfaces/MusixmatchLyricsFetchResult.html b/docs/interfaces/MusixmatchLyricsFetchResult.html index f81c25d..b1085c8 100644 --- a/docs/interfaces/MusixmatchLyricsFetchResult.html +++ b/docs/interfaces/MusixmatchLyricsFetchResult.html @@ -1,7 +1,7 @@ -MusixmatchLyricsFetchResult | SyncLyrics - v2.5.6

Interface MusixmatchLyricsFetchResultPrivate

interface MusixmatchLyricsFetchResult {
    lineSynced: null | string;
    plain: null | string;
    wordSynced: null | WordSyncedLyrics[];
}

Properties

lineSynced +MusixmatchLyricsFetchResult | SyncLyrics - v2.5.7

Interface MusixmatchLyricsFetchResultPrivate

interface MusixmatchLyricsFetchResult {
    lineSynced: null | string;
    plain: null | string;
    wordSynced: null | WordSyncedLyrics[];
}

Properties

lineSynced: null | string

Track's line synced lyrics

-
plain: null | string

Track's plain lyrics

-
wordSynced: null | WordSyncedLyrics[]

Track's word synced lyrics

-
+
plain: null | string

Track's plain lyrics

+
wordSynced: null | WordSyncedLyrics[]

Track's word synced lyrics

+
diff --git a/docs/interfaces/MusixmatchSearchResult.html b/docs/interfaces/MusixmatchSearchResult.html index 0c8ed8e..7efdf44 100644 --- a/docs/interfaces/MusixmatchSearchResult.html +++ b/docs/interfaces/MusixmatchSearchResult.html @@ -1,11 +1,11 @@ -MusixmatchSearchResult | SyncLyrics - v2.5.6

Interface MusixmatchSearchResultPrivate

interface MusixmatchSearchResult {
    commonTrackId: string;
    hasLineSyncedLyrics: boolean;
    hasLyrics: boolean;
    hasWordSyncedLyrics: boolean;
    trackId: string;
}

Properties

commonTrackId +MusixmatchSearchResult | SyncLyrics - v2.5.7

Interface MusixmatchSearchResultPrivate

interface MusixmatchSearchResult {
    commonTrackId: string;
    hasLineSyncedLyrics: boolean;
    hasLyrics: boolean;
    hasWordSyncedLyrics: boolean;
    trackId: string;
}

Properties

commonTrackId: string

Musixmatch's commontrack_id

-
hasLineSyncedLyrics: boolean

Whetever the Musixmatch's catalogue has the song's line synced lyrics

-
hasLyrics: boolean

Whetever the Musixmatch's catalogue has the song's plain lyrics

-
hasWordSyncedLyrics: boolean

Whetever the Musixmatch's catalogue has the song's word synced lyrics

-
trackId: string

Musixmatch's track_id

-
+
hasLineSyncedLyrics: boolean

Whetever the Musixmatch's catalogue has the song's line synced lyrics

+
hasLyrics: boolean

Whetever the Musixmatch's catalogue has the song's plain lyrics

+
hasWordSyncedLyrics: boolean

Whetever the Musixmatch's catalogue has the song's word synced lyrics

+
trackId: string

Musixmatch's track_id

+
diff --git a/docs/interfaces/NeteaseFetchResult.html b/docs/interfaces/NeteaseFetchResult.html index 6ae294d..e4ed090 100644 --- a/docs/interfaces/NeteaseFetchResult.html +++ b/docs/interfaces/NeteaseFetchResult.html @@ -1,9 +1,9 @@ -NeteaseFetchResult | SyncLyrics - v2.5.6

Interface NeteaseFetchResultPrivate

interface NeteaseFetchResult {
    lineSynced: null | string;
    plain: null;
    source: "Netease";
    wordSynced: null;
}

Properties

lineSynced +NeteaseFetchResult | SyncLyrics - v2.5.7

Interface NeteaseFetchResultPrivate

interface NeteaseFetchResult {
    lineSynced: null | string;
    plain: null;
    source: "Netease";
    wordSynced: null;
}

Properties

lineSynced: null | string

Line synced lyrics if avaible

-
plain

Always null as Netease does not support word synced lyrics

-
source

Netease

-
wordSynced

Always null as Netease does not support word synced lyrics

-
+
plain

Always null as Netease does not support word synced lyrics

+
source

Netease

+
wordSynced

Always null as Netease does not support word synced lyrics

+
diff --git a/docs/interfaces/PlainLyricsData.html b/docs/interfaces/PlainLyricsData.html index 70a064e..6bfdd15 100644 --- a/docs/interfaces/PlainLyricsData.html +++ b/docs/interfaces/PlainLyricsData.html @@ -1,5 +1,5 @@ -PlainLyricsData | SyncLyrics - v2.5.6

Interface PlainLyricsData

interface PlainLyricsData {
    lyrics: undefined | null | string;
    source: undefined | null | string;
}

Properties

lyrics +PlainLyricsData | SyncLyrics - v2.5.7

Interface PlainLyricsData

interface PlainLyricsData {
    lyrics: undefined | null | string;
    source: undefined | null | string;
}

Properties

Properties

lyrics: undefined | null | string

Lyrics as plain text

-
source: undefined | null | string

Lyrics source

-
+
source: undefined | null | string

Lyrics source

+
diff --git a/docs/interfaces/TokenData.html b/docs/interfaces/TokenData.html index 08f9383..03e435c 100644 --- a/docs/interfaces/TokenData.html +++ b/docs/interfaces/TokenData.html @@ -1,8 +1,8 @@ -TokenData | SyncLyrics - v2.5.6

Interface TokenDataPrivate

Musixmatch token data

-
interface TokenData {
    cookies: undefined | string;
    expiresAt: number;
    usertoken: string;
}

Properties

cookies +TokenData | SyncLyrics - v2.5.7

Interface TokenDataPrivate

Musixmatch token data

+
interface TokenData {
    cookies: undefined | string;
    expiresAt: number;
    usertoken: string;
}

Properties

cookies: undefined | string

Cookies used for the Musixmatch's API request

-
expiresAt: number

When the Musixmatch's usertoken expires

-
usertoken: string

Musixmatch's usertoken

-
+
expiresAt: number

When the Musixmatch's usertoken expires

+
usertoken: string

Musixmatch's usertoken

+
diff --git a/docs/interfaces/WordSyncedLyrics.html b/docs/interfaces/WordSyncedLyrics.html index 3660604..909bbf7 100644 --- a/docs/interfaces/WordSyncedLyrics.html +++ b/docs/interfaces/WordSyncedLyrics.html @@ -1,9 +1,9 @@ -WordSyncedLyrics | SyncLyrics - v2.5.6

Interface WordSyncedLyrics

interface WordSyncedLyrics {
    end: number;
    lyric: string;
    start: number;
    syncedLyric: WordSyncedLyricsLine[];
}

Properties

end +WordSyncedLyrics | SyncLyrics - v2.5.7

Interface WordSyncedLyrics

interface WordSyncedLyrics {
    end: number;
    lyric: string;
    start: number;
    syncedLyric: WordSyncedLyricsLine[];
}

Properties

end: number

When the lyric's line ends

-
lyric: string

The lyric complete text

-
start: number

When the lyric's line starts

-
syncedLyric: WordSyncedLyricsLine[]

The lyric synced by characters

-
+
lyric: string

The lyric complete text

+
start: number

When the lyric's line starts

+
syncedLyric: WordSyncedLyricsLine[]

The lyric synced by characters

+
diff --git a/docs/interfaces/WordSyncedLyricsData.html b/docs/interfaces/WordSyncedLyricsData.html index 8338abd..8662792 100644 --- a/docs/interfaces/WordSyncedLyricsData.html +++ b/docs/interfaces/WordSyncedLyricsData.html @@ -1,5 +1,5 @@ -WordSyncedLyricsData | SyncLyrics - v2.5.6

Interface WordSyncedLyricsData

interface WordSyncedLyricsData {
    lyrics: undefined | null | WordSyncedLyrics[];
    source: undefined | null | string;
}

Properties

lyrics +WordSyncedLyricsData | SyncLyrics - v2.5.7

Interface WordSyncedLyricsData

interface WordSyncedLyricsData {
    lyrics: undefined | null | WordSyncedLyrics[];
    source: undefined | null | string;
}

Properties

Properties

lyrics: undefined | null | WordSyncedLyrics[]
source: undefined | null | string

Lyrics source

-
+
source: undefined | null | string

Lyrics source

+
diff --git a/docs/interfaces/WordSyncedLyricsLine.html b/docs/interfaces/WordSyncedLyricsLine.html index fb42cdf..4d9962c 100644 --- a/docs/interfaces/WordSyncedLyricsLine.html +++ b/docs/interfaces/WordSyncedLyricsLine.html @@ -1,5 +1,5 @@ -WordSyncedLyricsLine | SyncLyrics - v2.5.6

Interface WordSyncedLyricsLine

interface WordSyncedLyricsLine {
    character: string;
    time: number;
}

Properties

character +WordSyncedLyricsLine | SyncLyrics - v2.5.7

Interface WordSyncedLyricsLine

interface WordSyncedLyricsLine {
    character: string;
    time: number;
}

Properties

Properties

character: string

The character of the timeframe that starts at the specified time

-
time: number

When the character timeframe starts

-
+
time: number

When the character timeframe starts

+
diff --git a/docs/modules.html b/docs/modules.html index 3d0819f..7299ea2 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,4 +1,4 @@ -SyncLyrics - v2.5.6

SyncLyrics - v2.5.6

Index

Classes

SyncLyrics +SyncLyrics - v2.5.7

SyncLyrics - v2.5.7

Index

Classes

Interfaces

Functions

+
diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 9d9dd54..ebfe1d9 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,118 +2,118 @@ https://synclyrics.js.org/modules.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/index.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/classes/SyncLyrics.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/Cache.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/CacheLineSyncedLyricsData.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/CacheLyrics.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/Data.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/FormattedLyric.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/LineSyncedLyricsData.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/LrcLibFetchResult.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/Lyrics.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/LyricsOutput.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/Metadata.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/MusixmatchFetchResult.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/MusixmatchLyricsFetchResult.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/MusixmatchSearchResult.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/NeteaseFetchResult.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/PlainLyricsData.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/TokenData.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/WordSyncedLyrics.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/WordSyncedLyricsData.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/interfaces/WordSyncedLyricsLine.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/types/LogLevel.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/types/LyricType.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/types/Sources.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/variables/logLevels.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/variables/lyricType-1.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/variables/sources-1.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z https://synclyrics.js.org/functions/normalize.html - 2024-11-18T15:02:07.030Z + 2024-11-18T15:03:02.985Z diff --git a/docs/types/LogLevel.html b/docs/types/LogLevel.html index 6abd693..7b96bb3 100644 --- a/docs/types/LogLevel.html +++ b/docs/types/LogLevel.html @@ -1 +1 @@ -LogLevel | SyncLyrics - v2.5.6

Type Alias LogLevel

LogLevel:
    | "none"
    | "info"
    | "warn"
    | "error"
    | "debug"
+LogLevel | SyncLyrics - v2.5.7

Type Alias LogLevel

LogLevel:
    | "none"
    | "info"
    | "warn"
    | "error"
    | "debug"
diff --git a/docs/types/LyricType.html b/docs/types/LyricType.html index e063bd3..09465b3 100644 --- a/docs/types/LyricType.html +++ b/docs/types/LyricType.html @@ -1 +1 @@ -LyricType | SyncLyrics - v2.5.6

Type Alias LyricType

LyricType: ("plain" | "lineSynced" | "wordSynced")[]
+LyricType | SyncLyrics - v2.5.7

Type Alias LyricType

LyricType: ("plain" | "lineSynced" | "wordSynced")[]
diff --git a/docs/types/Sources.html b/docs/types/Sources.html index 385b9a2..d5c4281 100644 --- a/docs/types/Sources.html +++ b/docs/types/Sources.html @@ -1,7 +1,7 @@ -Sources | SyncLyrics - v2.5.6

Type Alias Sources

Sources: ("musixmatch" | "lrclib" | "netease")[]

Avaible sources:

+Sources | SyncLyrics - v2.5.7

Type Alias Sources

Sources: ("musixmatch" | "lrclib" | "netease")[]

Avaible sources:

-
+
diff --git a/docs/variables/logLevels.html b/docs/variables/logLevels.html index e814d45..0debb0b 100644 --- a/docs/variables/logLevels.html +++ b/docs/variables/logLevels.html @@ -1 +1 @@ -logLevels | SyncLyrics - v2.5.6

Variable logLevelsConst

logLevels: {
    debug: number;
    error: number;
    info: number;
    none: number;
    warn: number;
} = ...
+logLevels | SyncLyrics - v2.5.7

Variable logLevelsConst

logLevels: {
    debug: number;
    error: number;
    info: number;
    none: number;
    warn: number;
} = ...
diff --git a/docs/variables/lyricType-1.html b/docs/variables/lyricType-1.html index 58f1877..4dde0b6 100644 --- a/docs/variables/lyricType-1.html +++ b/docs/variables/lyricType-1.html @@ -1 +1 @@ -lyricType | SyncLyrics - v2.5.6

Variable lyricTypeConst

lyricType: LyricType = ...
+lyricType | SyncLyrics - v2.5.7

Variable lyricTypeConst

lyricType: LyricType = ...
diff --git a/docs/variables/sources-1.html b/docs/variables/sources-1.html index c595cd4..408695d 100644 --- a/docs/variables/sources-1.html +++ b/docs/variables/sources-1.html @@ -1 +1 @@ -sources | SyncLyrics - v2.5.6

Variable sourcesConst

sources: Sources = ...
+sources | SyncLyrics - v2.5.7

Variable sourcesConst

sources: Sources = ...
diff --git a/package.json b/package.json index a1176d2..52423be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stef-0012/synclyrics", - "version": "2.5.6", + "version": "2.5.7", "description": "Get the plain, line synced & word synced lyrics of any song avaible on Musixmatch, LrcLib.net or Netease", "main": "dist/index.min.js", "types": "./types/index.d.ts", diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index ba5ad88..0000000 --- a/types/index.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -export type Sources = Array<"musixmatch" | "lrclib" | "netease">; -export type LogLevel = "none" | "info" | "warn" | "error" | "debug"; -export type LyricType = Array<"plain" | "lineSynced" | "wordSynced">; -export declare const sources: Sources; -export declare const lyricType: LyricType; -export declare const logLevels: { - debug: number; - error: number; - warn: number; - info: number; - none: number; -}; -export interface TokenData { - cookies: string | undefined; - usertoken: string; - expiresAt: number; -} -export interface Metadata { - track?: string; - album?: string; - length?: number; - artist?: string; - trackId?: string; - lyricsType?: LyricType; -} -export interface Cache { - get(key: K): V | undefined | null; - set(key: K, value: V): void; - has(key: K): boolean; - [key: string]: any; -} -export interface Data { - logLevel?: LogLevel; - instrumentalLyricsIndicator?: string; - sources?: Sources; - cache?: Cache; - saveMusixmatchToken?: (tokenData: TokenData) => void | Promise; - getMusixmatchToken?: () => TokenData | null | undefined | Promise; -} -export interface FormattedLyric { - time: number; - text: string; -} -export interface LineSyncedLyricsData { - parse: (lyrics?: string | null | undefined) => FormattedLyric[] | null; - source: string | null | undefined; - lyrics: string | null | undefined; -} -export interface PlainLyricsData { - source: string | null | undefined; - lyrics: string | null | undefined; -} -export interface WordSyncedLyricsLine { - character: string; - time: number; -} -export interface WordSyncedLyrics { - end: number; - start: number; - lyric: string; - syncedLyric: Array; -} -export interface WordSyncedLyricsData { - source: string | null | undefined; - lyrics: Array | null | undefined; -} -export interface Lyrics { - wordSynced: WordSyncedLyricsData; - lineSynced: LineSyncedLyricsData; - plain: PlainLyricsData; -} -export interface CacheLineSyncedLyricsData { - source: string | null | undefined; - lyrics: string | null | undefined; -} -export interface CacheLyrics { - wordSynced: WordSyncedLyricsData; - lineSynced: CacheLineSyncedLyricsData; - plain: PlainLyricsData; -} -export interface LyricsOutput { - artist: string | undefined; - track: string | undefined; - album: string | undefined; - trackId: string; - cached: boolean; - lyrics: Lyrics; -} -export interface MusixmatchSearchResult { - hasLineSyncedLyrics: boolean; - hasWordSyncedLyrics: boolean; - commonTrackId: string; - hasLyrics: boolean; - trackId: string; -} -export interface MusixmatchLyricsFetchResult { - wordSynced: Array | null; - lineSynced: string | null; - plain: string | null; -} -export interface MusixmatchFetchResult { - wordSynced?: Array | null; - lineSynced?: string | null; - plain?: string | null; - source: "Musixmatch"; -} -export interface LrcLibFetchResult { - lineSynced: string | null; - plain: string | null; - source: "lrclib.net"; - wordSynced: null; -} -export interface NeteaseFetchResult { - lineSynced: string | null; - source: "Netease"; - wordSynced: null; - plain: null; -} -export declare class SyncLyrics { - logLevel: LogLevel; - instrumentalLyricsIndicator: string; - sources: Sources; - cache: Cache; - saveMusixmatchToken: null | undefined | ((tokenData: TokenData) => void | Promise); - getMusixmatchToken: null | undefined | (() => TokenData | Promise | null | undefined); - private lyrics; - private _trackId; - private _fetching; - constructor(data?: Data); - private getMusixmatchUsertoken; - private _searchLyricsMusixmatch; - private _fetchPlainLyricsMusixmatch; - private _fetchLineSyncedLyricsMusixmatch; - private _fetchWordSyncedLyricsMusixmatch; - private _fetchLyricsMusixmatch; - private _searchLyricsNetease; - private _fetchLyricsNetease; - private _parseNeteaseLyrics; - private fetchLyricsLrclib; - private fetchLyricsMusixmatch; - private fetchLyricsNetease; - private _getLyrics; - getLyrics(metadata: Metadata, skipCache?: boolean): Promise; - parseLyrics(lyrics?: string | null | undefined): Array | null; - getTrackId(metadata: Metadata): string; - setLogLevel(newLogLevel?: LogLevel): this; - setInstrumentalLyricsIndicator(newInstrumentalLyricsIndicator?: string): this; - setSources(newSources?: Sources): this; - setCache(newCache?: Cache): this; - setSaveMusixmatchToken(saveMusixmatchToken?: (tokenData: TokenData) => void | Promise): this; - setGetMusixmatchToken(getMusixmatchToken?: () => TokenData | Promise): this; - private warnLog; - private debugLog; - private errorLog; - private infoLog; -} -export declare function normalize(string: string): string;