mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 15:39:53 +01:00
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
)
|
|
|
|
func JikanConvert(jik *SeasonAnimeJikan) Anime {
|
|
res := Anime{
|
|
Anime: jik.MalID,
|
|
Title: jik.Title,
|
|
TitleEn: jik.TitleEnglish,
|
|
TitleJp: jik.TitleJapanese,
|
|
ImageMediumURL: jik.Images.Jpg.ImageURL,
|
|
ImageLargeURL: jik.Images.Jpg.LargeImageURL,
|
|
ImageThumbURL: jik.Images.Jpg.SmallImageURL,
|
|
Type: jik.Type,
|
|
Status: jik.Status,
|
|
Episodes: jik.Episodes,
|
|
Synopsis: jik.Synopsis,
|
|
StartDate: jik.Aired.From,
|
|
EndDate: jik.Aired.To,
|
|
Year: jik.Year,
|
|
Season: jik.Season,
|
|
Score: jik.Score,
|
|
ScoredBy: jik.ScoredBy,
|
|
Rank: jik.Rank,
|
|
Popularity: jik.Popularity,
|
|
Members: jik.Members,
|
|
Source: jik.Source,
|
|
DayOfTheWeek: jik.Broadcast.Day,
|
|
StartTime: jik.Broadcast.Time,
|
|
TrailerURL: jik.Trailer.URL,
|
|
}
|
|
for _, g := range jik.Genres {
|
|
res.Genres = append(res.Genres, AnimeGenre{
|
|
ID: g.MalID,
|
|
Name: g.Name,
|
|
})
|
|
}
|
|
for _, s := range jik.Studios {
|
|
res.Studios = append(res.Studios, AnimeStudio{
|
|
ID: s.MalID,
|
|
Name: s.Name,
|
|
})
|
|
}
|
|
return res
|
|
}
|
|
|
|
func GetSeasonCache() ([]Anime, error) {
|
|
data, err := cache.Get(seasonApiJikan)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var seasonData []Anime
|
|
err = json.Unmarshal(data, &seasonData)
|
|
return seasonData, err
|
|
}
|
|
|
|
func SearchSeason(animeId int64) (*Anime, error) {
|
|
season, err := GetSeasonCache()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(season) == 0 {
|
|
return nil, errors.New("no seasonal anime")
|
|
}
|
|
for _, a := range season {
|
|
if a.Anime == animeId {
|
|
return &a, err
|
|
}
|
|
}
|
|
return nil, errors.New("anime not found")
|
|
}
|