Skip to content

Commit 893fbe1

Browse files
authored
Merge pull request #202 from sqcrtx/mediatracker-upcoming
MediaTracker widget and some minor changes for "Komga Recently Added Series" widget
2 parents b36a399 + 4306258 commit 893fbe1

File tree

7 files changed

+209
-36
lines changed

7 files changed

+209
-36
lines changed

widgets/komga-latest/README.md

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Description
22

3-
This widgets displays covers of recently added/updated series of a Komga library as horizontally scrolling items (cards):
3+
This widget displays recently added/updated series of a Komga library as cards in horizontal carousel:
44

55
![Preview of the widget](preview.png)
66

7-
The widget requires modifications to the configuration file in order to work. Under the `options` field in the yaml configurations file, one needs to supply Komga URL, API key and a library ID of a relevant library. You can either supply them directly or as environment variables.
7+
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 Komga URL, API key and a library ID of a relevant library. One can either supply them directly or as environment variables.
88

99
## List of Options
1010

@@ -31,7 +31,7 @@ The widget requires modifications to the configuration file in order to work. Un
3131
{{ $apiKey := .Options.StringOr "api-key" "" }}
3232
{{ $libraryId := .Options.StringOr "library-id" "" }}
3333
{{ $numberOfItems := .Options.IntOr "items" 10 }}
34-
{{ $mode := .Options.mode "library-id" "new" }}
34+
{{ $mode := .Options.StringOr "mode" "new" }}
3535
3636
{{
3737
$auth := newRequest (concat $baseURL "/api/v1/login")
@@ -48,44 +48,55 @@ The widget requires modifications to the configuration file in order to work. Un
4848
{{ $session := $auth.Response.Header.Get "Set-Cookie" }}
4949
5050
{{ if or (eq $baseURL "") (eq $apiKey "") }}
51-
<p class="color-negative">Komga base-url or/and api-key is/are not set.</p>
51+
<div class="widget-content-frame" style="flex=0 0 25vh; display:flex">
52+
<div class="grow padding-inline-widget margin-top-10 margin-bottom-10 color-negative">
53+
Komga base-url or API token not set.
54+
</div>
55+
</div>
5256
{{ else }}
53-
<div class="cards-horizontal carousel-items-container">
54-
{{ $arr := $content.JSON.Array "content" }}
55-
{{ $len := len $arr }}
56-
{{ $shown := 0 }}
57-
58-
{{ range $i, $_ := $arr }}
59-
{{ if lt $shown $numberOfItems }}
60-
{{ $el := index $arr $i }}
57+
{{ if eq $content.Response.StatusCode 200 }}
58+
<div class="cards-horizontal carousel-items-container">
59+
{{ $arr := $content.JSON.Array "content" }}
60+
{{ $len := len $arr }}
61+
{{ $shown := 0 }}
6162
62-
<a class="card widget-content-frame"
63-
href="{{ $baseURL }}/series/{{ $el.String "id" }}"
64-
style="flex:0 0 25vh;min-width:170px; min-height: 150px; display:flex;flex-direction:column;box-sizing:border-box;text-decoration:none;color:inherit;">
65-
<div style="position: relative;">
66-
<img src="{{ $baseURL }}/api/v1/series/{{ $el.String "id" }}/thumbnail"
67-
alt="{{ $el.String "metadata.title" }}"
68-
loading="lazy"
69-
class="media-server-thumbnail shrink-0 loaded finished-transition"
70-
style="width:100%; height: 37vh; min-height: 250px; display:block;border-radius:var(--border-radius) var(--border-radius) 0 0;object-fit:cover;"
71-
/>
72-
</div>
63+
{{ range $i, $_ := $arr }}
64+
{{ if lt $shown $numberOfItems }}
65+
{{ $el := index $arr $i }}
66+
67+
<a class="card widget-content-frame"
68+
href="{{ $baseURL }}/series/{{ $el.String "id" }}"
69+
style="flex:0 0 25vh;min-width:170px; min-height: 150px; display:flex;flex-direction:column;box-sizing:border-box;text-decoration:none;color:inherit;">
70+
<div style="position: relative;">
71+
<img src="{{ $baseURL }}/api/v1/series/{{ $el.String "id" }}/thumbnail"
72+
alt="{{ $el.String "metadata.title" }}"
73+
loading="lazy"
74+
class="media-server-thumbnail shrink-0 loaded finished-transition"
75+
style="width:100%; height: 37vh; min-height: 250px; display:block;border-radius:var(--border-radius) var(--border-radius) 0 0;object-fit:cover;"
76+
/>
77+
</div>
78+
<div class="grow padding-inline-widget margin-top-10 margin-bottom-10">
79+
<ul class="flex flex-column justify-evenly margin-bottom-3" style="height:100%; gap:4px;">
80+
<li class="text-truncate color-primary" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="{{ $el.String "title" }}">
81+
{{ $el.String "metadata.title" }} <!-- ({{ $el.String "metadata.releaseDate" | parseTime "2006-01-02" | formatTime "2006" }}) -->
82+
</li>
83+
<li style="font-size:0.85em;opacity:0.7;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
84+
Added: {{ $el.String "created" | parseTime "RFC3339" | formatTime "Jan 2, 2006" }}
85+
</li>
86+
</ul>
87+
</div>
88+
</a>
89+
{{ $shown = add $shown 1 }}
90+
{{ end }}
91+
{{ end }}
92+
</div>
93+
{{ else }}
94+
<div class="widget-content-frame" style="flex=0 0 25vh; display:flex">
7395
<div class="grow padding-inline-widget margin-top-10 margin-bottom-10">
74-
<ul class="flex flex-column justify-evenly margin-bottom-3" style="height:100%; gap:4px;">
75-
<li class="text-truncate color-primary" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="{{ $el.String "title" }}">
76-
{{ $el.String "metadata.title" }} <!-- ({{ $el.String "metadata.releaseDate" | parseTime "2006-01-02" | formatTime "2006" }}) -->
77-
</li>
78-
<li style="font-size:0.85em;opacity:0.7;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
79-
Added: {{ $el.String "created" | parseTime "RFC3339" | formatTime "Jan 2, 2006" }}
80-
</li>
81-
</ul>
96+
Failed to fetch items (status {{ $content.Response.StatusCode }})
8297
</div>
83-
</a>
84-
85-
{{ $shown = add $shown 1 }}
86-
{{ end }}
98+
</div>
8799
{{ end }}
88-
</div>
89100
{{ end }}
90101
```
91102
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
![Preview of the widget (TV Shows)](preview_tv.png)
8+
9+
Movies:
10+
11+
![Preview of the widget (Movies)](preview_movies.png)
12+
13+
Video Games:
14+
15+
![Preview of the widget (Video Games)](preview_video-games.png)
16+
17+
No upcoming media:
18+
19+
![Preview of the widget (Nothing fetched)](preview_no-cards.png)
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+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: MediaTracker Upcoming Media
2+
description: displays upcoming TV shows, movies or video games monitored by MediaTracker
3+
author: VictorMitr
199 KB
Loading
8.39 KB
Loading
795 KB
Loading
436 KB
Loading

0 commit comments

Comments
 (0)