diff --git a/api/params/video.go b/api/params/video.go index da2f1bef..2e68b08d 100644 --- a/api/params/video.go +++ b/api/params/video.go @@ -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 +} diff --git a/api/params/video_test.go b/api/params/video_test.go index 9a55d010..d2738834 100644 --- a/api/params/video_test.go +++ b/api/params/video_test.go @@ -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) +} diff --git a/api/video.go b/api/video.go index b6e85b9a..01b7f83e 100644 --- a/api/video.go +++ b/api/video.go @@ -235,6 +235,17 @@ func (vk *VK) VideoGetCommentsExtended(params Params) (response VideoGetComments return } +// VideoLiveGetCategoriesResponse struct. +type VideoLiveGetCategoriesResponse []object.VideoLiveCategory + +// VideoLiveGetCategories method. +// +// https://vk.com/dev/video.liveGetCategories +func (vk *VK) VideoLiveGetCategories(params Params) (response VideoLiveGetCategoriesResponse, err error) { + err = vk.RequestUnmarshal("video.liveGetCategories", &response, params) + return +} + // VideoRemoveFromAlbum allows you to remove the video from the album. // // https://vk.com/dev/video.removeFromAlbum @@ -336,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 +} diff --git a/api/video_test.go b/api/video_test.go index 6d1001fb..19d4470f 100644 --- a/api/video_test.go +++ b/api/video_test.go @@ -264,6 +264,17 @@ func TestVK_VideoGetCommentsExtended(t *testing.T) { assert.NotEmpty(t, res.Profiles) } +func TestVK_VideoLiveGetCategories(t *testing.T) { + t.Parallel() + + needUserToken(t) + + res, err := vkUser.VideoLiveGetCategories(nil) + noError(t, err) + + assert.NotEmpty(t, res) +} + func TestVK_VideoReport(t *testing.T) { t.Parallel() @@ -315,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) +} diff --git a/doc.go b/doc.go index 9d70254e..3e3c12a1 100644 --- a/doc.go +++ b/doc.go @@ -7,6 +7,6 @@ package vksdk // Module constants. const ( - Version = "2.13.1" + Version = "2.14.0" API = "5.131" ) diff --git a/object/video.go b/object/video.go index 6c48224b..d86143a9 100644 --- a/object/video.go +++ b/object/video.go @@ -297,3 +297,27 @@ type VideoVideoImage struct { BaseImage 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"` + Label string `json:"label"` + Sublist []VideoLiveCategory `json:"sublist,omitempty"` +}