-
Notifications
You must be signed in to change notification settings - Fork 1
/
truyentranh.go
executable file
·60 lines (49 loc) · 1.18 KB
/
truyentranh.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
package truyentranh
import (
"fmt"
"github.com/gocolly/colly"
"github.com/vqhuy/kindle-manga/bot"
)
func init() {
bot.Register(&collector{
Bot: &bot.Bot{},
})
}
type collector struct {
*bot.Bot
}
var _ bot.Collector = (*collector)(nil)
func (b *collector) Page() string {
return "http://truyentranh.net/"
}
func (b *collector) GetLink(base string, chap int) string {
return fmt.Sprintf("%s/Chap-%03d/", base, chap)
}
func (b *collector) Collect(base string, chap int, outputDir string) error {
b.Colly = colly.NewCollector()
b.Colly.OnHTML(`#viewer`, func(e *colly.HTMLElement) {
e.ForEach("img", func(i int, ee *colly.HTMLElement) {
link := ee.Attr("src")
b.Visit(link)
})
})
b.Colly.OnHTML(`div.each-page`, func(e *colly.HTMLElement) {
e.ForEach("img", func(i int, ee *colly.HTMLElement) {
link := ee.Attr("src")
b.Visit(link)
})
})
b.Colly.OnHTML(`div.OtherText`, func(e *colly.HTMLElement) {
e.ForEach("img", func(i int, ee *colly.HTMLElement) {
link := ee.Attr("src")
b.Visit(link)
})
})
b.Bot.Collect(base, chap, outputDir)
link := b.GetLink(base, chap)
if link == "" {
return bot.ErrorChapNotFound
}
b.Colly.Visit(link)
return nil
}