forked from ylqjgm/AVMeta
/
siro.go
167 lines (139 loc) · 3.8 KB
/
siro.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
package scraper
import (
"fmt"
"net/http"
"strings"
"time"
"github.com/cute-angelia/AVMeta/pkg/util"
"github.com/PuerkitoBio/goquery"
)
// SiroScraper siro网站刮削器
type SiroScraper struct {
Proxy string // 代理配置
uri string // 页面地址
number string // 最终番号
root *goquery.Document // 根节点
}
// NewSiroScraper 返回一个被初始化的siro刮削对象
//
// proxy 字符串参数,传入代理信息
func NewSiroScraper(proxy string) *SiroScraper {
return &SiroScraper{Proxy: proxy}
}
// Fetch 刮削
func (s *SiroScraper) Fetch(code string) error {
// 设置番号
s.number = strings.ToUpper(code)
// 定义Cookies
var cookies []*http.Cookie
// 加入Cookie
cookies = append(cookies, &http.Cookie{
Name: "adc",
Value: "1",
Path: "/",
Domain: "mgstage.com",
Expires: time.Now().Add(1 * time.Hour),
})
// 组合地址
uri := fmt.Sprintf("https://www.mgstage.com/product/product_detail/%s/", s.number)
// 打开链接
root, err := util.GetRoot(uri, s.Proxy, cookies)
// 检查
if err != nil {
return err
}
// 设置页面地址
s.uri = uri
// 设置根节点
s.root = root
return nil
}
// GetTitle 获取名称
func (s *SiroScraper) GetTitle() string {
return s.root.Find(`h1.tag`).Text()
}
// GetIntro 获取简介
func (s *SiroScraper) GetIntro() string {
return util.IntroFilter(s.root.Find(`#introduction p.introduction`).Text())
}
// GetDirector 获取导演
func (s *SiroScraper) GetDirector() string {
return ""
}
// GetRelease 发行时间
func (s *SiroScraper) GetRelease() string {
return s.root.Find(`th:contains("配信開始日")`).NextFiltered("td").Text()
}
// GetRuntime 获取时长
func (s *SiroScraper) GetRuntime() string {
return strings.TrimRight(s.root.Find(`th:contains("収録時間")`).NextFiltered("td").Text(), "min")
}
// GetStudio 获取厂商
func (s *SiroScraper) GetStudio() string {
val := s.root.Find(`th:contains("メーカー")`).NextFiltered("td").Text()
if val == "" {
val = s.root.Find(`th:contains("メーカー")`).NextFiltered("td").Find("a").Text()
}
return val
}
// GetSeries 获取系列
func (s *SiroScraper) GetSeries() string {
val := s.root.Find(`th:contains("シリーズ")`).NextFiltered("td").Text()
if val=="" {
val=s.root.Find(`th:contains("シリーズ")`).NextFiltered("td").Find("a").Text()
}
return val
}
// GetTags 获取标签
func (s *SiroScraper) GetTags() []string {
// 标签数组
var tags []string
// 循环获取
s.root.Find(`th:contains("ジャンル")`).NextFiltered("td").Find("a").Each(func(i int, item *goquery.Selection) {
tags = append(tags, strings.TrimSpace(item.Text()))
})
return tags
}
// GetCover 获取图片
func (s *SiroScraper) GetCover() string {
// 获取图片
fanart, _ := s.root.Find(`#EnlargeImage`).Attr("href")
return fanart
}
// GetActors 获取演员
func (s *SiroScraper) GetActors() map[string]string {
// 演员数组
actors := make(map[string]string)
// 循环获取
s.root.Find(`th:contains("出演")`).NextFiltered("td").Find("a").Each(func(i int, item *goquery.Selection) {
// 演员名字
actors[strings.TrimSpace(item.Text())] = ""
})
// 是否获取到
if len(actors) == 0 {
// 重新获取
name := s.root.Find(`th:contains("出演")`).NextFiltered("td").Text()
// 获取演员名字
actors[strings.TrimSpace(name)] = ""
}
return actors
}
// GetURI 获取页面地址
func (s *SiroScraper) GetURI() string {
return s.uri
}
// GetNumber 获取番号
func (s *SiroScraper) GetNumber() string {
return s.number
}
// 获取样图
func (s *SiroScraper) GetSample() []string {
// 获取图片
sample := []string{}
s.root.Find(`a.sample_image`).Each(func(i int, selection *goquery.Selection) {
if v, ok := selection.Attr("href"); ok {
sample = append(sample, v)
}
})
return sample
}