-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
video.go
101 lines (85 loc) · 2.8 KB
/
video.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package message
import (
"context"
"time"
"github.com/gotd/td/tg"
)
// Video creates new VideoDocumentBuilder to create video attachment.
func (u *UploadedDocumentBuilder) Video() *VideoDocumentBuilder {
b := u
if u.doc.MimeType == "" {
b = u.MIME(DefaultVideoMIME)
}
return &VideoDocumentBuilder{
doc: b,
attr: tg.DocumentAttributeVideo{},
}
}
// RoundVideo creates new VideoDocumentBuilder to create round video attachment.
func (u *UploadedDocumentBuilder) RoundVideo() *VideoDocumentBuilder {
return u.Video().Round()
}
// VideoDocumentBuilder is a Video media option.
type VideoDocumentBuilder struct {
doc *UploadedDocumentBuilder
attr tg.DocumentAttributeVideo
}
// Round sets flag to mark this video as round.
func (u *VideoDocumentBuilder) Round() *VideoDocumentBuilder {
u.attr.RoundMessage = true
return u
}
// SupportsStreaming sets flag to mark this video as which supports streaming.
func (u *VideoDocumentBuilder) SupportsStreaming() *VideoDocumentBuilder {
u.attr.SupportsStreaming = true
return u
}
// Resolution sets resolution of this video.
func (u *VideoDocumentBuilder) Resolution(w, h int) *VideoDocumentBuilder {
u.attr.W = w
u.attr.H = h
return u
}
// Duration sets duration of video file.
func (u *VideoDocumentBuilder) Duration(duration time.Duration) *VideoDocumentBuilder {
u.attr.Duration = duration.Seconds()
return u
}
// DurationSeconds sets duration in seconds.
//
// Deprecated: Use Duration instead. Telegram now supports fractional seconds.
func (u *VideoDocumentBuilder) DurationSeconds(duration int) *VideoDocumentBuilder {
u.attr.Duration = float64(duration)
return u
}
// apply implements MediaOption.
func (u *VideoDocumentBuilder) apply(ctx context.Context, b *multiMediaBuilder) error {
return u.doc.Attributes(&u.attr).apply(ctx, b)
}
// applyMulti implements MultiMediaOption.
func (u *VideoDocumentBuilder) applyMulti(ctx context.Context, b *multiMediaBuilder) error {
return u.doc.Attributes(&u.attr).applyMulti(ctx, b)
}
// Video adds video attachment.
func Video(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder {
// TODO(tdakkota): better MIME and attributes building.
return UploadedDocument(file, caption...).Video()
}
// RoundVideo adds round video attachment.
func RoundVideo(file tg.InputFileClass, caption ...StyledTextOption) *VideoDocumentBuilder {
return UploadedDocument(file, caption...).RoundVideo()
}
// Video sends video.
func (b *Builder) Video(
ctx context.Context,
file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error) {
return b.Media(ctx, Video(file, caption...))
}
// RoundVideo sends round video.
func (b *Builder) RoundVideo(
ctx context.Context,
file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error) {
return b.Media(ctx, RoundVideo(file, caption...))
}