aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-04 02:20:19 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-04 02:20:19 +0530
commit1cac547f4aa9d15a56281c4b5a9db5e8f3d97c47 (patch)
tree675023739bfcb3035a7a54bb06e28f440c9b4422
parent9228897f84d898a7736f1f6df9b2aac005a89514 (diff)
added anime info with searching
-rw-r--r--mal/search.go9
-rw-r--r--ui/search.go52
2 files changed, 59 insertions, 2 deletions
diff --git a/mal/search.go b/mal/search.go
index c010112..32df60f 100644
--- a/mal/search.go
+++ b/mal/search.go
@@ -26,7 +26,14 @@ import (
)
func SearchAnime(searchString string) []a.Anime {
- fields := []string{"title", "id", "my_list_status"}
+ fields := []string{
+ "title", "id", "num_episodes",
+ "synopsis", "alternative_titles",
+ "start_date", "end_date", "mean",
+ "start_season", "rank", "media_type",
+ "status", "average_episode_duration",
+ "rating", "studios",
+ }
res, err := animeClient.SearchAnime(searchString, SearchLength, SearchOffset, SearchNSFW, fields)
if err != nil {
diff --git a/ui/search.go b/ui/search.go
index 8e6ac0d..baea6f1 100644
--- a/ui/search.go
+++ b/ui/search.go
@@ -32,14 +32,64 @@ import (
func AnimeSearch(label, searchString string) a.Anime {
animes := mal.SearchAnime(searchString)
+ for i, anime := range animes {
+ animes[i].DurationSeconds = anime.DurationSeconds / 60
+
+ /* I cant find a way to add functions to the details template
+ * So I am formatting the studios as one string
+ * and setting as the first studio name. pretty hacky. */
+ if len(anime.Studios) > 0 {
+ var studiosFormatted string
+ for j, studio := range anime.Studios {
+ studiosFormatted = studiosFormatted + studio.Name
+ // setting other studio names as ""
+ animes[i].Studios[j].Name = ""
+ if j != len(anime.Studios) - 1 {
+ studiosFormatted = studiosFormatted + ", "
+ }
+ }
+ animes[i].Studios[0].Name = studiosFormatted
+ }
+
+ var ratingFormatted string
+ switch anime.Rating {
+ case "g":
+ ratingFormatted = "G - All Ages"
+ case "pg":
+ ratingFormatted = "PG - Children"
+ case "pg_13":
+ ratingFormatted = "PG13 - Teens 13 and Older"
+ case "r":
+ ratingFormatted = "R - 17+ (violence & profanity)"
+ case "r+":
+ ratingFormatted = "R+ - Profanity & Mild Nudity"
+ case "rx":
+ ratingFormatted = "Rx - Hentai"
+ default:
+ ratingFormatted = anime.Rating
+ }
+ animes[i].Rating = ratingFormatted
+ }
+
template := &p.SelectTemplates {
Label: "{{ . }}",
Active: "{{ .Title | magenta }}",
Inactive: "{{ .Title }}",
Selected: "{{ .Title | blue }}",
+ // TODO: format and maybe color code details
Details: `
--------- {{ .Title }} ----------
-More Details To Be Added Later
+{{ "Number of Episodes:" | blue | bold }} {{ .NumEpisodes }}
+{{ "English Title:" | blue | bold }} {{ .AltTitles.En }}
+{{ "Japanese Title:" | blue | bold }} {{ .AltTitles.Ja }}
+{{ "Original Run:" | blue | bold }} {{ .StartDate }} - {{ .EndDate }} ({{ .StartSeason.Name }} {{ .StartSeason.Year }})
+{{ "Mean Score:" | blue | bold }} {{ .MeanScore }}
+{{ "Rank:" | blue | bold }} {{ .Rank }}
+{{ "Type:" | blue | bold }} {{ .MediaType }}
+{{ "Status:" | blue | bold }} {{ .Status }}
+{{ "Average Duration:" | blue | bold }} {{ .DurationSeconds }} minutes
+{{ "Rating:" | blue | bold }} {{ .Rating }}
+{{ "Studios:" | blue | bold }} {{ range .Studios }}{{ .Name }}{{ end }}
`,
}