@manhgdev/spotifyweb
Version:
Spotify library in typescript without using the Spotify Web API. No authentication required with automatic internal token generation.
29 lines (28 loc) • 1.66 kB
JavaScript
export var Musixmatch;
(function (Musixmatch) {
async function search(terms) {
const searchResponse = await (await fetch(`https://www.musixmatch.com/search/?query=${encodeURIComponent(terms)}`)).text();
const buildId = searchResponse.match(/"buildId":"([^"]+)"/);
const query = searchResponse.match(/"query":"([^"]+)"/);
const trackResponse = await (await fetch(`https://www.musixmatch.com/_next/data/${buildId[1]}/en/search.json?query${encodeURIComponent(query[1])}`)).json();
return trackResponse.pageProps.data.comSearchBrowseGet.data.mxmComSearchBrowse;
}
Musixmatch.search = search;
async function getLyricsFromUrl(url) {
const trackResponse = await (await fetch(url)).text();
const lyricsMatch = trackResponse.match(/"body":"([^"]+)"/);
if (!lyricsMatch)
throw new Error("Not found lyrics");
return lyricsMatch[1].split("\\n");
}
Musixmatch.getLyricsFromUrl = getLyricsFromUrl;
async function searchLyrics(terms) {
throw new Error("Comming soon...");
const searchResponse = await (await fetch(`https://www.musixmatch.com/search?query=${encodeURIComponent(terms)}`)).text();
const buildId = searchResponse.match(/"buildId":"([^"]+)"/);
const query = searchResponse.match(/"query":"([^"]+)"/);
const trackResponse = await (await fetch(`https://www.musixmatch.com/_next/data/${buildId[1]}/en/lyrics/${encodeURIComponent(query[1])}.json`)).json();
return trackResponse.pageProps.data.trackInfo.data.lyrics.body;
}
Musixmatch.searchLyrics = searchLyrics;
})(Musixmatch || (Musixmatch = {}));