amuse.git

commit b8c2b81f75b672bf5e3ec6cdc12ede1bdf5caacf

Author: Adam <git@apiote.tk>

blur spoilers

 libamuse/serie.go | 43 +++++++++++++++++++++++++++++++++++++++++++
 static/style/style.css | 15 +++++++++++++--
 templates/tvserie.html | 12 ++++++------
 tmdb/serie.go | 23 ++++++++++++-----------


diff --git a/libamuse/serie.go b/libamuse/serie.go
index a62aa17095a8ba37621264f4c95977140a381a5c..15c27c6a605df3f2d004f0dfa3f7a3bdd7b17f41 100644
--- a/libamuse/serie.go
+++ b/libamuse/serie.go
@@ -9,6 +9,7 @@
 	"fmt"
 	"sort"
 	"strings"
+	"time"
 
 	"notabug.org/apiote/gott"
 )
@@ -169,6 +170,47 @@
 	return gott.Tuple(args), err
 }
 
+func setSpoilers(args ...interface{}) interface{} {
+	result := args[1].(*Result)
+	tvSerie := result.result.(*tmdb.TvSerie)
+	nextEpisode := tvSerie.Next_episode_to_watch
+	nextCode := nextEpisode.Episode_code
+	if nextCode == "" {
+		if tvSerie.WatchedEpisodes > 0 {
+			nextCode = "S99E99"
+		} else {
+			nextCode = "S01E01"
+		}
+	}
+	nextDate := nextEpisode.Air_date
+	if nextDate.IsZero() {
+		if tvSerie.WatchedEpisodes > 0 {
+			nextDate = time.Now()
+		} else {
+			for _, season := range tvSerie.Seasons {
+				if season.Season_number == 1 && len(season.Episodes) > 0 {
+					nextDate = season.Episodes[0].Air_date
+				}
+			}
+		}
+	}
+	for s := 0; s < len(tvSerie.Seasons); s++ {
+		for e := 0; e < len(tvSerie.Seasons[s].Episodes); e++ {
+			episode := &(tvSerie.Seasons[s].Episodes[e])
+			if episode.Air_date.After(nextDate) ||
+				(episode.Air_date == nextDate && episode.Episode_code > nextCode) {
+				episode.ContainsSpoilers = true
+			}
+		}
+	}
+	episode := &(tvSerie.Last_episode_to_air)
+	if episode.Air_date.After(nextDate) ||
+		(episode.Air_date == nextDate && episode.Episode_code > nextCode) {
+		episode.ContainsSpoilers = true
+	}
+	return gott.Tuple(args)
+}
+
 func getEpisodesExperiences(args ...interface{}) (interface{}, error) {
 	result := args[1].(*Result)
 	tvSerie := result.result.(*tmdb.TvSerie)
@@ -204,6 +246,7 @@ 		Map(countAllEpisodes).
 		Bind(calculateProgress).
 		Bind(findNextEpisode).
 		Bind(getEpisodesExperiences).
+		Map(setSpoilers).
 		Bind(createRenderer).
 		Map(renderSerie).
 		Finish()




diff --git a/static/style/style.css b/static/style/style.css
index 901f02040a9d8386aaa77a1ae5b99c35a3e16700..ef997c6847b3e1837c78b9f468040b09f0b9659d 100644
--- a/static/style/style.css
+++ b/static/style/style.css
@@ -538,12 +538,23 @@ }
 
 /* FILTER */
 
+p.spoiler {
+	color: var(--bg);
+	border: 1px solid var(--text);
+	filter: none;
+}
+
+p.spoiler:hover {
+	color: var(--text);
+	border: 1px solid transparent;
+}
+
 .spoiler {
 	filter: blur(10px);
 }
 
