This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsession.go
60 lines (51 loc) · 1.61 KB
/
session.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 skillshare_dl
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
type Session struct {
ID int `json:"id"`
ParentClassSku int `json:"parent_class_sku"`
Title string `json:"title"`
VideoHashedID string `json:"video_hashed_id"`
}
type videoSourceInfo struct {
Sources []*Video `json:"sources"`
}
type Video struct {
Codecs string `json:"codecs,omitempty"`
ExtXVersion string `json:"ext_x_version,omitempty"`
Src string `json:"src"`
Type string `json:"type,omitempty"`
Profiles string `json:"profiles,omitempty"`
AvgBitrate int `json:"avg_bitrate,omitempty"`
Codec string `json:"codec,omitempty"`
Container string `json:"container,omitempty"`
Duration int `json:"duration,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
}
func (s *Session) Video(account, pk string) ([]*Video, error) {
vid := strings.Split(s.VideoHashedID, ":")[1]
url := fmt.Sprintf("https://edge.api.brightcove.com/playback/v1/accounts/%s/videos/%s", account, vid)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Add("Accept", fmt.Sprintf("application/json;pk=%s", pk))
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0")
req.Header.Add("Origin", "https://www.skillshare.com")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
vsi := &videoSourceInfo{}
err = json.NewDecoder(resp.Body).Decode(vsi)
if err != nil {
return nil, err
}
return vsi.Sources, nil
}