chore(lyrics): polish rebased TTML branch

This commit is contained in:
ranokay 2026-03-27 07:55:08 +02:00
parent 177e7089ee
commit 27255fb9ae
No known key found for this signature in database
3 changed files with 10 additions and 7 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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)