-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixivlee.go
66 lines (52 loc) · 963 Bytes
/
pixivlee.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
package Pixivlee
import (
"strconv"
"strings"
"time"
)
type Pixiver struct {
pid TPid
sessionID string
state int
limitAt int
}
func (p *Pixiver) Pid() TPid {
if p.pid > 0 {
return p.pid
}
if arr := strings.SplitN(p.sessionID, "_", 2); len(arr) == 2 {
pid, _ := strconv.ParseUint(arr[0], 10, 64)
return TPid(pid)
}
return 0
}
func (p *Pixiver) SessionID() string {
return p.sessionID
}
func (p *Pixiver) State() int {
return p.state
}
func (p *Pixiver) SetPid(pid TPid) {
if p.Pid() == 0 {
p.pid = pid
}
}
func (p *Pixiver) UpdateState(state int) {
if p.State() == state {
return
}
switch state {
case PixiverNormal:
p.state = PixiverNormal
p.limitAt = 0
case PixiverRateLimiting:
p.state = PixiverRateLimiting
p.limitAt = time.Now().Nanosecond()
case PixiverInvalid:
p.state = PixiverInvalid
p.limitAt = 0
}
}
func NewPixiver(sessionID string) IPixiver {
return &Pixiver{sessionID: sessionID}
}