Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

46 lines
1.3 KiB
Go

package model
import (
"net/url"
"strings"
"github.com/bjarneo/cliamp/resolve"
tea "charm.land/bubbletea/v2"
)
const ytdlBatchSize = 100 // items per background batch
// resetYTDLBatch invalidates any in-progress batch loading session.
// Incrementing the generation ensures that stale in-flight responses
// are discarded by the handler, even if the same URL is reloaded.
func (m *Model) resetYTDLBatch() {
m.ytdlBatch.gen++
m.ytdlBatch.url = ""
m.ytdlBatch.offset = 0
m.ytdlBatch.done = false
m.ytdlBatch.loading = false
}
// initYTDLBatch detects a YouTube Radio URL among the given source URLs and
// kicks off incremental batch loading. The offset is derived from the known
// initial fetch size (resolve.YTDLRadioInitialItems) so it stays correct
// regardless of how many tracks other URLs contributed to the same load.
func (m *Model) initYTDLBatch(urls []string) tea.Cmd {
for _, u := range urls {
parsed, err := url.Parse(u)
if err != nil {
continue
}
if strings.HasPrefix(parsed.Query().Get("list"), "RD") {
m.ytdlBatch.gen++
m.ytdlBatch.url = u
m.ytdlBatch.offset = resolve.YTDLRadioInitialItems
m.ytdlBatch.done = false
m.ytdlBatch.loading = true
return fetchYTDLBatchCmd(m.ytdlBatch.gen, u, resolve.YTDLRadioInitialItems, ytdlBatchSize)
}
}
return nil
}