|
| 1 | +## Description |
| 2 | + |
| 3 | +This widget fetches upcoming movies, TV shows or video games from an instance of [MediaTracker](https://github.com/bonukai/MediaTracker) and shows them as cards in horizontal carousel. Each card contains a poster, an episode number (for a TV show), an episode name (for a TV show), a name (of a TV show, movie or a video game) and its release date. |
| 4 | + |
| 5 | +TV Shows: |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +Movies: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +Video Games: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +No upcoming media: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +The widget requires modifications to the configuration file in order to work. Under the `options` field in the yaml configuration file, one needs to supply MediaTracker URL, API key and some other options. One can either supply them directly or as environment variables. |
| 23 | + |
| 24 | +## List of Options |
| 25 | + |
| 26 | +- (required) `base-url` requires URL pointing to your MediaTracker, be sure to include "http://" or "https://" |
| 27 | +- (required) `api-key` requires MediaTracker API key that can be retrieved in MediaTracker under "ACCOUNTNAME -> Application tokens -> Add Token" |
| 28 | +- (optional) `media-type` requires "tv", "movie" or "video_game". The default value is "tv". |
| 29 | +- (optional) `only-on-watchlist` can be either "true" or "false". Determines whether only media items from the watchlist are fetched. The default value is "false". |
| 30 | +- (optional) `items` value limits number of cards. The default value is 10. |
| 31 | + |
| 32 | +## Widget Configuration YAML |
| 33 | +```yaml |
| 34 | +- type: custom-api |
| 35 | + title: Upcoming # change to your liking |
| 36 | + frameless: true |
| 37 | + cache: 1h |
| 38 | + options: |
| 39 | + base-url: ${MEDIATRACKER_URL} # URL pointing to your MediaTracker |
| 40 | + api-key: ${MEDIATRACKER_API_KEY} # can be retrieved in Account Name -> Application tokens |
| 41 | + media-type: tv # tv, movie or video_game |
| 42 | + only-on-watchlist: "false" # "true" or "false" |
| 43 | + items: 10 # integer number |
| 44 | + template: | |
| 45 | + {{ $baseURL := .Options.StringOr "base-url" "" }} |
| 46 | + {{ $apiKey := .Options.StringOr "api-key" "" }} |
| 47 | + {{ $mediaType := .Options.StringOr "media-type" "tv" }} |
| 48 | + {{ $onlyOnWatchlist := .Options.StringOr "only-on-watchlist" "false" }} |
| 49 | + {{ $numberOfItems := .Options.IntOr "items" 10 }} |
| 50 | + {{ $orderBy := "releaseDate" }} |
| 51 | + {{ $sortOrder := "asc" }} |
| 52 | + {{ $videoGameReleaseDate := "TBA" }} |
| 53 | + |
| 54 | + {{ if or (eq $baseURL "") (eq $apiKey "") }} |
| 55 | + <div class="widget-content-frame" style="flex=0 0 25vh; display:flex"> |
| 56 | + <div class="grow padding-inline-widget margin-top-10 margin-bottom-10 color-negative"> |
| 57 | + MediaTracker base-url or API token not set. |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + {{ else }} |
| 61 | + {{ if eq $mediaType "tv" }} |
| 62 | + {{ $orderBy = "nextAiring" }} |
| 63 | + {{ end }} |
| 64 | + {{ $requestURL := concat $baseURL "/api/items?mediaType=" $mediaType "&orderBy=" $orderBy "&sortOrder=" $sortOrder "&onlyOnWatchlist" $onlyOnWatchlist "&token=" $apiKey}} |
| 65 | + {{ if or (eq $mediaType "video_game") (eq $mediaType "movie") }} |
| 66 | + {{ $requestURL = concat $requestURL "&onlyWithNextAiring=true" }} |
| 67 | + {{ end }} |
| 68 | + |
| 69 | + {{ $items := newRequest $requestURL | getResponse }} |
| 70 | + {{ if eq $items.Response.StatusCode 200 }} |
| 71 | + {{ $arr := $items.JSON.Array "" }} |
| 72 | + {{ $len := len $arr }} |
| 73 | + {{ $shown := 0 }} |
| 74 | + |
| 75 | + {{ if gt (len $arr) 0 }} |
| 76 | + <div class="cards-horizontal carousel-items-container"> |
| 77 | + {{ range $i, $_ := $arr }} |
| 78 | + {{ if and (.Exists "nextAiring") (ne (.String "nextAiring") "") (lt $shown $numberOfItems) }} |
| 79 | + {{ $el := index $arr $i }} |
| 80 | + |
| 81 | + <a class="card widget-content-frame" |
| 82 | + href="{{ $baseURL }}/#/details/{{ $el.Int "id" }}" |
| 83 | + style=" |
| 84 | + flex: 0 0 25vh; |
| 85 | + min-width: 170px; |
| 86 | + min-heght: 150px; |
| 87 | + display:flex; |
| 88 | + flex-direction:column; |
| 89 | + box-sizing:border-box; |
| 90 | + text-decoration:none; |
| 91 | + color:inherit;" |
| 92 | + > |
| 93 | + <div style="position: relative;"> |
| 94 | + {{ if and ($el.Exists "posterSmall") (ne ($el.String "posterSmall") "") }} |
| 95 | + <img src="{{ $baseURL }}{{ $el.String "posterSmall" }}&token={{ $apiKey }}" |
| 96 | + alt="{{ $el.String "title" }}" |
| 97 | + loading="lazy" |
| 98 | + class="media-server-thumbnail shrink-0 loaded finished-transition" |
| 99 | + style=" |
| 100 | + width:100%; |
| 101 | + display:block; |
| 102 | + border-radius:var(--border-radius) var(--border-radius) 0 0; |
| 103 | + object-fit:cover;" |
| 104 | + /> |
| 105 | + {{ else }} |
| 106 | + <div style="width:100%; background:#222; display:flex; align-items:center; justify-content:center; color:#ddd; aspect-ratio:2/3;"> |
| 107 | + No image |
| 108 | + </div> |
| 109 | + {{ end }} |
| 110 | + </div> |
| 111 | + <div class="grow padding-inline-widget margin-top-10 margin-bottom-10"> |
| 112 | + <ul class="flex flex-column justify-evenly margin-bottom-3" style="height:100%; gap: 4px;"> |
| 113 | + {{ if eq $mediaType "tv" }} |
| 114 | + <ul class="list-horizontal-text flex-nowrap" style="padding:0; margin:0;"> |
| 115 | + <li class="color-primary shrink-0"> S{{ printf "%02d" ($el.Int "upcomingEpisode.seasonNumber") }}E{{ printf "%02d" ($el.Int "upcomingEpisode.episodeNumber") }}</li> |
| 116 | + <li class="text-truncate">{{ $el.String "upcomingEpisode.title" }}</li> |
| 117 | + </ul> |
| 118 | + {{ end }} |
| 119 | + <li class="text-truncate color-primary" style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" title="{{ $el.String "title" }}"> |
| 120 | + {{ $el.String "title" }} |
| 121 | + </li> |
| 122 | + {{ if eq $mediaType "video_game" }} |
| 123 | + <li style="font-size:0.85em; opacity:0.7; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"> |
| 124 | + {{ $videoGameReleaseDate = $el.String "releaseDate" | parseTime "RFC3339" }} |
| 125 | + {{ if eq ($videoGameReleaseDate | formatTime "02-01") "31-12" }} |
| 126 | + {{ $videoGameReleaseDate | formatTime "2006" }} |
| 127 | + {{ else }} |
| 128 | + {{ $videoGameReleaseDate | formatTime "Jan 02, 2006" }} |
| 129 | + {{ end }} |
| 130 | + </li> |
| 131 | + {{ else}} |
| 132 | + <li style="font-size:0.85em; opacity:0.7; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"> |
| 133 | + {{ $el.String "nextAiring" | parseTime "2006-01-02" | formatTime "Jan 02, 2006" }} |
| 134 | + </li> |
| 135 | + {{ end }} |
| 136 | + </ul> |
| 137 | + </div> |
| 138 | + </a> |
| 139 | + {{ $shown = add $shown 1 }} |
| 140 | + {{ end }} |
| 141 | + {{ end }} |
| 142 | + </div> |
| 143 | + {{ else }} |
| 144 | + <div class="widget-content-frame" style="flex=0 0 25vh; display:flex"> |
| 145 | + <div class="grow padding-inline-widget margin-top-10 margin-bottom-10"> |
| 146 | + No upcoming entries on the watchlist. |
| 147 | + </div> |
| 148 | + </div> |
| 149 | + {{ end }} |
| 150 | + {{ else }} |
| 151 | + <div class="widget-content-frame" style="flex=0 0 25vh; display:flex"> |
| 152 | + <div class="grow padding-inline-widget margin-top-10 margin-bottom-10"> |
| 153 | + Failed to fetch items (status {{ $items.Response.StatusCode }}) |
| 154 | + </div> |
| 155 | + </div> |
| 156 | + {{ end }} |
| 157 | + {{ end }} |
| 158 | +``` |
| 159 | +
|
0 commit comments