-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescription.go
35 lines (31 loc) · 900 Bytes
/
description.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
package main
import (
"errors"
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
)
func parseDescription(video *Video, document *goquery.Document) error {
video.Description = ""
desc := document.Find("#eow-description").Contents()
desc.Each(func(i int, s *goquery.Selection) {
switch s.Nodes[0].Type {
case html.TextNode:
video.Description += s.Text()
case html.ElementNode:
switch s.Nodes[0].Data {
case "a":
video.Description += s.Text()
case "br":
video.Description += "\n"
default:
video.Description = "unknown data type when parsing description, cancelation"
}
default:
video.Description = "unknown data type when parsing description, cancelation"
}
})
if video.Description == "unknown data type when parsing description, cancelation" {
return errors.New("unknown data type when parsing description, cancelation")
}
return nil
}