update to omnilyrics

This commit is contained in:
bignutty 2024-09-08 22:46:53 +02:00
parent 197e776f03
commit 5c13db8f62
3 changed files with 64 additions and 12 deletions

View file

@ -23,6 +23,35 @@ function renderMetadata(metadata){
return pills.join(' ')
}
// These have to be synced with the backend (search_service/endpoints/lyrics).
const LYRIC_PROVIDERS = {
UNKNOWN_PROVIDER: 0,
MUSIXMATCH: 1,
GENIUS: 2
}
function renderLyricsFooter(context, provider){
switch(provider){
case LYRIC_PROVIDERS.MUSIXMATCH:
return {
text: `Musixmatch • ${context.application.name}`,
iconUrl: STATICS.musixmatch
}
break;
case LYRIC_PROVIDERS.GENIUS:
return {
text: `Genius • ${context.application.name}`,
iconUrl: STATICS.genius
}
break;
default: // Fallback, this should never happen
return {
text: context.application.name,
iconUrl: STATICS.labscore
}
}
}
function createLyricsPage(context, search, fields){
let em = createEmbed("default", context, {
author: {
@ -30,10 +59,7 @@ function createLyricsPage(context, search, fields){
name: `${search.body.track.title} by ${search.body.track.artist}`
},
fields: fields,
footer: {
iconUrl: STATICS.musixmatch,
text: `Musixmatch • ${context.application.name}`
}
footer: renderLyricsFooter(context, search.body.lyrics_provider)
})
if(search.body.track.cover) em.thumbnail = { url: search.body.track.cover }
if(search.body.track.metadata.length) em.description = renderMetadata(search.body.track.metadata)
@ -79,7 +105,7 @@ module.exports = {
for(const f of search.body.lyrics.split('\n\n')){
fields.push({
name: '',
value: f.substr(0,1024),
value: f.substr(0,1024).replace(/\[(.*?)\]/g,"-# [$1]"),
inline: false
})
}