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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# MAL2Go/anime
MAL2Go `anime` package has functionality related to getting data about anime.
To *update* anime status (score, status, etc) refer to [`user/anime`](../user/anime) package.
## Installation
In a terminal, run
``` fish
go get "github.com/MikunoNaka/MAL2Go/anime"
```
## Usage
Firstly, import this package and instanciate the client.
``` go
import (
"github.com/MikunoNaka/MAL2Go/anime"
)
```
Now instanciate with
``` go
myClient := anime.Client {
AuthToken: "Bearer " + yourTokenHere,
}
```
- ### Searching for an anime
``` go
searchString := "mushishi" // your search string here
// max amount of results to pull. Max is 500
limit := 10
// if the offset is 2 it will skip the first 2 results, then pull the next 10
offset := 0
// the API by default only returns some basic data
// you can specify some fields as a []string slice.
// it will return the default fields even if they aren't specified
fields := []string{
"id", "title", "main_picture",
"alternative_titles", "start_date",
"end_date", "synopsis", "mean", "rank",
"popularity", "num_list_users",
"num_scoring_users", "nsfw", "created_at",
"updated_at", "media_type", "status",
"genres", "my_list_status", "num_episodes",
"start_season", "broadcast", "source",
"average_episode_duration", "rating",
"pictures", "background", "related_anime",
"related_manga", "recommendations",
"studios", "statistics",
} // for all default fields fields := []string{} will also work
// finally making the API request
searchResults, err := myClient.SearchAnime(searchString, limit, offset, fields)
fmt.Println(searchResults.Animes) // print list of the search results
```
- ### Getting an anime's info
Each anime on MyAnimeList has a unique ID, which you need to find it
Refer to [anime.structs.go](anime.structs.go) to find out all the keys the Anime struct has
``` go
animeId := 42351
fields := []string{} // pull every field
anime, err := myClient.GetAnimeById(animeId, fields)
if err != nil {
fmt.Println(err)
}
fmt.Println(anime.Title, anime.MeanScore, anime.ListStatus.Status)
```
- ### Get anime ranking
Ranking is a list of anime sorted by their rank
Possible ranking types are:
- `all`
- `airing`
- `upcoming`
- `tv`
- `ova`
- `movie`
- `special`
- `bypopularity`
- `favorite`
``` go
rankingType := "favorite"
limit, offset := 10, 0
fields := []string{"title"}
ranking, err := myClient.GetAnimeRanking(rankingType, limit, offset, fields)
// loop over the array of animes returned by the API
for _, anime := range ranking.Animes {
fmt.Printf("Title: %s, Rank Number: %d", anime.Title, anime.RankNum)
}
```
- ### Get seasonal anime
Get a list of anime from a particular season/year
Possible seasons are:
- `winter`
- `spring`
- `summer`
- `fall`
Possible ways to sort are:
- `anime_score`
- `anime_num_list_users`
``` go
year := "2021"
season := "winter"
sort := "anime_score"
limit, offset := 10, 0
fields := []string{"title"}
seasonalAnime, err := myClient.GetSeasonalAnime(year, season, sort, limit, offset, fields)
if err != nil {
fmt.Println(err)
}
for _, anime := range seasonalAnime.Animes {
fmt.Println(anime.Title)
}
fmt.Println(seaonalAnime.Season)
```
- ### Get suggested anime
Returns suggestions related to the authenticated user
``` go
limit, offset := 10, 0
fields := []string{"title"}
suggestedAnime, err := myClient.GetSuggestedAnime(limit, offset, fields)
if err != nil {
fmt.Println(err)
}
for _, anime := range suggestedAnime.Animes {
fmt.Println(anime.Titile)
}
```
## Structure
- [anime.go](anime.go)
Contains all the exported functions for pulling data from the API.
- [anime.structs.go](anime.structs.go)
Contains all the structs representing an anime entry on MyAnimeList.
- [client.go](client.go)
The Client for accessing the API with this package.
- [general.structs.go](general.structs.go)
Some structs that can't particularly be grouped with another file.
- [ranking.structs.go](ranking.structs.go)
Representing anime ranking data both in the form returned by the API and
the formatted form to be returned by this package.
- [request_handler.go](request_handler.go)
Responsible for making HTTP requests
- [search.structs.go](search.structs.go)
Representing search results.
- [seasonal.structs.go](seasonal.structs.go)
Representing seasonal anime list.
- [suggestedanime.structs.go](suggestedanime.structs.go)
Representing suggested anime data.
|