CoolFace
Apppublic

Shadowfilebot/nodelink

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
genius.js58 linesDownload Raw Back to sources
1import { makeRequest } from '../utils.js'2 3async function search(query) {4  const { body: data } = await makeRequest(`https://genius.com/api/search/multi?q=${encodeURIComponent(query)}`, {5    method: 'GET'6  })7 8  if (data.response.sections[1].hits.length === 0) return null9 10  return data.response.sections[1].hits[0].result.path11}12 13async function loadLyrics(decodedTrack, language) {14  const searchResult = await search(`${decodedTrack.title} ${decodedTrack.author}`)15 16  if (!searchResult) return null17 18  const { body: data } = await makeRequest(`https://genius.com${searchResult}`, {19    method: 'GET'20  })21 22  const trackInfo = JSON.parse(data.match(/JSON.parse\('(.*)'\);/)[1].replace(/\\(.)/g, '$1'))23 24  const lyricsEvents = []25  trackInfo.songPage.lyricsData.body.children[0].children.forEach((text) => {26    if (typeof text === 'object') {27      if (!text.children) return;28 29      text.children.forEach((child) => {30        if (typeof child !== 'string') return;31 32        lyricsEvents.push({33          text: child34        })35      })36 37      return;38    }39 40    lyricsEvents.push({41      text42    })43  })44 45  return {46    loadType: 'lyricsSingle',47    data: {48      name: 'original',49      synced: false,50      data: lyricsEvents,51      rtl: false52    }53  }54}55 56export default {57  loadLyrics58}