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
/
people_staff_manga.go
70 lines (55 loc) · 1.78 KB
/
people_staff_manga.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
package people
import (
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/rl404/go-malscraper/model"
"github.com/rl404/go-malscraper/pkg/utils"
)
type staffManga struct {
area *goquery.Selection
_type string
cleanImg bool
data []model.Role
}
// GetStaffManga to get people anime staff or published manga list.
func (p *parser) GetStaffManga(a *goquery.Selection, t string) []model.Role {
v := staffManga{area: a, cleanImg: p.cleanImg, _type: t}
v.setDetail()
return v.data
}
func (sm *staffManga) setDetail() {
list := []model.Role{}
area := sm.area.Find("#content table tr td").Next()
area.Find(".normal_header").First().Remove()
if sm._type == "manga" {
area.Find(".normal_header").First().Remove()
}
area = area.Find(".normal_header").First().Next()
if goquery.NodeName(area) == "table" {
area.Find("tr").Each(func(i int, staff *goquery.Selection) {
animeImageArea := staff.Find("td:nth-of-type(1)")
stArea := staff.Find("td:nth-of-type(2)")
list = append(list, model.Role{
ID: sm.getID(stArea),
Name: sm.getTitle(stArea),
Image: sm.getImage(animeImageArea),
Role: sm.getRole(stArea),
})
})
}
sm.data = list
}
func (sm *staffManga) getID(animeArea *goquery.Selection) int {
animeID, _ := animeArea.Find("a").Attr("href")
return utils.StrToNum(utils.GetValueFromSplit(animeID, "/", 4))
}
func (sm *staffManga) getImage(animeImageArea *goquery.Selection) string {
animeImage, _ := animeImageArea.Find("img").Attr("data-src")
return utils.URLCleaner(animeImage, "image", sm.cleanImg)
}
func (sm *staffManga) getTitle(animeArea *goquery.Selection) string {
return animeArea.Find("a").First().Text()
}
func (sm *staffManga) getRole(stArea *goquery.Selection) string {
return strings.TrimSpace(stArea.Find("small").Text())
}