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