{{ $collapseAfter := .Options.IntOr "collapse-after" 5 }} {{ $showGrabbed := .Options.BoolOr "show-grabbed" false }} {{ $sortTime := .Options.StringOr "sort-time" "desc" }} {{ $coverProxy := .Options.StringOr "cover-proxy" "" }} {{ $size := .Options.StringOr "size" "medium" }} {{ $service := .Options.StringOr "service" "" }} {{ $type := .Options.StringOr "type" "" }} {{ $intervalH := .Options.IntOr "interval" 0 | mul 24 }} {{ $now := now | formatTime "2006-01-02T15:04:05" }} {{ $posInterval := (offsetNow (printf "+%dh" $intervalH)) | formatTime "2006-01-02T15:04:05" }} {{ $negInterval := (offsetNow (printf "-%dh" $intervalH)) | formatTime "2006-01-02T15:04:05" }} {{ $apiBaseUrl := .Options.StringOr "api-base-url" "" }} {{ $key := .Options.StringOr "key" "" }} {{ $url := .Options.StringOr "url" $apiBaseUrl }} {{ if or (and (ne $service "sonarr") (ne $service "radarr") (ne $service "lidarr")) (and (ne $type "upcoming") (ne $type "recent") (ne $type "missing")) (eq $apiBaseUrl "") (eq $key "") (eq $url "") }}
ERROR

Some options are not set or malformed
service{{ $service }}must be sonarr, radarr, or lidarr
type{{ $type }}must be upcoming, recent, or missing
api-base-url{{ $apiBaseUrl }}should include http(s):// and port if needed
key{{ $key }}

{{ else }} {{ $requestUrl := "" }} {{ if eq $service "sonarr" }} {{ if eq $type "recent" }} {{ $requestUrl = printf "%s/api/v3/history/since?includeSeries=true&includeEpisode=true&eventType=grabbed&date=%s" $apiBaseUrl $negInterval }} {{ else if eq $type "missing" }} {{ $requestUrl = printf "%s/api/v3/wanted/missing?page=1&pageSize=50&includeSeries=true" $apiBaseUrl }} {{ else if eq $type "upcoming" }} {{ $requestUrl = printf "%s/api/v3/calendar?includeSeries=true&start=%s&end=%s" $apiBaseUrl $now $posInterval }} {{ end }} {{ else if eq $service "radarr" }} {{ if eq $type "recent" }} {{ $requestUrl = printf "%s/api/v3/history/since?includeMovie=true&eventType=grabbed&date=%s" $apiBaseUrl $negInterval }} {{ else if eq $type "missing" }} {{ $requestUrl = printf "%s/api/v3/wanted/missing?page=1&pageSize=50" $apiBaseUrl }} {{ else if eq $type "upcoming" }} {{ $requestUrl = printf "%s/api/v3/calendar?start=%s&end=%s" $apiBaseUrl $now $posInterval }} {{ end }} {{ else if eq $service "lidarr" }} {{ if eq $type "recent" }} {{ $requestUrl = printf "%s/api/v1/history/since?includeArtist=true&includeAlbum=true&eventType=grabbed&date=%s" $apiBaseUrl $negInterval }} {{ else if eq $type "missing" }} {{ $requestUrl = printf "%s/api/v1/wanted/missing?page=1&pageSize=50&includeArtist=true" $apiBaseUrl }} {{ else if eq $type "upcoming" }} {{ $requestUrl = printf "%s/api/v1/calendar?includeArtist=true&start=%s&end=%s" $apiBaseUrl $now $posInterval }} {{ end }} {{ end }} {{ $data := newRequest $requestUrl | withHeader "Accept" "application/json" | withHeader "X-Api-Key" $key | getResponse }} {{ end }}