Skip to content

Commit

Permalink
Add: navidrome Lyric
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerf committed Dec 3, 2024
1 parent f34cda7 commit 2194f36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions app/components/player/FullScreenPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ const FullScreenPlayer = ({ fullscreen, time }) => {
return `${String((second - second % 60) / 60).padStart(2, '0')}:${String((second - second % 1) % 60).padStart(2, '0')}`
}

const getLyrics = async () => {
if (isPreview == preview.LYRICS) return setIsPreview(preview.COVER)
if (lyrics.length > 0) setIsPreview(preview.LYRICS)

const getNavidromeLyrics = () => {
getApi(config, 'getLyricsBySongId', { id: song.songInfo.id })
.then(res => {
const ly = res.lyricsList?.structuredLyrics[0]?.line?.map(ly => ({ time: ly.start / 1000, text: ly.value.length ? ly.value : '...' }))
if (ly.length == 0) { // not found
return getLrcLibLyrics()
}
ly.sort((a, b) => a.time - b.time)
setLyrics(ly)
setIsPreview(preview.LYRICS)
})
.catch(() => { // not found
getLrcLibLyrics()
})
}

const getLrcLibLyrics = () => {
const params = {
track_name: song.songInfo.title,
artist_name: song.songInfo.artist,
Expand All @@ -62,6 +77,12 @@ const FullScreenPlayer = ({ fullscreen, time }) => {
})
}

const getLyrics = async () => {
if (isPreview == preview.LYRICS) return setIsPreview(preview.COVER)
if (lyrics.length > 0) return setIsPreview(preview.LYRICS)
getNavidromeLyrics()
}

return (
<Modal>
<View
Expand Down
2 changes: 1 addition & 1 deletion app/services/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ registerRoute(

registerRoute(
({ url }) => {
return url.hostname === "lrclib.net"
return url.hostname === "lrclib.net" || url.pathname.match(/\/rest\/getLyricsBySongId$/)
},
new NetworkFirst({
cacheName: "lyrics",
Expand Down

0 comments on commit 2194f36

Please sign in to comment.