This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
/
api_search.go
169 lines (158 loc) · 4.46 KB
/
api_search.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
package malscraper
import (
"github.com/rl404/go-malscraper/model"
)
// SearchAnime to quick search anime.
//
// Example: https://myanimelist.net/anime.php?q=naruto.
func (m *Malscraper) SearchAnime(title string, page ...int) ([]model.AnimeSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.AdvSearchAnime(model.Query{Title: title, Page: p})
}
// AdvSearchAnime to search anime with advanced query.
//
// Available constant options.
//
// Type Status Rating
// ----------- -------------- -------------
// TypeDefault StatusDefault RatingDefault
// TypeTV StatusOnGoing RatingG
// TypeOVA StatusFinished RatingPG
// TypeMovie StatusUpcoming RatingPG13
// TypeSpecial RatingR17
// TypeONA RatingR
// TypeMusic RatingRx
//
// ProducerID should be from `GetProducers()`.
//
// GenreID should be from `GetAnimeGenres()`.
//
// Example: https://myanimelist.net/anime.php?q=naruto.
func (m *Malscraper) AdvSearchAnime(query model.Query) ([]model.AnimeSearch, int, error) {
if query.Page == 0 {
query.Page = 1
}
return m.api.SearchAnime(query)
}
// SearchManga to quick search manga.
//
// Example: https://myanimelist.net/manga.php?q=naruto.
func (m *Malscraper) SearchManga(title string, page ...int) ([]model.MangaSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.AdvSearchManga(model.Query{Title: title, Page: p})
}
// AdvSearchManga to search manga with advanced query.
//
// Available constant options.
//
// Type Status
// ----------- --------------
// TypeDefault StatusDefault
// TypeManga StatusOnGoing
// TypeLightNovel StatusFinished
// TypeOneShot StatusUpcoming
// TypeDoujinshi StatusHiatus
// TypeManhwa StatusDiscontinued
// TypeManhua
// TypeNovel
//
// MagazineID should be from `GetMagazines()`.
//
// GenreID should be from `GetMangaGenres()`.
//
// Example: https://myanimelist.net/manga.php?q=naruto.
func (m *Malscraper) AdvSearchManga(query model.Query) ([]model.MangaSearch, int, error) {
if query.Page == 0 {
query.Page = 1
}
return m.api.SearchManga(query)
}
// SearchCharacter to search character.
//
// Example: https://myanimelist.net/character.php?q=luffy.
func (m *Malscraper) SearchCharacter(name string, page ...int) ([]model.CharacterSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.api.SearchCharacter(name, p)
}
// SearchPeople to search people.
//
// Example: https://myanimelist.net/people.php?q=kana.
func (m *Malscraper) SearchPeople(name string, page ...int) ([]model.PeopleSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.api.SearchPeople(name, p)
}
// SearchClub to quick search club.
//
// Example: https://myanimelist.net/clubs.php?cat=club&catid=0&q=naruto&action=find.
func (m *Malscraper) SearchClub(name string, page ...int) ([]model.ClubSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.AdvSearchClub(model.ClubQuery{Name: name, Page: p})
}
// AdvSearchClub to search club with advanced query.
//
// Available constant options.
//
// Category Sort
// ------------------ -----------
// AllCategory SortDefault
// AnimeCategory SortName
// ConventionCategory SortComment
// ActorCategory SortPost
// CharacterCategory SortMember
// CompanyCategory
// GameCategory
// JapanCategory
// CityCategory
// MusicCategory
// MangaCategory
// SchoolCategory
// OtherCategory
//
// Example: https://myanimelist.net/clubs.php?cat=club&catid=0&q=naruto&action=find.
func (m *Malscraper) AdvSearchClub(query model.ClubQuery) ([]model.ClubSearch, int, error) {
if query.Page == 0 {
query.Page = 1
}
return m.api.SearchClub(query)
}
// SearchUser to quick search user.
//
// Example: https://myanimelist.net/users.php?q=rl404.
func (m *Malscraper) SearchUser(username string, page ...int) ([]model.UserSearch, int, error) {
p := 1
if len(page) > 0 {
p = page[0]
}
return m.AdvSearchUser(model.UserQuery{Username: username, Page: p})
}
// AdvSearchUser to search user with advanced query.
//
// Gender should be one of these constants.
//
// GenderDefault
// GenderMale
// GenderFemale
// GenderNonBinary
//
// Example: https://myanimelist.net/users.php?q=rl404.
func (m *Malscraper) AdvSearchUser(query model.UserQuery) ([]model.UserSearch, int, error) {
if query.Page == 0 {
query.Page = 1
}
return m.api.SearchUser(query)
}