Add the calendar view (M10)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/arr"
|
||||
)
|
||||
@@ -56,6 +57,9 @@ type Movie struct {
|
||||
Monitored bool `json:"monitored"`
|
||||
HasFile bool `json:"hasFile"`
|
||||
QualityProfileID int `json:"qualityProfileId"`
|
||||
InCinemas string `json:"inCinemas,omitempty"` // ISO timestamps, empty if unknown
|
||||
PhysicalRelease string `json:"physicalRelease,omitempty"`
|
||||
DigitalRelease string `json:"digitalRelease,omitempty"`
|
||||
SizeOnDisk int64 `json:"sizeOnDisk"`
|
||||
IsAvailable bool `json:"isAvailable"`
|
||||
Path string `json:"path,omitempty"`
|
||||
@@ -181,3 +185,17 @@ func (c *Client) DeleteMovie(ctx context.Context, id int, deleteFiles, addExclus
|
||||
}
|
||||
return c.Do(ctx, http.MethodDelete, "movie/"+strconv.Itoa(id), q, nil, nil)
|
||||
}
|
||||
|
||||
// Calendar lists the library movies with a release date (cinemas, digital or
|
||||
// physical) between start and end, both inclusive. Unmonitored movies are
|
||||
// only included when asked for.
|
||||
func (c *Client) Calendar(ctx context.Context, start, end time.Time, unmonitored bool) ([]Movie, error) {
|
||||
q := url.Values{
|
||||
"start": {start.Format("2006-01-02")},
|
||||
"end": {end.Format("2006-01-02")},
|
||||
"unmonitored": {strconv.FormatBool(unmonitored)},
|
||||
}
|
||||
var movies []Movie
|
||||
err := c.Do(ctx, http.MethodGet, "calendar", q, nil, &movies)
|
||||
return movies, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/arr"
|
||||
)
|
||||
@@ -176,3 +177,21 @@ func TestDeleteMovie(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalendar(t *testing.T) {
|
||||
c := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
if r.URL.Path != "/api/v3/calendar" || q.Get("start") != "2026-10-20" || q.Get("end") != "2026-11-02" || q.Get("unmonitored") != "true" {
|
||||
t.Errorf("unexpected request %s", r.URL)
|
||||
}
|
||||
w.Write([]byte(`[{"id":4,"title":"Dune","year":2021,"monitored":true,"hasFile":false,"inCinemas":"2026-10-22T00:00:00Z","digitalRelease":"2026-11-01T00:00:00Z"}]`))
|
||||
})
|
||||
start := time.Date(2026, 10, 20, 0, 0, 0, 0, time.UTC)
|
||||
movies, err := c.Calendar(context.Background(), start, start.AddDate(0, 0, 13), true)
|
||||
if err != nil || len(movies) != 1 {
|
||||
t.Fatalf("movies=%v err=%v", movies, err)
|
||||
}
|
||||
if m := movies[0]; m.InCinemas != "2026-10-22T00:00:00Z" || m.DigitalRelease == "" || m.PhysicalRelease != "" {
|
||||
t.Errorf("dates not decoded: %+v", m)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user