amuse.git

commit cf4cd1a44fca2fc45e7fa5941c73097b6ed492be

Author: Adam <git@apiote.tk>

show most popular film as person’s backdrop

 templates/person.html | 4 ++++
 tmdb/person.go | 19 +++++++++++++++++++


diff --git a/templates/person.html b/templates/person.html
index a22bedcc18d1705de172b857adc7145f7237d77f..81c0f2882ae12c3a60b7439d2fb4e8a3f8605a01 100644
--- a/templates/person.html
+++ b/templates/person.html
@@ -45,7 +45,11 @@ 				{{ end }}
 			</div>
 		</header>
 		<div class="absolute top behind w12">
+			{{if .Data.Backdrop_path }}
+			<img src="https://image.tmdb.org/t/p/original{{.Data.Backdrop_path}}" class="w12 cover height-30" />
+			{{else}}
 			<img src="/static/img/person_backdrop.webp" class="w12 cover height-30" /> <!-- Photo by [Pixbay](https://www.pexels.com/@pixabay) from [Pexels](https://www.pexels.com/photo/time-lapse-photo-of-lights-220118/) -->
+			{{end}}
 			<div class="on-desktop relative bottom-4 sans inline-block w12 padding-l-16 font-3 bg-gradient border-box">
 				<span class="text-white">{{.Data.Name}}</span>
 			</div>




diff --git a/tmdb/person.go b/tmdb/person.go
index 41c46f843402c00bfa11ab04df52fd5412ed8044..b231a05f79b352fb776864d5ae86e3f43d163935 100644
--- a/tmdb/person.go
+++ b/tmdb/person.go
@@ -16,6 +16,8 @@ 	Cast []struct {
 		Id                 int
 		Media_type         string `json:"media_type"`
 		Poster_path        string `json:"poster_path"`
+		Backdrop_path      string `json:"backdrop_path"`
+		Popularity         float64
 		Character          string
 		Title              string
 		Name               string
@@ -46,6 +48,7 @@ 	Name           string
 	Biography      string
 	Place_of_birth string `json:"place_of_birth"`
 	Profile_path   string `json:"profile_path"`
+	Backdrop_path  string
 	Source         string
 	Credits        Credits `json:"combined_credits"`
 }
@@ -168,6 +171,21 @@ 	})
 	return gott.Tuple(args)
 }
 
+func getBackdrop(args ...interface{}) interface{} {
+	person := args[1].(*network.Result).Result.(*Person)
+	maxPopularity := 0.0
+	backdropPath := ""
+	for _, f := range person.Credits.Cast {
+		if f.Popularity > maxPopularity {
+			backdropPath = f.Backdrop_path
+			maxPopularity = f.Popularity
+		}
+	}
+	person.Backdrop_path = backdropPath
+	return gott.Tuple(args)
+}
+
+
 func GetPerson(id, language, etag string) (*Person, error) {
 	person, err := gott.
 		NewResult(gott.Tuple{&network.Request{Id: id, Etag: etag, Language: language}, &network.Result{}}).
@@ -182,6 +200,7 @@ 		Bind(convertPersonDeathDate).
 		Bind(convertJobsDates).
 		Map(convertJobsNames).
 		Map(sortJobs).
+		Map(getBackdrop).
 		Finish()
 
 	if err != nil {