forked from ylqjgm/AVMeta
/
tokyohot.go
226 lines (190 loc) · 4.82 KB
/
tokyohot.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
package scraper
import (
"fmt"
"regexp"
"strconv"
"strings"
"github.com/cute-angelia/AVMeta/pkg/util"
"github.com/PuerkitoBio/goquery"
)
// TokyoHotScraper tokyohot网站刮削器
type TokyoHotScraper struct {
Proxy string // 代理配置
uri string // 页面地址
number string // 最终番号
root *goquery.Document // 根节点
}
// NewTokyoHotScraper 返回一个被初始化的tokyohot刮削对象
//
// proxy 字符串参数,传入代理信息
func NewTokyoHotScraper(proxy string) *TokyoHotScraper {
return &TokyoHotScraper{Proxy: proxy}
}
// Fetch 刮削
func (s *TokyoHotScraper) Fetch(code string) error {
// 设置番号
s.number = strings.ToLower(code)
// 获取编号
id, err := s.search()
// 检查
if id == "" || err != nil {
return fmt.Errorf("404 Not Found")
}
// 组合地址
uri := fmt.Sprintf("https://my.tokyo-hot.com%s?lang=zh-TW", id)
// 打开链接
root, err := util.GetRoot(uri, s.Proxy, nil)
// 检查
if err != nil {
return err
}
// 设置页面地址
s.uri = uri
// 设置根节点
s.root = root
return nil
}
// 搜索
func (s *TokyoHotScraper) search() (id string, err error) {
// 组合地址
uri := fmt.Sprintf("https://my.tokyo-hot.com/product/?q=%s&x=0&y=0&lang=zh-TW", s.number)
// 获取节点
root, err := util.GetRoot(uri, s.Proxy, nil)
// 检查错误
if err != nil {
return
}
// 是否找到
if -1 < root.Find(`ul.list > li:contains("沒有登入")`).Index() {
err = fmt.Errorf("404 Not Found")
return
}
// 获取结果
root.Find(`ul.list li.detail a`).Each(func(i int, item *goquery.Selection) {
// 获取番号
number, _ := item.Find("img").Attr("title")
// 转换大写
number = strings.ToUpper(number)
// 比较是否一致
if !strings.EqualFold(strings.ToUpper(s.number), number) {
return
}
// 获取地址链接
id, _ = item.Attr("href")
})
// 检查是否获取到
if id == "" {
err = fmt.Errorf("404 Not Found")
return
}
return id, err
}
// GetTitle 获取名称
func (s *TokyoHotScraper) GetTitle() string {
return s.root.Find(`.pagetitle h2`).Text()
}
// GetIntro 获取简介
func (s *TokyoHotScraper) GetIntro() string {
// 获取简介
intro, err := s.root.Find(`div.sentence`).Html()
// 检查错误
if err != nil {
return ""
}
return util.IntroFilter(intro)
}
// GetDirector 获取导演
func (s *TokyoHotScraper) GetDirector() string {
return util.TOKYOHOT
}
// GetRelease 发行时间
func (s *TokyoHotScraper) GetRelease() string {
return s.root.Find(`dt:contains("配信開始日")`).Next().Text()
}
// GetRuntime 获取时长
func (s *TokyoHotScraper) GetRuntime() string {
// 获取时长
strTime := strings.TrimSpace(s.root.Find(`dt:contains("収録時間"`).Next().Text())
// 是否正确获取
if strTime != "" {
// 搜索正则
r := regexp.MustCompile(`^(\d+):(\d+):(\d+)$`)
// 搜索
t := r.FindStringSubmatch(strTime)
// 获取小时
hour, err := strconv.Atoi(t[1])
// 检查
if err != nil {
hour = 0
}
// 获取分钟
minute, err := strconv.Atoi(t[2])
// 检查
if err != nil {
minute = 0
}
return strconv.Itoa((hour * 60) + minute)
}
return "0"
}
// GetStudio 获取厂商
func (s *TokyoHotScraper) GetStudio() string {
return "東京熱"
}
// GetSeries 获取系列
func (s *TokyoHotScraper) GetSeries() string {
return s.root.Find(`dt:contains("系列")`).Next().Find("a").Text()
}
// GetTags 获取标签
func (s *TokyoHotScraper) GetTags() []string {
// 标签数组
var tags []string
// 循环获取
s.root.Find(`dt:contains("Tag")`).Next().Find("a").Each(func(i int, item *goquery.Selection) {
tags = append(tags, strings.TrimSpace(item.Text()))
})
return tags
}
// GetCover 获取图片
func (s *TokyoHotScraper) GetCover() string {
// 获取图片
fanart, _ := s.root.Find(`.flowplayer video`).Attr("poster")
return fanart
}
// GetActors 获取演员
func (s *TokyoHotScraper) GetActors() map[string]string {
// 演员数组
actors := make(map[string]string)
// 循环获取
s.root.Find(`dt:contains("出演者")`).Next().Find("a").Each(func(i int, item *goquery.Selection) {
// 获取连接
link, _ := item.Attr("href")
// 组合地址
uri := fmt.Sprintf("https://my.tokyo-hot.com%s", link)
// 打开链接
root, err := util.GetRoot(uri, s.Proxy, nil)
// 检查错误
if err != nil {
return
}
// 获取演员图片
img, _ := item.Find(`#profile img`).Attr("src")
// 获取演员名字
actors[strings.TrimSpace(root.Find(`.pagetitle h2`).Text())] = strings.TrimSpace(img)
})
return actors
}
// GetURI 获取页面地址
func (s *TokyoHotScraper) GetURI() string {
return s.uri
}
// GetNumber 获取番号
func (s *TokyoHotScraper) GetNumber() string {
return s.number
}
// 获取样图
func (s *TokyoHotScraper) GetSample() []string {
// 获取图片
sample := []string{}
return sample
}