]> git.lizzy.rs Git - go-anidb.git/blob - anime.go
5e5c4b7c997f6c2bb8623bdf1a6c78917f7b3441
[go-anidb.git] / anime.go
1 package anidb
2
3 import (
4         "github.com/Kovensky/go-anidb/misc"
5         "strconv"
6         "time"
7 )
8
9 // See the constants list for the valid values.
10 type AnimeType string
11
12 const (
13         AnimeTypeTVSeries   = AnimeType("TV Series")  // Anime was a regular TV broadcast series
14         AnimeTypeTVSpecial  = AnimeType("TV Special") // Anime was broadcast on TV as a special
15         AnimeTypeMovie      = AnimeType("Movie")      // Anime was a feature film
16         AnimeTypeOVA        = AnimeType("OVA")        // Anime was released direct-to-video
17         AnimeTypeWeb        = AnimeType("Web")        // Anime was released through online streaming or downloads
18         AnimeTypeMusicVideo = AnimeType("Music Video")
19 )
20
21 type Rating struct {
22         Rating    float32
23         VoteCount int
24 }
25
26 type Resource []string
27
28 // Links to third party websites
29 type Resources struct {
30         AniDB,
31         ANN,
32         MyAnimeList,
33         AnimeNfo,
34         OfficialJapanese,
35         OfficialEnglish,
36         WikipediaEnglish,
37         WikipediaJapanese,
38         SyoboiSchedule,
39         AllCinema,
40         Anison,
41         VNDB,
42         MaruMegane Resource
43 }
44
45 type UniqueTitleMap map[Language]string
46 type TitleMap map[Language][]string
47
48 type Anime struct {
49         AID AID  // The Anime ID.
50         R18 bool // Whether this anime is considered porn.
51
52         Type          AnimeType    // Production/distribution type.
53         TotalEpisodes int          // Total number of regular episodes.
54         EpisodeCount  EpisodeCount // Known numbers of the various types of episodes.
55
56         StartDate time.Time // Date of first episode release, if available.
57         EndDate   time.Time // Date of last episode release, if available.
58
59         PrimaryTitle   string         // The primary title in the database; almost always a romanization of the Japanese title.
60         OfficialTitles UniqueTitleMap // The official title for each language.
61         ShortTitles    TitleMap       // Shortcut titles used for searches
62         Synonyms       TitleMap       // Synonyms for each language, or unofficial titles
63
64         OfficialURL string // URL for original official website.
65         Picture     string // URL for the page picture on AniDB.
66
67         Description string
68
69         Votes          Rating // Votes from people who watched the whole thing.
70         TemporaryVotes Rating // Votes from people who are still watching this.
71         Reviews        Rating // Votes from reviewers.
72
73         Episodes []*Episode // List of episodes.
74
75         Awards    []string
76         Resources Resources
77
78         Incomplete bool      // Set if the UDP API part of the query failed.
79         Updated    time.Time // When the data was last modified in the server.
80         Cached     time.Time // When the data was retrieved from the server.
81 }
82
83 type EpisodeCount struct {
84         RegularCount int
85         SpecialCount int
86         CreditsCount int
87         OtherCount   int
88         TrailerCount int
89         ParodyCount  int
90 }
91
92 // Convenience method that runs AnimeByID on the result of
93 // SearchAnime.
94 func (adb *AniDB) AnimeByName(name string) <-chan *Anime {
95         return adb.AnimeByID(SearchAnime(name))
96 }
97
98 // Convenience method that runs AnimeByID on the result of
99 // SearchAnimeFold.
100 func (adb *AniDB) AnimeByNameFold(name string) <-chan *Anime {
101         return adb.AnimeByID(SearchAnimeFold(name))
102 }
103
104 // Returns a list of all Episodes in this Anime's Episodes list
105 // that are contained by the given EpisodeContainer.
106 func (a *Anime) EpisodeList(c misc.EpisodeContainer) (eps []*Episode) {
107         if a == nil || c == nil {
108                 return nil
109         }
110
111         for i, e := range a.Episodes {
112                 if c.ContainsEpisodes(&e.Episode) {
113                         eps = append(eps, a.Episodes[i])
114                 }
115         }
116         return
117 }
118
119 // Searches for the given Episode in this Anime's Episodes list
120 // and returns the match.
121 //
122 // Returns nil if there is no match.
123 func (a *Anime) Episode(ep *misc.Episode) *Episode {
124         switch list := a.EpisodeList(ep); len(list) {
125         case 0:
126                 return nil
127         case 1:
128                 return list[0]
129         default:
130                 panic("Single episode search returned more than one result")
131         }
132 }
133
134 // Convenience method that parses the string into an Episode
135 // before doing the Episode search.
136 func (a *Anime) EpisodeByString(name string) *Episode {
137         return a.Episode(misc.ParseEpisode(name))
138 }
139
140 // Convenience method that parses the int into an Episode
141 // before doing the Episode search.
142 //
143 // Only works with regular (i.e. not special, etc) episodes.
144 func (a *Anime) EpisodeByNumber(number int) *Episode {
145         return a.EpisodeByString(strconv.Itoa(number))
146 }
147
148 func (a *Anime) EpisodeByEID(eid EID) *Episode {
149         if a == nil {
150                 return nil
151         }
152         for _, ep := range a.Episodes {
153                 if ep.EID == eid {
154                         return ep
155                 }
156         }
157         return nil
158 }