Commit b22716db90
Unsigned
Layout: unified · split
internal/anilist.go +10 −49
| @@ -11,55 +11,6 @@ import ( | |||
| 11 | "strings" | 11 | "strings" |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | // AniListAnime is the struct for the API response | ||
| 15 | type AniListAnime struct { | ||
| 16 | ID int `json:"id"` | ||
| 17 | Title struct { | ||
| 18 | Romaji string `json:"romaji"` | ||
| 19 | English string `json:"english"` | ||
| 20 | Native string `json:"native"` | ||
| 21 | } `json:"title"` | ||
| 22 | } | ||
| 23 | |||
| 24 | // Page represents the page in AniList response | ||
| 25 | type Page struct { | ||
| 26 | Media []AniListAnime `json:"media"` | ||
| 27 | } | ||
| 28 | |||
| 29 | // ResponseData represents the full response structure | ||
| 30 | type ResponseData struct { | ||
| 31 | Page Page `json:"Page"` | ||
| 32 | } | ||
| 33 | |||
| 34 | // AnimeTitle represents the title in different languages | ||
| 35 | type AnimeTitle struct { | ||
| 36 | Romaji string | ||
| 37 | English string | ||
| 38 | Japanese string | ||
| 39 | } | ||
| 40 | |||
| 41 | type Media struct { | ||
| 42 | Duration int `json:"duration"` | ||
| 43 | Episodes int `json:"episodes"` | ||
| 44 | ID int `json:"id"` | ||
| 45 | Title AnimeTitle `json:"title"` | ||
| 46 | } | ||
| 47 | |||
| 48 | type Entry struct { | ||
| 49 | Media Media `json:"media"` | ||
| 50 | Progress int `json:"progress"` | ||
| 51 | Score float64 `json:"score"` | ||
| 52 | Status string `json:"status"` | ||
| 53 | } | ||
| 54 | |||
| 55 | type AnimeList struct { | ||
| 56 | Watching []Entry `json:"watching"` | ||
| 57 | Completed []Entry `json:"completed"` | ||
| 58 | Paused []Entry `json:"paused"` | ||
| 59 | Dropped []Entry `json:"dropped"` | ||
| 60 | Planning []Entry `json:"planning"` | ||
| 61 | } | ||
| 62 | |||
| 63 | // FindKeyByValue searches for a key associated with a given value in a map[string]string | 14 | // FindKeyByValue searches for a key associated with a given value in a map[string]string |
| 64 | func FindKeyByValue(m map[string]string, value string) (string, error) { | 15 | func FindKeyByValue(m map[string]string, value string) (string, error) { |
| 65 | for key, val := range m { | 16 | for key, val := range m { |
| @@ -571,3 +522,13 @@ func FindAnimeByAnilistID(list AnimeList, idStr string) (*Entry, error) { | |||
| 571 | 522 | ||
| 572 | return nil, fmt.Errorf("anime with ID %d not found", id) // Return an error if not found | 523 | return nil, fmt.Errorf("anime with ID %d not found", id) // Return an error if not found |
| 573 | } | 524 | } |
| 525 | |||
| 526 | // FindAnimeByAnilistIDInAnimes searches for an anime by its AniList ID in a slice of Anime | ||
| 527 | func FindAnimeByAnilistIDInAnimes(animes []Anime, anilistID int) (*Anime, error) { | ||
| 528 | for i := range animes { | ||
| 529 | if animes[i].AnilistId == anilistID { | ||
| 530 | return &animes[i], nil | ||
| 531 | } | ||
| 532 | } | ||
| 533 | return nil, fmt.Errorf("anime with ID %d not found", anilistID) | ||
| 534 | }\ No newline at end of file | ||