-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmedia.go
86 lines (79 loc) · 2.34 KB
/
media.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
85
86
package elevengo
import (
"context"
"github.com/deadblue/elevengo/internal/util"
"github.com/deadblue/elevengo/lowlevel/api"
"github.com/deadblue/elevengo/lowlevel/errors"
)
// VideoDefinition values from 115.
type VideoDefinition int
const (
// Standard Definition, aka. 480P.
VideoDefinitionSD VideoDefinition = 1
// High Definition, aka. 720P.
VideoDefinitionHD VideoDefinition = 2
// Full-HD, aka. 1080P.
VideoDefinitionFHD VideoDefinition = 3
// Another 1080P, what the fuck?
VideoDefinition1080P VideoDefinition = 4
// 4K Definition, aka. Ultra-HD.
VideoDefinition4K VideoDefinition = 5
// The fallback definition, usually for non-standard resolution.
VideoDefinitionOrigin VideoDefinition = 100
)
// VideoTicket contains all required arguments to play a cloud video.
type VideoTicket struct {
// Play URL, it is normally a m3u8 URL.
Url string
// Request headers which SHOULD be sent with play URL.
Headers map[string]string
// File name.
FileName string
// File size.
FileSize int64
// Video duration in seconds.
Duration float64
// Video width.
Width int
// Video height.
Height int
}
// VideoCreateTicket creates a PlayTicket to play the cloud video.
func (a *Agent) VideoCreateTicket(pickcode string, ticket *VideoTicket) (err error) {
if !a.isWeb {
return errors.ErrUnsupportedPlatform
}
spec := (&api.VideoPlayWebSpec{}).Init(pickcode)
if err = a.llc.CallApi(spec, context.Background()); err != nil {
return
}
if !spec.Result.IsReady {
return errors.ErrVideoNotReady
}
ticket.FileName = spec.Result.FileName
ticket.FileSize = spec.Result.FileSize
ticket.Duration = spec.Result.VideoDuration
// Select the video with best definition
for _, video := range spec.Result.Videos {
if video.Width > ticket.Width {
ticket.Width = video.Width
ticket.Height = video.Height
ticket.Url = video.PlayUrl
}
}
ticket.Headers = map[string]string{
"User-Agent": a.llc.GetUserAgent(),
"Cookie": util.MarshalCookies(a.llc.ExportCookies(ticket.Url)),
}
return
}
// ImageGetUrl gets an accessible URL of an image file by its pickcode.
func (a *Agent) ImageGetUrl(pickcode string) (imageUrl string, err error) {
spec := (&api.ImageGetSpec{}).Init(pickcode)
if err = a.llc.CallApi(spec, context.Background()); err != nil {
return
}
// The origin URL can be access without cookie.
imageUrl = spec.Result.OriginUrl
return
}