forked from aliforever/gista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tv.go
58 lines (51 loc) · 1.12 KB
/
tv.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
package gista
import (
"regexp"
"github.com/aliforever/gista/constants"
"github.com/aliforever/gista/errs"
"github.com/aliforever/gista/responses"
)
type tv struct {
ig *Instagram
}
func newTv(i *Instagram) *tv {
return &tv{ig: i}
}
/**
* Get channel.
*
* You can filter the channel with different IDs: "for_you", "chrono_following", "popular", "continue_watching"
* and using a user ID in the following format: "user_1234567891".
*
*/
func (tv *tv) GetChannel(id string, maxId *string) (res *responses.TVChannels, err error) {
res = &responses.TVChannels{}
found := false
allowed := []string{"for_you", "chrono_following", "popular", "continue_watching"}
for _, item := range allowed {
if item == id {
found = true
break
}
}
if !found {
r := regexp.MustCompile(`^user_[1-9]\d*$`)
if r.MatchString(id) {
found = true
}
}
if !found {
err = errs.InvalidIdForIgtv(id)
return
}
req := tv.ig.client.Request(constants.GetIGTVChannel).
AddPost("id", id).
AddUIdPost().
AddUuIdPost().
AddCSRFPost()
if maxId != nil {
req.AddPost("max_id", *maxId)
}
err = req.GetResponse(res)
return
}