mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
chore(lyrics): polish rebased TTML branch
This commit is contained in:
parent
177e7089ee
commit
27255fb9ae
@ -814,9 +814,9 @@ func (p *ttmlParser) updateTimingParams(attrs []xml.Attr) {
|
||||
}
|
||||
}
|
||||
|
||||
p.params.frameRate = max(frameRate, defaultTTMLFrameRate)
|
||||
p.params.subFrameRate = max(subFrameRate, defaultTTMLSubFrameRate)
|
||||
p.params.tickRate = max(tickRate, defaultTTMLTickRate)
|
||||
p.params.frameRate = positiveOrDefault(frameRate, defaultTTMLFrameRate)
|
||||
p.params.subFrameRate = positiveOrDefault(subFrameRate, defaultTTMLSubFrameRate)
|
||||
p.params.tickRate = positiveOrDefault(tickRate, defaultTTMLTickRate)
|
||||
}
|
||||
|
||||
func parseTTMLDurationExpression(expr string, params ttmlTimingParams) (int64, bool) {
|
||||
@ -1102,7 +1102,7 @@ func hydrateLineTimingFromTokens(line model.Line) model.Line {
|
||||
return model.NormalizeLineTiming(line)
|
||||
}
|
||||
|
||||
func max(v float64, fallback float64) float64 {
|
||||
func positiveOrDefault(v float64, fallback float64) float64 {
|
||||
if v <= 0 {
|
||||
return fallback
|
||||
}
|
||||
|
||||
@ -99,6 +99,8 @@ func (api *Router) GetLyrics(r *http.Request) (*responses.Subsonic, error) {
|
||||
lyricsResponse := responses.Lyrics{}
|
||||
response.Lyrics = &lyricsResponse
|
||||
opts := filter.SongsByArtistTitleWithLyricsFirst(artist, title)
|
||||
// Keep the search exhaustive so an older duplicate can still supply the
|
||||
// matching sidecar lyrics when the newest candidate only has embedded data.
|
||||
opts.Max = 0
|
||||
mediaFiles, err := api.ds.MediaFile(r.Context()).GetAll(opts)
|
||||
|
||||
|
||||
@ -84,7 +84,9 @@ const normalizeToken = (token) => {
|
||||
|
||||
const buildAgentLookup = (structuredLyric) => {
|
||||
const lookup = new Map()
|
||||
const agents = Array.isArray(structuredLyric?.agents) ? structuredLyric.agents : []
|
||||
const agents = Array.isArray(structuredLyric?.agents)
|
||||
? structuredLyric.agents
|
||||
: []
|
||||
for (const agent of agents) {
|
||||
const id = typeof agent?.id === 'string' ? agent.id : ''
|
||||
if (!id || lookup.has(id)) {
|
||||
@ -112,8 +114,7 @@ const normalizeCueLine = (cueLine, fallbackIndex, agentLookup) => {
|
||||
: fallbackIndex
|
||||
const agentId = typeof cueLine?.agentId === 'string' ? cueLine.agentId : ''
|
||||
const agent = agentId ? agentLookup.get(agentId) || null : null
|
||||
const fallbackRole =
|
||||
typeof cueLine?.role === 'string' ? cueLine.role : ''
|
||||
const fallbackRole = typeof cueLine?.role === 'string' ? cueLine.role : ''
|
||||
const tokens = sortTokensByStart(
|
||||
Array.isArray(cueLine?.cue)
|
||||
? cueLine.cue.map(normalizeToken).filter(Boolean)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user