-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanime365.go
297 lines (277 loc) · 9.37 KB
/
anime365.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
package anime365
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const apiURL = "https://smotret-anime.ru/api/"
type genre struct {
ID uint `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
}
type link struct {
Title string `json:"title"`
URL string `json:"url"`
}
type title struct {
RU string `json:"ru"`
Romaji string `json:"romaji"`
JA string `json:"ja"`
EN string `json:"en"`
Short string `json:"short"`
}
type fansubsTranslation struct {
ID uint32 `json:"id"`
FansubsSeriesID uint32 `json:"fansubsSeriesId"`
Count string `json:"count"`
Date string `json:"date"`
Comment string `json:"comment"`
File string `json:"file"`
FileURL string `json:"fileUrl"`
}
type description struct {
Source string `json:"source"`
Value string `json:"value"`
UpdatedDateTime string `json:"updatedDateTime"`
}
// Series structure contains parsed JSON response with all fields
type Series struct {
ID uint32 `json:"id"`
AniDbID uint32 `json:"aniDbId"`
AnimeNewsNetworkID uint32 `json:"animeNewsNetworkId"`
FansubsID uint32 `json:"fansubsId"`
ImdbID uint32 `json:"imdbId"`
WorldArtID uint32 `json:"worldArtId"`
Links []link `json:"link"`
MyAnimeListID uint32 `json:"myAnimeListId"`
MyAnimeListScore string `json:"myAnimeListScore"`
WorldArtListScore string `json:"worldArtListScore"`
WorldArtTopPlace uint32 `json:"worldArtTopPlace"`
NumberOfEpisodes uint32 `json:"numberOfEpisodes"`
PosterURL string `json:"posterUrl"`
PosterURLSmall string `json:"posterUrlSmall"`
Season string `json:"string"`
Year uint32 `json:"year"`
Type string `json:"type"`
TypeTitle string `json:"typeTitle"`
CountViews uint32 `json:"countViews"`
Titles title `json:"titles"`
TitleLines []string `json:"titleLines"`
AllTitles []string `json:"allTitles"`
Title string `json:"title"`
URL string `json:"url"`
Descriptions []description `json:"descriptions"`
Episodes []Episode `json:"episodes"`
Genres []genre `json:"genres"`
isActive uint8
isAiring uint8
isHentai uint8
}
// IsActive returns boolean value whether series is active (true) or not (false)
func (s *Series) IsActive() bool {
if s.isActive == 1 {
return true
}
return false
}
// IsAiring returns boolean value whether series is airing (true) or not (false)
func (s *Series) IsAiring() bool {
if s.isAiring == 1 {
return true
}
return false
}
// IsHentai returns boolean value whether series is hentai (true) or not (false)
func (s *Series) IsHentai() bool {
if s.isHentai == 1 {
return true
}
return false
}
// Translation structure contains parsed JSON response with all fields
type Translation struct {
ID uint32 `json:"id"`
AddedDateTime string `json:"addedDateTime"`
ActiveDateTime string `json:"activeDateTime"`
AuthorsList []string `json:"authorsList"`
FansubsTranslationID uint32 `json:"fansubsTranslationId"`
Priority uint32 `json:"priority"`
QualityType string `json:"qualityType"`
Type string `json:"type"`
TypeKind string `json:"typeKind"`
TypeLang string `json:"typeLang"`
UpdatedDateTime string `json:"updatedDateTime"`
Title string `json:"title"`
SeriesID uint32 `json:"seriesId"`
EpisodeID uint32 `json:"episodeId"`
CountViews uint32 `json:"countViews"`
URL string `json:"url"`
EmbedURL string `json:"embedUrl"`
AuthorsSummary string `json:"authorsSummary"`
Episode Episode `json:"episode"`
Series Series `json:"series"`
FansubsTranslation fansubsTranslation `json:"url"`
Duration string `json:"duration"`
Width uint32 `json:"width"`
Height uint32 `json:"height"`
isActive uint8
}
// IsActive returns boolean value whether translation is active (true) or not (false)
func (t *Translation) IsActive() bool {
if t.isActive == 1 {
return true
}
return false
}
// Episode structure contains parsed JSON response with all fields
type Episode struct {
ID uint32 `json:"id"`
EpisodeFull string `json:"episodeFull"`
EpisodeInt string `json:"episodeInt"`
EpisodeTitle string `json:"episodeTitle"`
EpisodeType string `json:"episodeType"`
FirstUploadedDateTime string `json:"firstUploadedDateTime"`
SeriesID uint32 `json:"seriesId"`
CountViews uint32 `json:"countViews"`
Translations []Translation `json:"translations"`
isActive uint8
}
// IsActive returns boolean value whether episode is active (true) or not (false)
func (e *Episode) IsActive() bool {
if e.isActive == 1 {
return true
}
return false
}
// GetTranslations makes request to API with followed parameters and returns list of Translation structures
func GetTranslations(parameters map[string]string) ([]Translation, error) {
requestURL, err := url.Parse(apiURL + "translations")
if err != nil {
return nil, err
}
requestQuery := requestURL.Query()
for key, value := range parameters {
requestQuery.Set(key, value)
}
requestURL.RawQuery = requestQuery.Encode()
response, err := http.Get(requestURL.String())
if err != nil {
return nil, err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string][]Translation
if err := json.Unmarshal(content, &jsonResponse); err != nil {
return nil, err
}
return jsonResponse["data"], nil
}
// GetTranslationByID makes request by ID with followed parameters to API and returns a Translation structure
func GetTranslationByID(id uint32, parameters map[string]string) (*Translation, error) {
requestURL, err := url.Parse(apiURL + "translations/" + fmt.Sprint(id))
if err != nil {
return nil, err
}
for key, value := range parameters {
requestURL.Query().Set(key, value)
}
requestURL.RawQuery = requestURL.Query().Encode()
response, err := http.Get(requestURL.String())
if err != nil {
return nil, err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string]*Translation
if err := json.Unmarshal(content, &jsonResponse); err != nil {
return nil, err
}
return jsonResponse["data"], nil
}
// GetSeries makes request to API with followed parameters and returns list of Series structures
func GetSeries(parameters map[string]string) ([]Series, error) {
requestURL, err := url.Parse(apiURL + "series")
if err != nil {
return nil, err
}
requestQuery := requestURL.Query()
for key, value := range parameters {
requestQuery.Set(key, value)
}
requestURL.RawQuery = requestQuery.Encode()
response, err := http.Get(requestURL.String())
if err != nil {
return nil, err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string][]Series
if err := json.Unmarshal(content, &jsonResponse); err != nil {
return nil, err
}
return jsonResponse["data"], nil
}
// GetSeriesByID makes request by ID with followed parameters to API and returns a Series structure
func GetSeriesByID(id uint32, parameters map[string]string) (*Series, error) {
requestURL, err := url.Parse(apiURL + "series/" + fmt.Sprint(id))
if err != nil {
return nil, err
}
requestQuery := requestURL.Query()
for key, value := range parameters {
requestQuery.Set(key, value)
}
requestURL.RawQuery = requestQuery.Encode()
response, err := http.Get(requestURL.String())
if err != nil {
return nil, err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string]*Series
if err := json.Unmarshal(content, &jsonResponse); err != nil {
return nil, err
}
return jsonResponse["data"], nil
}
// GetEpisodeByID makes request by ID with followed parameters to API and returns an Episode structure
func GetEpisodeByID(id uint32, parameters map[string]string) (*Episode, error) {
requestURL, err := url.Parse(apiURL + "episodes/" + fmt.Sprint(id))
if err != nil {
return nil, err
}
requestQuery := requestURL.Query()
for key, value := range parameters {
requestQuery.Set(key, value)
}
requestURL.RawQuery = requestQuery.Encode()
response, err := http.Get(requestURL.String())
if err != nil {
return nil, err
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var jsonResponse map[string]*Episode
if err := json.Unmarshal(content, &jsonResponse); err != nil {
return nil, err
}
return jsonResponse["data"], nil
}