Series drill-down: mark downloading episodes and seasons
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+37
-19
@@ -8,8 +8,8 @@ import (
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/arr"
|
||||
)
|
||||
|
||||
// libQueueInterval is how often the Library asks for the download queues
|
||||
// while it is visible.
|
||||
// libQueueInterval is how often the Library (and a series' seasons and
|
||||
// episodes) ask for the download queues while they are visible.
|
||||
const libQueueInterval = 10 * time.Second
|
||||
|
||||
// dlInfo says that a library title is in the Radarr/Sonarr download queue.
|
||||
@@ -52,6 +52,38 @@ func queueByTitle(items []arr.QueueItem, series bool) map[int]dlInfo {
|
||||
return out
|
||||
}
|
||||
|
||||
// queueByEpisode picks the queue entries of one series, by episode.
|
||||
func queueByEpisode(items []arr.QueueItem, seriesID int) map[int]dlInfo {
|
||||
out := map[int]dlInfo{}
|
||||
for _, q := range items {
|
||||
if q.SeriesID != seriesID || q.EpisodeID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, seen := out[q.EpisodeID]; !seen {
|
||||
out[q.EpisodeID] = dlInfo{count: 1, progress: q.Progress(), timeLeft: q.TimeLeft}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// every runs f on the UI goroutine every d until stop is called.
|
||||
func (a *App) every(d time.Duration, f func()) (stop func()) {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
t := time.NewTicker(d)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-t.C:
|
||||
a.post(f)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return func() { close(done) }
|
||||
}
|
||||
|
||||
// loadQueue fetches both download queues and marks the titles in them.
|
||||
// Failures (a service down or not configured) leave the marks as they were.
|
||||
func (v *libraryView) loadQueue() {
|
||||
@@ -77,29 +109,15 @@ func (v *libraryView) loadQueue() {
|
||||
// startQueueWatch refreshes the queue marks while the Library is visible.
|
||||
func (v *libraryView) startQueueWatch() {
|
||||
v.loadQueue()
|
||||
if v.queueStop != nil {
|
||||
return
|
||||
if v.queueStop == nil {
|
||||
v.queueStop = v.app.every(libQueueInterval, v.loadQueue)
|
||||
}
|
||||
stop := make(chan struct{})
|
||||
v.queueStop = stop
|
||||
go func() {
|
||||
t := time.NewTicker(libQueueInterval)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
case <-t.C:
|
||||
v.app.post(v.loadQueue)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// deactivate stops the queue watch when the Library is left.
|
||||
func (v *libraryView) deactivate() {
|
||||
if v.queueStop != nil {
|
||||
close(v.queueStop)
|
||||
v.queueStop()
|
||||
v.queueStop = nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user