/
types.go
61 lines (51 loc) · 1.26 KB
/
types.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
package video
import (
"fmt"
"os"
)
// ChannelMessage used to exchange between a main thread and goroutines.
type ChannelMessage struct {
Result *Video
Err error
Link string
}
func (msg ChannelMessage) String() string {
if msg.Err != nil {
return fmt.Sprintf("result=%v err=%v", msg.Result, msg.Err)
}
return fmt.Sprintf("Result: %#v", msg.Result)
}
// ErrorBadLink link is not valid.
type ErrorBadLink struct {
link string
message string
}
func (e *ErrorBadLink) Error() string {
return fmt.Sprintf("Link %q %v", e.link, e.message)
}
// ErrorFetchPlaybackURL video stream URL can't be fetched/found.
type ErrorFetchPlaybackURL struct {
link string
message string
}
func (e *ErrorFetchPlaybackURL) Error() string {
return fmt.Sprintf("Failed to get a stream URL for the link %q reason: %q", e.link, e.message)
}
// Video internal video object.
type Video struct {
url string
streamUrl string
name string
mimeType string
File *os.File
AudioFilePath string
}
func (v Video) String() string {
return fmt.Sprintf(
"<name=%q url=%q hasStream=%v mime=%v file=%v audio=%v>",
v.name, v.url, v.HasStreamURL(), v.mimeType, *v.File, v.AudioFilePath,
)
}
func (v Video) HasStreamURL() bool {
return v.streamUrl != ""
}