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_video.go
70 lines (60 loc) · 1.9 KB
/
anime_video.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 anime
import (
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/rl404/go-malscraper/model"
"github.com/rl404/go-malscraper/pkg/utils"
)
type video struct {
area *goquery.Selection
cleanVideo bool
data model.Video
}
// GetVideos to get anime video list.
func (p *parser) GetVideos(a *goquery.Selection) *model.Video {
v := video{area: a, cleanVideo: p.cleanVid}
v.setEpisode()
v.setPromotion()
return &v.data
}
func (v *video) setEpisode() {
episodeList := []model.VideoEpisode{}
v.area.Find(".episode-video").Find(".video-list-outer").Each(func(i int, eachEpisode *goquery.Selection) {
linkArea := eachEpisode.Find("a").First()
link, _ := linkArea.Attr("href")
episodeList = append(episodeList, model.VideoEpisode{
Title: v.getEpisodeTitle(linkArea),
Episode: v.getEpisodeNo(linkArea),
Link: link,
})
})
v.data.Episodes = episodeList
}
func (v *video) getEpisodeTitle(linkArea *goquery.Selection) string {
return linkArea.Find("span.title span").Text()
}
func (v *video) getEpisodeNo(linkArea *goquery.Selection) int {
linkArea.Find("span.title").Find("span").Remove()
episode := linkArea.Find("span.title").Text()
episode = strings.Replace(episode, "Episode", "", -1)
return utils.StrToNum(episode)
}
func (v *video) setPromotion() {
promoList := []model.VideoPromo{}
area := v.area.Find(".promotional-video")
area.Find(".video-list-outer").Each(func(i int, eachPromo *goquery.Selection) {
linkArea := eachPromo.Find("a").First()
promoList = append(promoList, model.VideoPromo{
Title: v.getPromoTitle(linkArea),
Link: v.getPromoLink(linkArea),
})
})
v.data.Promotions = promoList
}
func (v *video) getPromoTitle(linkArea *goquery.Selection) string {
return linkArea.Find("span.title").Text()
}
func (v *video) getPromoLink(linkArea *goquery.Selection) string {
link, _ := linkArea.Attr("href")
return utils.URLCleaner(link, "video", v.cleanVideo)
}