-.spoler:hover {
-	filter: blur(0) !important;
+.spoiler:hover {
+	filter: blur(0px);
 }
 
 .bw {




diff --git a/templates/tvserie.html b/templates/tvserie.html
index 1320890f7a597b52de2e981d4e0f8d86eb7eddf0..ca91377501c3757e0ade214db4af805bd0f36744 100644
--- a/templates/tvserie.html
+++ b/templates/tvserie.html
@@ -106,16 +106,16 @@ 						{{.Strings.Serie.latest_episode}}
 						<div class="flex margin-tb-1">
 							<div class="margin-lr-1">
 								{{if .Data.Last_episode_to_air.Still_path}}
-								<img src="https://image.tmdb.org/t/p/w185{{.Data.Last_episode_to_air.Still_path}}" decoding="async" loading="lazy" class="width-185px"/>
+								<img src="https://image.tmdb.org/t/p/w185{{.Data.Last_episode_to_air.Still_path}}" decoding="async" loading="lazy" class="width-185px {{if .Data.Last_episode_to_air.ContainsSpoilers}}spoiler{{end}}"/>
 								{{else}}
 								<img src="/static/img/still_empty.webp" decoding="async" loading="lazy" class="width-185px"/> <!-- Photo by [Mahdi Leader](https://www.pexels.com/@mahdi-leader-415984) from [Pexels](https://www.pexels.com/photo/walpaper-firewatch-1090640) -->
 								{{end}}
 							</div>
 							<div>
 								<p class="sans text-grey margin-tb-0">{{.Data.Last_episode_to_air.Episode_code}}</p>
-								<p class="sans margin-bottom-_5 margin-top-0">{{.Data.Last_episode_to_air.Name}}</p>
+								<p class="sans margin-bottom-_5 margin-top-0 {{if .Data.Last_episode_to_air.ContainsSpoilers}}spoiler{{end}}">{{.Data.Last_episode_to_air.Name}}</p>
 								<p class="sans margin-tb-_5 text-grey">{{.Data.Last_episode_to_air.Air_date_str}}</p>
-								<p class="font-_875 clamp">{{.Data.Last_episode_to_air.Overview}}</p>
+								<p class="font-_875 clamp {{if .Data.Last_episode_to_air.ContainsSpoilers}}spoiler{{end}}">{{.Data.Last_episode_to_air.Overview}}</p>
 							</div>
 						</div>
 						{{end}}
@@ -204,7 +204,7 @@ 					{{range .Episodes}}
 					<div class="flex margin-tb-1">
 						<div class="margin-lr-1">
 							{{if .Still_path}}
-							<img src="https://image.tmdb.org/t/p/w185{{.Still_path}}" decoding="async" loading="lazy" class="width-185px"/>
+							<img src="https://image.tmdb.org/t/p/w185{{.Still_path}}" decoding="async" loading="lazy" class="width-185px {{if .ContainsSpoilers}}spoiler{{end}}"/>
 							{{else}}
 							<img src="/static/img/still_empty.webp" decoding="async" loading="lazy" class="width-185px"/> <!-- Photo by [Mahdi Leader](https://www.pexels.com/@mahdi-leader-415984) from [Pexels](https://www.pexels.com/photo/walpaper-firewatch-1090640) -->
 							{{end}}
@@ -213,7 +213,7 @@ 						
<div class="flex flex-row flex-justify-space flex-align-start"> <div> <p class="sans text-grey margin-tb-0">{{.Episode_code}}</p> - <p class="sans margin-bottom-_5 margin-top-0">{{.Name}}</p> + <p class="sans margin-bottom-_5 margin-top-0 {{if .ContainsSpoilers}}spoiler{{end}}">{{.Name}}</p> <p class="sans margin-tb-_5 text-grey">{{.Air_date_str}}</p> {{if .IsWatched}} <p class="sans margin-tb-_5 text-grey">{{$.Strings.Serie.watched}} {{.GetLastExperience $.Strings $.State.User.Timezone}}</p> @@ -252,7 +252,7 @@ {{end}} </div> </div> - <p class="font-_875">{{.Overview}}</p> + <p class="font-_875 {{if .ContainsSpoilers}}spoiler{{end}}">{{.Overview}}</p> </div> </div> {{end}} diff --git a/tmdb/serie.go b/tmdb/serie.go index 29fa8e5ec56036619c7b579414173579063b4352..f04669030f7daff9dc3090ded6367a368ecdc3cd 100644 --- a/tmdb/serie.go +++ b/tmdb/serie.go @@ -16,17 +16,18 @@ "notabug.org/apiote/gott" ) type Episode struct { - Air_date_str string `json:"air_date"` - Air_date time.Time - Episode_number int `json:"episode_number"` - Name string - Overview string - Season_number int `json:"season_number"` - Still_path string `json:"still_path"` - Vote_count int `json:"vote_count"` - Vote_average float32 `json:"vote_average"` - Episode_code string - Experiences []time.Time + Air_date_str string `json:"air_date"` + Air_date time.Time + Episode_number int `json:"episode_number"` + Name string + Overview string + Season_number int `json:"season_number"` + Still_path string `json:"still_path"` + Vote_count int `json:"vote_count"` + Vote_average float32 `json:"vote_average"` + Episode_code string + Experiences []time.Time + ContainsSpoilers bool } func (e Episode) IsWatched() bool {