-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanga.go
319 lines (289 loc) · 8.36 KB
/
manga.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
package jikan
import (
"fmt"
"net/url"
"time"
)
// MangaBase struct
type MangaBase struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Images Images3 `json:"images"`
Title string `json:"title"`
TitleEnglish string `json:"title_english"`
TitleJapanese string `json:"title_japanese"`
TitleSynonyms []string `json:"title_synonyms"`
Type string `json:"type"`
Chapters int `json:"chapters"`
Volumes int `json:"volumes"`
Status string `json:"status"`
Publishing bool `json:"publishing"`
Published DateRange `json:"published"`
Score float64 `json:"score"`
ScoredBy int `json:"scored_by"`
Rank int `json:"rank"`
Popularity int `json:"popularity"`
Members int `json:"members"`
Favorites int `json:"favorites"`
Synopsis string `json:"synopsis"`
Background string `json:"background"`
Authors []MalItem `json:"authors"`
Serializations []MalItem `json:"serializations"`
Genres []MalItem `json:"genres"`
ExplicitGenres []MalItem `json:"explicit_genres"`
Themes []MalItem `json:"themes"`
Demographics []MalItem `json:"demographics"`
}
// MangaById struct
type MangaById struct {
Data MangaBase `json:"data"`
}
// GetMangaById returns manga by id
func GetMangaById(id int) (*MangaById, error) {
res := &MangaById{}
err := urlToStruct(fmt.Sprintf("/manga/%d", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaCharacters struct
type MangaCharacters struct {
Data []struct {
Character struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Images Images2 `json:"images"`
Name string `json:"name"`
} `json:"character"`
Role string `json:"role"`
} `json:"data"`
}
// GetMangaCharacters returns manga characters
func GetMangaCharacters(id int) (*MangaCharacters, error) {
res := &MangaCharacters{}
err := urlToStruct(fmt.Sprintf("/manga/%d/characters", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaNews struct
type MangaNews struct {
Data []struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Title string `json:"title"`
Date time.Time `json:"date"`
AuthorUsername string `json:"author_username"`
AuthorUrl string `json:"author_url"`
ForumUrl string `json:"forum_url"`
Images struct {
Jpg struct {
ImageUrl string `json:"image_url"`
} `json:"jpg"`
} `json:"images"`
Comments int `json:"comments"`
Excerpt string `json:"excerpt"`
} `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetMangaNews returns manga news
func GetMangaNews(id, page int) (*MangaNews, error) {
res := &MangaNews{}
err := urlToStruct(fmt.Sprintf("/manga/%d/news?page=%d", id, page), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaForum struct
type MangaForum struct {
Data []struct {
MalId int `json:"mal_id"`
Url string `json:"url"`
Title string `json:"title"`
Date time.Time `json:"date"`
AuthorUsername string `json:"author_username"`
AuthorUrl string `json:"author_url"`
Comments int `json:"comments"`
LastComment Comment `json:"last_comment"`
} `json:"data"`
}
type MangaForumFilter string
const (
MangaForumFilterAll MangaForumFilter = "all"
MangaForumFilterEpisode MangaForumFilter = "episode"
MangaForumFilterOther MangaForumFilter = "other"
)
// GetMangaTopics returns manga forum
func GetMangaForum(id int, filter MangaForumFilter) (*MangaForum, error) {
res := &MangaForum{}
req := fmt.Sprintf("/manga/%d/forum", id)
if filter != "" {
req += fmt.Sprintf("?filter=%s", filter)
}
err := urlToStruct(req, res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaPictures struct
type MangaPictures struct {
Data []Images3 `json:"data"`
}
// GetMangaPictures returns manga pictures
func GetMangaPictures(id int) (*MangaPictures, error) {
res := &MangaPictures{}
err := urlToStruct(fmt.Sprintf("/manga/%d/pictures", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaStatistics struct
type MangaStatistics struct {
Data struct {
Reading int `json:"reading"`
Completed int `json:"completed"`
OnHold int `json:"on_hold"`
Dropped int `json:"dropped"`
PlanToRead int `json:"plan_to_read"`
Total int `json:"total"`
Scores []ScoresShort `json:"scores"`
} `json:"data"`
}
// GetMangaStatistics returns manga statistics
func GetMangaStatistics(id int) (*MangaStatistics, error) {
res := &MangaStatistics{}
err := urlToStruct(fmt.Sprintf("/manga/%d/statistics", id), res)
if err != nil {
return nil, err
}
return res, nil
}
type MangaMoreInfo struct {
Data struct {
Moreinfo string `json:"moreinfo"`
} `json:"data"`
}
// GetMangaMoreInfo returns manga more info
func GetMangaMoreInfo(id int) (*MangaMoreInfo, error) {
res := &MangaMoreInfo{}
err := urlToStruct(fmt.Sprintf("/manga/%d/moreinfo", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaRecommendations struct
type MangaRecommendations struct {
Data []struct {
Entry EntryTitle3 `json:"entry"`
Url string `json:"url"`
Votes int `json:"votes"`
} `json:"data"`
}
// GetMangaRecommendations returns manga recommendations
func GetMangaRecommendations(id int) (*MangaRecommendations, error) {
res := &MangaRecommendations{}
err := urlToStruct(fmt.Sprintf("/manga/%d/recommendations", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaUserUpdates struct
type MangaUserUpdates struct {
Data []struct {
User UserItem `json:"user"`
Score float64 `json:"score"`
Status string `json:"status"`
VolumesRead int `json:"volumes_read"`
VolumesTotal int `json:"volumes_total"`
ChaptersRead int `json:"chapters_read"`
ChaptersTotal int `json:"chapters_total"`
Date time.Time `json:"date"`
} `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetMangaUserUpdates returns manga user updates
func GetMangaUserUpdates(id, page int) (*MangaUserUpdates, error) {
res := &MangaUserUpdates{}
err := urlToStruct(fmt.Sprintf("/manga/%d/userupdates?page=%d", id, page), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaReviews struct
type MangaReviews struct {
Data []struct {
User UserItem `json:"user"`
MalId int `json:"mal_id"`
Url string `json:"url"`
Type string `json:"type"`
Votes int `json:"votes"`
Date time.Time `json:"date"`
ChaptersRead int `json:"chapters_read"`
Review string `json:"review"`
Scores ScoresManga `json:"scores"`
} `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetMangaReviews returns manga reviews
func GetMangaReviews(id, page int) (*MangaReviews, error) {
res := &MangaReviews{}
err := urlToStruct(fmt.Sprintf("/manga/%d/reviews?page=%d", id, page), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaRelations struct
type MangaRelations struct {
Data []struct {
Relation string `json:"relation"`
Entry []MalItem `json:"entry"`
} `json:"data"`
}
// GetMangaRelations returns manga relations
func GetMangaRelations(id int) (*MangaRelations, error) {
res := &MangaRelations{}
err := urlToStruct(fmt.Sprintf("/manga/%d/relations", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaExternal struct
type MangaExternal struct {
Data []struct {
Name string `json:"name"`
Url string `json:"url"`
} `json:"data"`
}
// GetMangaExternal returns manga external
func GetMangaExternal(id int) (*MangaExternal, error) {
res := &MangaExternal{}
err := urlToStruct(fmt.Sprintf("/manga/%d/external", id), res)
if err != nil {
return nil, err
}
return res, nil
}
// MangaSearch struct
type MangaSearch struct {
Data []MangaBase `json:"data"`
Pagination Pagination `json:"pagination"`
}
// GetMangaSearch returns manga search
func GetMangaSearch(query url.Values) (*MangaSearch, error) {
res := &MangaSearch{}
err := urlToStruct(fmt.Sprintf("/manga?%s", query.Encode()), res)
if err != nil {
return nil, err
}
return res, nil
}