This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anime_staff.go
56 lines (48 loc) · 1.5 KB
/
anime_staff.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
package anime
import (
"github.com/PuerkitoBio/goquery"
"github.com/rl404/go-malscraper/model"
"github.com/rl404/go-malscraper/pkg/utils"
)
type staff struct {
area *goquery.Selection
cleanImg bool
data []model.Role
}
// GetStaff to get anime staff list.
func (p *parser) GetStaff(a *goquery.Selection) []model.Role {
c := staff{area: a, cleanImg: p.cleanImg}
c.setDetail()
return c.data
}
func (s *staff) setDetail() {
staffList := []model.Role{}
s.area.Find("article").Remove()
s.area.Find("h2").First().Remove()
staffArea := s.area.Find("h2").First().Parent().Next()
for goquery.NodeName(staffArea) == "table" {
staffNameArea := staffArea.Find("td:nth-of-type(2)")
staffList = append(staffList, model.Role{
ID: s.getID(staffNameArea),
Image: s.getImage(staffArea),
Name: s.getName(staffNameArea),
Role: s.getRole(staffNameArea),
})
staffArea = staffArea.Next()
}
s.data = staffList
}
func (s *staff) getID(charNameArea *goquery.Selection) int {
id, _ := charNameArea.Find("a").First().Attr("href")
return utils.StrToNum(utils.GetValueFromSplit(id, "/", 4))
}
func (s *staff) getImage(charArea *goquery.Selection) string {
image, _ := charArea.Find("td .picSurround img").Attr("data-src")
return utils.URLCleaner(image, "image", s.cleanImg)
}
func (s *staff) getName(charNameArea *goquery.Selection) string {
return charNameArea.Find("a").First().Text()
}
func (s *staff) getRole(charNameArea *goquery.Selection) string {
return charNameArea.Find("small").First().Text()
}