Lyrics implementation prototype (#224)
* Lyrics implementation prototype * feat: update lyrics view * chore: add docs * chore: cleanup * feat: animate active text * fix: hide lyrics button when there are none * feat: create lyrics preview in now playing modal * fix: header overlay color Closes #224 Closes #151 Closes #100 --------- Co-authored-by: Lei Nelissen <lei@codified.nl>
This commit is contained in:
committed by
GitHub
parent
a64f52c4f9
commit
c5b1406e16
48
src/utility/JellyfinApi/lyrics.ts
Normal file
48
src/utility/JellyfinApi/lyrics.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { fetchApi } from './lib';
|
||||
import {AlbumTrack} from '@/store/music/types.ts';
|
||||
|
||||
interface Metadata {
|
||||
Artist: string
|
||||
Album: string
|
||||
Title: string
|
||||
Author: string
|
||||
Length: number
|
||||
By: string
|
||||
Offset: number
|
||||
Creator: string
|
||||
Version: string
|
||||
IsSynced: boolean
|
||||
}
|
||||
|
||||
interface LyricData {
|
||||
Text: string
|
||||
Start: number
|
||||
}
|
||||
|
||||
export interface Lyrics {
|
||||
Metadata: Metadata
|
||||
Lyrics: LyricData[]
|
||||
}
|
||||
|
||||
async function retrieveTrackLyrics(trackId: string): Promise<Lyrics | null> {
|
||||
return fetchApi<Lyrics>(`/Audio/${trackId}/Lyrics`)
|
||||
.catch((e) => {
|
||||
console.error('Error on fetching track lyrics: ', e);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export async function retrieveAndInjectLyricsToTracks(tracks: AlbumTrack[]): Promise<AlbumTrack[]> {
|
||||
return Promise.all(tracks.map(async (track) => {
|
||||
if (!track.HasLyrics) {
|
||||
track.Lyrics = null;
|
||||
return track;
|
||||
}
|
||||
|
||||
track.Lyrics = await retrieveTrackLyrics(track.Id);
|
||||
|
||||
return track;
|
||||
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user