Skip to content

Commit

Permalink
feat: add video start & stop streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Apr 4, 2022
1 parent 2ba1dab commit 69e9790
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
102 changes: 102 additions & 0 deletions api/params/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,3 +1142,105 @@ func (b *VideoSearchBuilder) LegalOwner(v int) *VideoSearchBuilder {
b.Params["legal_owner"] = v
return b
}

// VideoStartStreamingBuilder builder.
//
// https://vk.com/dev/video.startStreaming
type VideoStartStreamingBuilder struct {
api.Params
}

// NewVideoStartStreamingBuilder func.
func NewVideoStartStreamingBuilder() *VideoStartStreamingBuilder {
return &VideoStartStreamingBuilder{api.Params{}}
}

// VideoID parameter.
func (b *VideoStartStreamingBuilder) VideoID(v int) *VideoStartStreamingBuilder {
b.Params["video_id"] = v
return b
}

// Name parameter.
func (b *VideoStartStreamingBuilder) Name(v string) *VideoStartStreamingBuilder {
b.Params["name"] = v
return b
}

// Description parameter.
func (b *VideoStartStreamingBuilder) Description(v string) *VideoStartStreamingBuilder {
b.Params["description"] = v
return b
}

// Wallpost parameter.
func (b *VideoStartStreamingBuilder) Wallpost(v bool) *VideoStartStreamingBuilder {
b.Params["wallpost"] = v
return b
}

// GroupID parameter.
func (b *VideoStartStreamingBuilder) GroupID(v int) *VideoStartStreamingBuilder {
b.Params["group_id"] = v
return b
}

// PrivacyView parameter.
func (b *VideoStartStreamingBuilder) PrivacyView(v []string) *VideoStartStreamingBuilder {
b.Params["privacy_view"] = v
return b
}

// PrivacyComment parameter.
func (b *VideoStartStreamingBuilder) PrivacyComment(v []string) *VideoStartStreamingBuilder {
b.Params["privacy_comment"] = v
return b
}

// NoComments parameter.
func (b *VideoStartStreamingBuilder) NoComments(v bool) *VideoStartStreamingBuilder {
b.Params["no_comments"] = v
return b
}

// CategoryID parameter.
func (b *VideoStartStreamingBuilder) CategoryID(v int) *VideoStartStreamingBuilder {
b.Params["category_id"] = v
return b
}

// Publish parameter.
func (b *VideoStartStreamingBuilder) Publish(v bool) *VideoStartStreamingBuilder {
b.Params["publish"] = v
return b
}

// VideoStopStreamingBuilder builder.
//
// https://vk.com/dev/video.stopStreaming
type VideoStopStreamingBuilder struct {
api.Params
}

// NewVideoStopStreamingBuilder func.
func NewVideoStopStreamingBuilder() *VideoStopStreamingBuilder {
return &VideoStopStreamingBuilder{api.Params{}}
}

// GroupID parameter.
func (b *VideoStopStreamingBuilder) GroupID(v int) *VideoStopStreamingBuilder {
b.Params["group_id"] = v
return b
}

// OwnerID parameter.
func (b *VideoStopStreamingBuilder) OwnerID(v int) *VideoStopStreamingBuilder {
b.Params["owner_id"] = v
return b
}

// VideoID parameter.
func (b *VideoStopStreamingBuilder) VideoID(v int) *VideoStopStreamingBuilder {
b.Params["video_id"] = v
return b
}
42 changes: 42 additions & 0 deletions api/params/video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,45 @@ func TestVideoSearchBuilder(t *testing.T) {
assert.Equal(t, b.Params["legal"], true)
assert.Equal(t, b.Params["legal_owner"], 1)
}

func TestVideoStartStreamingBuilder(t *testing.T) {
t.Parallel()

b := params.NewVideoStartStreamingBuilder()

b.VideoID(1)
b.Name("text")
b.Description("text")
b.Wallpost(true)
b.GroupID(1)
b.PrivacyView([]string{"text"})
b.PrivacyComment([]string{"text"})
b.NoComments(true)
b.CategoryID(1)
b.Publish(true)

assert.Equal(t, b.Params["video_id"], 1)
assert.Equal(t, b.Params["name"], "text")
assert.Equal(t, b.Params["description"], "text")
assert.Equal(t, b.Params["wallpost"], true)
assert.Equal(t, b.Params["group_id"], 1)
assert.Equal(t, b.Params["privacy_view"], []string{"text"})
assert.Equal(t, b.Params["privacy_comment"], []string{"text"})
assert.Equal(t, b.Params["no_comments"], true)
assert.Equal(t, b.Params["category_id"], 1)
assert.Equal(t, b.Params["publish"], true)
}

func TestVideoStopStreamingBuilder(t *testing.T) {
t.Parallel()

b := params.NewVideoStopStreamingBuilder()

b.GroupID(1)
b.OwnerID(1)
b.VideoID(1)

assert.Equal(t, b.Params["group_id"], 1)
assert.Equal(t, b.Params["owner_id"], 1)
assert.Equal(t, b.Params["video_id"], 1)
}
24 changes: 24 additions & 0 deletions api/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,27 @@ func (vk *VK) VideoSearchExtended(params Params) (response VideoSearchExtendedRe

return
}

// VideoStartStreamingResponse struct.
type VideoStartStreamingResponse object.VideoLive

// VideoStartStreaming method.
//
// https://vk.com/dev/video.startStreaming
func (vk *VK) VideoStartStreaming(params Params) (response VideoStartStreamingResponse, err error) {
err = vk.RequestUnmarshal("video.startStreaming", &response, params)
return
}

// VideoStopStreamingResponse struct.
type VideoStopStreamingResponse struct {
UniqueViewers int `json:"unique_viewers"`
}

// VideoStopStreaming method.
//
// https://vk.com/dev/video.stopStreaming
func (vk *VK) VideoStopStreaming(params Params) (response VideoStopStreamingResponse, err error) {
err = vk.RequestUnmarshal("video.stopStreaming", &response, params)
return
}
16 changes: 16 additions & 0 deletions api/video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,19 @@ func TestVK_VideoSearchExtended(t *testing.T) {
assert.NotEmpty(t, res.Count)
assert.NotEmpty(t, res.Items)
}

func TestVK_VideoStartStreaming(t *testing.T) {
t.Parallel()

needUserToken(t)

res, err := vkUser.VideoStartStreaming(nil)
noError(t, err)

assert.NotEmpty(t, res)

_, err = vkUser.VideoStopStreaming(api.Params{
"video_id": res.VideoID,
})
noError(t, err)
}
17 changes: 17 additions & 0 deletions object/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,23 @@ type VideoVideoImage struct {
WithPadding BaseBoolInt `json:"with_padding"`
}

// VideoLive struct.
type VideoLive struct {
OwnerID int `json:"owner_id"`
VideoID int `json:"video_id"`
Name string `json:"name"`
Description string `json:"description"`
AccessKey string `json:"access_key"`
Stream VideoLiveStream `json:"stream"`
}

// VideoLiveStream struct.
type VideoLiveStream struct {
URL string `json:"url"`
Key string `json:"key"`
OKMPURL string `json:"okmp_url"`
}

// VideoLiveCategory struct.
type VideoLiveCategory struct {
ID int `json:"id"`
Expand Down

0 comments on commit 69e9790

Please sign in to comment.