This repository has been archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plashiki.go
123 lines (118 loc) · 2.82 KB
/
plashiki.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
package plashikigo
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/url"
)
// GetAnimeID ...
func GetAnimeID(id string) (map[int]Episode, error) {
resp, err := http.Get("https://plashiki.su/api/anime/v2/" + id)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
anime := AnimeIDResponse{}
if err := json.Unmarshal(body, &anime); err != nil {
return nil, err
}
if anime.OK {
return anime.Result, nil
}
return nil, errors.New("Request error: " + anime.Reason)
}
// GetAnimeEpisode ...
func GetAnimeEpisode(id string, num string) (map[int]Episode, error) {
resp, err := http.Get("https://plashiki.su/api/anime/v2/" + id + "/episodes/" + num)
if err != nil {
return map[int]Episode{}, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return map[int]Episode{}, err
}
anime := AnimeEpisodeResponse{}
if err := json.Unmarshal(body, &anime); err != nil {
return map[int]Episode{}, err
}
if anime.OK {
return anime.Result, nil
}
return map[int]Episode{}, errors.New("Request error: " + anime.Reason)
}
// GetAnimeEpisodesNumber ...
func GetAnimeEpisodesNumber(id string) ([]int, error) {
resp, err := http.Get("https://plashiki.su/api/anime/v2/" + id + "/episodes")
if err != nil {
return []int{}, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []int{}, err
}
anime := AnimeEpisodesResponse{}
if err := json.Unmarshal(body, &anime); err != nil {
return []int{}, err
}
if anime.OK {
return anime.Result, nil
}
return []int{}, errors.New("Request error: " + anime.Reason)
}
// GetAnimeQuery ...
func GetAnimeQuery(args map[string]string) ([]Translation, error) {
baseURL, err := url.Parse("https://plashiki.su")
if err != nil {
return nil, err
}
baseURL.Path += "/api/anime/query"
params := url.Values{}
if val, ok := args["anime"]; ok {
params.Add("anime", val)
}
if val, ok := args["searchLimit"]; ok {
params.Add("searchLimit", val)
}
if val, ok := args["episode"]; ok {
params.Add("episode", val)
}
if val, ok := args["kind"]; ok {
params.Add("kind", val)
}
if val, ok := args["lang"]; ok {
params.Add("lang", val)
}
if val, ok := args["quality"]; ok {
params.Add("quality", val)
}
if val, ok := args["author"]; ok {
params.Add("author", val)
}
if val, ok := args["uploader"]; ok {
params.Add("uploader", val)
}
if val, ok := args["player"]; ok {
params.Add("player", val)
}
baseURL.RawQuery = params.Encode()
resp, err := http.Get(baseURL.String())
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
anime := AnimeQueryResponse{}
if err := json.Unmarshal(body, &anime); err != nil {
return nil, err
}
if anime.OK {
return anime.Result, nil
}
return nil, errors.New("Request error: " + anime.Reason)
}