{{/* Required config options */}} {{ $baseURL := .Options.StringOr "base-url" "" }} {{ $apiKey := .Options.StringOr "api-key" "" }} {{ $userName := .Options.StringOr "user-name" "" }} {{/* Required config options for "latest" mode */}} {{ $libraryName := .Options.StringOr "library-name" "" }} {{/* Optional config options */}} {{ $mode := .Options.StringOr "mode" "latest" }} {{ $itemCount := .Options.StringOr "item-count" "10" }} {{ $mediaTypes := .Options.StringOr "media-types" "Movie,Episode,MusicAlbum" }} {{ $thumbAspectRatio := .Options.StringOr "thumbnail-aspect-ratio" "" }} {{ $isSmallColumn:= .Options.BoolOr "small-column" false }} {{ $showThumbnail := .Options.BoolOr "show-thumbnail" false }} {{ $showProgressBar := .Options.BoolOr "progress-bar" true }} {{/* Error message template */}} {{ define "errorMsg" }}
{{ . }}
{{ end }} {{/* Check required fields */}} {{ if or (eq $baseURL "") (eq $apiKey "") (eq $userName "") (eq $mode "") (and (eq $mode "latest") (eq $libraryName "")) }} {{ template "errorMsg" "Some required options are not set." }} {{ else }} {{/* Fetch user ID */}} {{ $userID := "" }} {{ $usersCall := newRequest (print $baseURL "/Users") | withParameter "api_key" $apiKey | withHeader "Accept" "application/json" | getResponse }} {{ range $i, $user := $usersCall.JSON.Array "" }} {{ if eq ($user.String "Name") $userName }} {{ $userID = $user.String "Id" }} {{ break }} {{ end }} {{ end }} {{ if eq $userID "" }} {{ template "errorMsg" (printf "User '%s' not found." $userName) }} {{ else }} {{ $items := "" }} {{ if eq $mode "latest" }} {{/* Fetch library ID */}} {{ $libraryID := "" }} {{ $userViewsCall := newRequest (print $baseURL "/UserViews") | withParameter "api_key" $apiKey | withParameter "userId" $userID | withHeader "Accept" "application/json" | getResponse }} {{ range $i, $item := $userViewsCall.JSON.Array "Items" }} {{ if eq ($item.String "Name") $libraryName }} {{ $libraryID = $item.String "Id" }} {{ break }} {{ end }} {{ end }} {{ if eq $libraryID "" }} {{ template "errorMsg" (printf "Library '%s' not found." $libraryName) }} {{ else }} {{/* Fetch latest items */}} {{ $latestCall := newRequest (print $baseURL "/Users/" $userID "/Items/Latest") | withParameter "api_key" $apiKey | withParameter "Limit" $itemCount | withParameter "ParentId" $libraryID | withParameter "IncludeItemTypes" $mediaTypes | withParameter "GroupItems" "true" | withHeader "Accept" "application/json" | getResponse }} {{ $items = $latestCall.JSON.Array "" }} {{ end }} {{ else if eq $mode "nextup" }} {{/* Fetch next up items */}} {{ $nextUpCall := newRequest (print $baseURL "/Shows/NextUp") | withParameter "api_key" $apiKey | withParameter "UserId" $userID | withParameter "Limit" $itemCount | withParameter "EnableResumable" "true" | withHeader "Accept" "application/json" | getResponse }} {{ $items = $nextUpCall.JSON.Array "Items" }} {{ else }} {{ template "errorMsg" "Unknown mode, expected 'latest' or 'nextup'" }} {{ end }} {{ if eq (len $items) 0 }}No items found, start streaming something!
{{ else }} {{/* Display the item carousel */}}