-
Notifications
You must be signed in to change notification settings - Fork 25
/
list.go
84 lines (58 loc) · 2.11 KB
/
list.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package youtube
import (
"bytes"
"encoding/csv"
"github.com/lithdew/bytesutil"
"github.com/valyala/fastjson"
"time"
)
type ListItem struct {
ID StreamID `json:"encrypted_id"`
Title string `json:"title"`
Description string `json:"description"`
Thumbnail string `json:"thumbnail"`
Added string `json:"added"`
TimeCreated time.Time `json:"time_created"`
Rating float64 `json:"rating"`
Likes uint `json:"likes"`
Dislikes uint `json:"dislikes"`
Views string `json:"views"`
Comments string `json:"comments"`
Duration string `json:"duration"`
LengthSeconds time.Duration `json:"length_seconds"`
Author string `json:"author"`
UserID string `json:"user_id"`
Privacy string `json:"privacy"`
CategoryID uint `json:"category_id"`
IsHD bool `json:"is_hd"`
IsCC bool `json:"is_cc"`
CCLicense bool `json:"cc_license"`
Keywords []string `json:"keywords"`
}
func ParseListItem(v *fastjson.Value) ListItem {
var r ListItem
r.ID = StreamID(bytesutil.String(v.GetStringBytes("encrypted_id")))
r.Title = bytesutil.String(v.GetStringBytes("title"))
r.Description = bytesutil.String(v.GetStringBytes("description"))
r.Thumbnail = bytesutil.String(v.GetStringBytes("thumbnail"))
r.Added = bytesutil.String(v.GetStringBytes("added"))
r.TimeCreated = time.Unix(v.GetInt64("time_created"), 0)
r.Rating = v.GetFloat64("rating")
r.Likes = v.GetUint("likes")
r.Dislikes = v.GetUint("dislikes")
r.Views = bytesutil.String(v.GetStringBytes("views"))
r.Comments = bytesutil.String(v.GetStringBytes("comments"))
r.Duration = bytesutil.String(v.GetStringBytes("duration"))
r.LengthSeconds = time.Duration(v.GetInt64("length_seconds")) * time.Second
r.Author = bytesutil.String(v.GetStringBytes("author"))
r.UserID = bytesutil.String(v.GetStringBytes("user_id"))
r.Privacy = bytesutil.String(v.GetStringBytes("privacy"))
r.CategoryID = v.GetUint("category_id")
r.IsHD = v.GetBool("is_hd")
r.IsCC = v.GetBool("is_cc")
r.CCLicense = v.GetBool("cc_license")
fr := csv.NewReader(bytes.NewReader(v.GetStringBytes("keywords")))
fr.Comma = ' '
r.Keywords, _ = fr.Read()
return r
}