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(' ') 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){ function createLyricsPage(context, search, fields){
let em = createEmbed("default", context, { let em = createEmbed("default", context, {
author: { author: {
@ -30,10 +59,7 @@ function createLyricsPage(context, search, fields){
name: `${search.body.track.title} by ${search.body.track.artist}` name: `${search.body.track.title} by ${search.body.track.artist}`
}, },
fields: fields, fields: fields,
footer: { footer: renderLyricsFooter(context, search.body.lyrics_provider)
iconUrl: STATICS.musixmatch,
text: `Musixmatch • ${context.application.name}`
}
}) })
if(search.body.track.cover) em.thumbnail = { url: search.body.track.cover } 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) 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')){ for(const f of search.body.lyrics.split('\n\n')){
fields.push({ fields.push({
name: '', name: '',
value: f.substr(0,1024), value: f.substr(0,1024).replace(/\[(.*?)\]/g,"-# [$1]"),
inline: false inline: false
}) })
} }

View file

@ -23,6 +23,35 @@ function renderMetadata(metadata){
return pills.join(' ') 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){ function createLyricsPage(context, search, fields){
let em = createEmbed("default", context, { let em = createEmbed("default", context, {
author: { author: {
@ -30,10 +59,7 @@ function createLyricsPage(context, search, fields){
name: `${search.body.track.title} by ${search.body.track.artist}` name: `${search.body.track.title} by ${search.body.track.artist}`
}, },
fields: fields, fields: fields,
footer: { footer: renderLyricsFooter(context, search.body.lyrics_provider)
iconUrl: STATICS.musixmatch,
text: `Musixmatch • ${context.application.name}`
}
}) })
if(search.body.track.cover) em.thumbnail = { url: search.body.track.cover } 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) if(search.body.track.metadata.length) em.description = renderMetadata(search.body.track.metadata)
@ -65,7 +91,7 @@ module.exports = {
for(const f of search.body.lyrics.split('\n\n')){ for(const f of search.body.lyrics.split('\n\n')){
fields.push({ fields.push({
name: '', name: '',
value: f, value: f.substr(0,1024).replace(/\[(.*?)\]/g,"-# [$1]"),
inline: false inline: false
}) })
} }
@ -89,7 +115,7 @@ module.exports = {
}); });
}catch(e){ }catch(e){
if(e.response?.body?.status && e.response.body.status == 2 && e.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message)) if(e.response?.body?.status && e.response.body.status == 2 && e.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
console.log(JSON.stringify(e.raw)) console.log(JSON.stringify(e.raw) || e)
return editOrReply(context, createEmbed("error", context, `Something went wrong.`)) return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
} }
}, },

View file

@ -33,7 +33,7 @@ const Api = Object.freeze({
SEARCH_BING_IMAGES: '/search/bing-images', SEARCH_BING_IMAGES: '/search/bing-images',
SEARCH_GOOGLE: '/search/google', SEARCH_GOOGLE: '/search/google',
SEARCH_GOOGLE_IMAGES: '/search/google-images', SEARCH_GOOGLE_IMAGES: '/search/google-images',
SEARCH_LYRICS: '/search/lyrics-v2', SEARCH_LYRICS: '/search/lyrics',
SEARCH_QUORA: '/search/quora', SEARCH_QUORA: '/search/quora',
SEARCH_QUORA_RESULT: '/search/quora-result', SEARCH_QUORA_RESULT: '/search/quora-result',
SEARCH_REDDIT: '/search/reddit', SEARCH_REDDIT: '/search/reddit',