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_episode.go
69 lines (58 loc) · 1.82 KB
/
anime_episode.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
package anime
import (
"strings"
"time"
"github.com/PuerkitoBio/goquery"
"github.com/rl404/go-malscraper/model"
"github.com/rl404/go-malscraper/pkg/utils"
)
type episode struct {
area *goquery.Selection
cleanVideo bool
data []model.Episode
}
// GetEpisode to get anime episode list.
func (p *parser) GetEpisodes(a *goquery.Selection) []model.Episode {
v := episode{area: a, cleanVideo: p.cleanVid}
v.setDetail()
return v.data
}
func (e *episode) setDetail() {
epList := []model.Episode{}
e.area.Find("table.episode_list").First().Find(".episode-list-data").Each(func(i int, eachEp *goquery.Selection) {
epList = append(epList, model.Episode{
Episode: e.getEpisode(eachEp),
Link: e.getLink(eachEp),
Title: e.getTitle(eachEp),
JapaneseTitle: e.getJapaneseTitle(eachEp),
AiredDate: e.getAired(eachEp),
Tag: e.getTag(eachEp),
})
})
e.data = epList
}
func (e *episode) getEpisode(eachEp *goquery.Selection) int {
return utils.StrToNum(eachEp.Find(".episode-number").Text())
}
func (e *episode) getLink(eachEp *goquery.Selection) string {
link, _ := eachEp.Find(".episode-video a").First().Attr("href")
return link
}
func (e *episode) getTitle(eachEp *goquery.Selection) string {
return eachEp.Find(".episode-title").First().Find("a").First().Text()
}
func (e *episode) getJapaneseTitle(eachEp *goquery.Selection) string {
return strings.TrimSpace(eachEp.Find(".episode-title span:last-child").Text())
}
func (e *episode) getAired(eachEp *goquery.Selection) *time.Time {
aired := eachEp.Find(".episode-aired").Text()
aired = strings.Replace(aired, "N/A", "", -1)
at, valid := utils.StrToTime(aired)
if !valid {
return nil
}
return &at
}
func (e *episode) getTag(eachEp *goquery.Selection) string {
return eachEp.Find("span.icon-episode-type-bg").Text()
}