-
Notifications
You must be signed in to change notification settings - Fork 9
/
catalog.go
43 lines (34 loc) · 784 Bytes
/
catalog.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
package gulli
import (
"context"
"log"
"strings"
"github.com/gocolly/colly"
)
type ShowEntry struct {
Title string
URL string
ThumbURL string
}
var catalogURL = "https://replay.gulli.fr/"
func (p *Gulli) downloadCatalog(ctx context.Context) ([]ShowEntry, error) {
ctx, done := context.WithTimeout(ctx, p.deadline)
cat := []ShowEntry{}
defer done()
parser := p.htmlParserFactory.New()
parser.OnHTML("div.bloc_linkmore ul.multicolumn>li>a", func(e *colly.HTMLElement) {
entry := ShowEntry{
Title: strings.TrimSpace(e.Text),
URL: e.Attr("href"),
}
cat = append(cat, entry)
})
if p.debug {
log.Println("[%s] Catalog url: %q", p.Name(), catalogURL)
}
err := parser.Visit(catalogURL)
if err != nil {
return nil, err
}
return cat, nil
}