-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmux.go
200 lines (189 loc) · 3.95 KB
/
mux.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
package main
import (
"strings"
"github.com/parnurzeal/gorequest"
)
func mux(u *up, request *gorequest.SuperAgent, signal chan int) {
switch u.Platform {
case zhanqi:
request.Get(u.URL).End(func(resp gorequest.Response, body string, errs []error) {
getZhanqi(body, errs, u)
})
case bili:
id := tail(u.URL)
request.Get(biliRoomInfoURL + id).EndBytes(func(resp gorequest.Response, body []byte, errs []error) {
getBili(body, errs, u)
})
case panda:
id := tail(u.URL)
request.Get(pandaRoomInfoURL + id).EndBytes(func(resp gorequest.Response, body []byte, errs []error) {
getPanda(body, errs, u)
})
case douyu:
request.Get(u.URL).End(func(resp gorequest.Response, body string, errs []error) {
getDouyu(body, errs, u)
})
case huya:
request.Get(u.URL).End(func(resp gorequest.Response, body string, errs []error) {
getHuya(body, errs, u)
})
case quanmin:
request.Get(u.URL).End(func(resp gorequest.Response, body string, errs []error) {
getQuanmin(body, errs, u)
})
case longzhu:
id := tail(u.URL)
request.Get(longzhuRoomInfoURL + id).EndBytes(func(resp gorequest.Response, body []byte, errs []error) {
getLongzhu(body, errs, u)
})
case huomao:
request.Get(u.URL).End(func(resp gorequest.Response, body string, errs []error) {
getHuomao(body, errs, u)
})
default:
u.Islive = false
u.Code = 3
u.Msg = "unsupport site error"
}
signal <- 0
return
}
func getZhanqi(body string, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
start := strings.Index(body, `","status":"`)
if start == -1 {
u.Islive = false
u.Code = 2
u.Msg = "search room status error"
return
}
if body[start+12] == '4' {
u.Islive = true
return
}
u.Islive = false
}
func getBili(body []byte, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
if json.Get(body, "data", "live_status").ToInt() == 1 {
u.Islive = true
return
}
u.Islive = false
}
func getPanda(body []byte, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
if json.Get(body, "data", "videoinfo", "status").ToString() == "2" {
u.Islive = true
return
}
u.Islive = false
}
func getDouyu(body string, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
start := strings.Index(body, `,"show_status":`)
if start == -1 {
u.Islive = false
u.Code = 2
u.Msg = "search room status error"
return
}
if body[start+15] == '1' {
u.Islive = true
return
}
u.Islive = false
}
func getHuya(body string, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
start := strings.Index(body, `","state":"`)
if start == -1 {
u.Islive = false
u.Code = 2
u.Msg = "search room status error"
return
}
if body[start+11:start+13] == "ON" {
u.Islive = true
return
}
u.Islive = false
}
func getQuanmin(body string, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
start := strings.Index(body, `","status":"`)
if start == -1 {
u.Islive = false
u.Code = 2
u.Msg = "search room status error"
return
}
if body[start+12] == '2' {
u.Islive = true
return
}
u.Islive = false
}
func getLongzhu(body []byte, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
if json.Get(body, "data", "live", "isLive").ToBool() == true {
u.Islive = true
return
}
u.Islive = false
}
func getHuomao(body string, errs []error, u *up) {
if len(errs) != 0 {
u.Islive = false
u.Code = 1
u.Msg = "get page error"
return
}
start := strings.Index(body, `,"is_live":`)
if start == -1 {
u.Islive = false
u.Code = 2
u.Msg = "search room status error"
return
}
if body[start+11] == '1' {
u.Islive = true
return
}
u.Islive = false
}