DEPRECATION WARNING: this SDK is deprecated and will no longer be maintained. It has been replaced by the Go API client. Please use it instead.

https://github.com/apivideo/go-sdk

Installation

go get github.com/apivideo/go-sdk

Quick Start

For a more advanced usage you can checkout the rest of the documentation in the docs directory

package main

import (
    "fmt"
    "os"

    apivideosdk "github.com/apivideo/go-sdk"
)

func main() {
    //Connect to production environment
    client := apivideosdk.NewClient(os.Getenv("API_VIDEO_KEY"))

    //Alternatively, connect to the sandbox environment for testing
    client := apivideosdk.NewSandboxClient(os.Getenv("API_VIDEO_SANDBOX_KEY"))

    //List Videos
    //First create the url options for searching
    opts := &apivideosdk.VideoOpts{
        CurrentPage: 1,
        PageSize: 25,
        SortBy:    "publishedAt",
        SortOrder: "desc",
    }

    //Then call the List endpoint with the options
    result, err := client.Videos.List(opts)
    
    if err != nil {
        fmt.Println(err)
    }

    for _, video := range result.Data {
        fmt.Printf("%s\n", video.VideoID)
        fmt.Printf("%s\n", video.Title)
    }

    //Upload a video
    //First create a container
    videoRequest := &apivideosdk.VideoRequest{
        Title: "My video title",
    }
    newVideo, err := client.Videos.Create(videoRequest)
    if err != nil {
        fmt.Println(err)
    }

    //Then upload your video to the container with the videoID
    uploadedVideo, err := client.Videos.Upload(newVideo.VideoID, "path/to/video.mp4")
    if err != nil {
        fmt.Println(err)
    }

    //And get the assets
    
    ```
    fmt.Printf("%s\n", uploadedVideo.Assets.Hls)
    fmt.Printf("%s\n", uploadedVideo.Assets.Iframe)
}

##Videos
```go

//List videos
opts := &apivideosdk.VideoOpts{
    CurrentPage: 1,
    PageSize: 25,
    SortBy:    "publishedAt",
    SortOrder: "desc",
    Tags:     []string{"tag1", "tag2"},
    Metadata: map[string]string{"key": "value"},
}

r, err := client.Videos.List(opts)

//Get one video
r, err := client.Videos.Get("videoID")

//Create a video container
videoRequest := &apivideosdk.VideoRequest{
    Title: "My video title",
    Tags:     []string{"tag1", "tag2"},
    Metadata: map[string]string{"key": "value"},
}
v, err := client.Videos.Create(videoRequest)

//Upload a video to a container
//The upload will be automatically chuncked if the file is more than 128MB
v, err := c.Videos.Upload("videoID", "path/to/video.mp4")

//Update a video
videoRequest := &apivideosdk.VideoRequest{
    Title: "My updated video title",
}
v, err := client.Videos.Update(videoRequest)

//Delete a video
err := client.Videos.Delete("videoID")

//Get video encoding status
v, err := client.Videos.Status("videoID")

//Pick a thumnail with a timecode
v, err := c.Videos.PickThumbnail("videoID", "00:01:12:12")

//Upload a thumnail 
v, err := c.Videos.UploadThumbnail("videoID", "path/to/thumbnail.jpg")

Live Streaming

//List livestreams
opts := &apivideosdk.LivestreamOpts{
    CurrentPage: 1,
    PageSize:    25,
    StreamKey:   "stream-key",
}
l, err := client.Livestreams.List(opts)

//Get one livestream
l, err := client.Livestreams.Get("livestreamID")

//Create a livestream
livestreamRequest := &apivideosdk.LivestreamRequest{
    Name: "My livetream name",
    Record: false
}
l, err := client.Livestreams.Create(livestreamRequest)

//Update a livestream
livestreamRequest := &apivideosdk.LivestreamRequest{
    Name: "My updated livetream name"
}
l, err := client.Livestreams.Update(livestreamRequest)

//Delete a livestream
err := client.Livestreams.Delete("livestreamID")

//Upload a thumbnail
l, err := client.Livestreams.UploadThumbnail("livestreamID", "path/to/thumbnail.jpg")

//Delete a thumbnail
l, err := client.Livestreams.DeleteThumbnail("livestreamID")

Captions

//List captions for a video
c, err := client.Captions.List("videoID")

//Get one caption
c, err := client.Captions.Get("videoID", "en")

//Upload a caption file
c, err := client.Captions.Upload("videoID", "en", "path/to/caption.vtt")

//Update a caption default status
captionRequest := &apivideosdk.CaptionRequest{
    Default: true,
}
c, err := client.Captions.Update("videoID", "en", captionRequest)

//Delete a caption
err := client.Captions.Delete("videoID", "en")

Chapters

//List chapters for a video
c, err := client.Chapters.List("videoID")

//Get one chapter
c, err := client.Chapters.Get("videoID", "en")

//Upload a chapter file
c, err := client.Chapters.Upload("videoID", "en", "path/to/chapter.vtt")

//Delete a chapter
err := client.Chapters.Delete("videoID", "en")

Players

//List Players
opts := &apivideosdk.PlayerOpts{
    CurrentPage: 1,
    PageSize:    25,
}
p, err := client.Players.List(opts)

//Get one player
p, err := client.Players.Get("playerID")

//Create a player
playerRequest := &apivideosdk.PlayerRequest{
    ShapeMargin:           3,
    ShapeRadius:           10,
    ShapeAspect:           "flat",
    ShapeBackgroundBottom: "rgba(255, 0, 0, 0.95)",
    ShapeBackgroundTop:    "rgba(255, 0, 0, 0.95)",
    Text:                  "rgba(255, 0, 0, 0.95)",
    Link:                  "rgba(255, 0, 0, 0.95)",
    LinkHover:             "rgba(255, 0, 0, 0.95)",
    LinkActive:            "rgba(255, 0, 0, 0.95)",
    TrackPlayed:           "rgba(255, 0, 0, 0.95)",
    TrackUnplayed:         "rgba(255, 0, 0, 0.95)",
    TrackBackground:       "rgba(255, 0, 0, 0.95)",
    BackgroundTop:         "rgba(255, 0, 0, 0.95)",
    BackgroundBottom:      "rgba(255, 0, 0, 0.95)",
    BackgroundText:        "rgba(255, 0, 0, 0.95)",
    EnableAPI:             false,
    EnableControls:        true,
    ForceAutoplay:         false,
    HideTitle:             false,
}
p, err := client.Players.Create(playerRequest)

//Update a player
playerRequest := &apivideosdk.PlayerRequest{
    ShapeMargin:           3,
    ShapeRadius:           10,
    ShapeAspect:           "flat",
    ShapeBackgroundBottom: "rgba(255, 255, 0, 0.95)",
    ShapeBackgroundTop:    "rgba(255, 255, 0, 0.95)",
    Text:                  "rgba(255, 255, 0, 0.95)",
    Link:                  "rgba(255, 255, 0, 0.95)",
    LinkHover:             "rgba(255, 255, 0, 0.95)",
    LinkActive:            "rgba(255, 255, 0, 0.95)",
    TrackPlayed:           "rgba(255, 255, 0, 0.95)",
    TrackUnplayed:         "rgba(255, 255, 0, 0.95)",
    TrackBackground:       "rgba(255, 255, 0, 0.95)",
    BackgroundTop:         "rgba(255, 255, 0, 0.95)",
    BackgroundBottom:      "rgba(255, 255, 0, 0.95)",
    BackgroundText:        "rgba(255, 255, 0, 0.95)",
    EnableAPI:             false,
    EnableControls:        true,
    ForceAutoplay:         false,
    HideTitle:             false,
}
p, err := client.Players.Update("playerID", playerRequest)

//Upload a logo for a player
p, err := c.Players.UploadLogo(
    "playerID", 
    "logoLinkURL",
    "path/to/logo.jpg"
)

//Delete a player
err := client.Players.Delete("playerID")

//Delete a player logo
err := client.Players.DeleteLogo("playerID")

Statistics and Analytics

//Get sessions statistics for one video
opts := &apivideosdk.SessionVideoOpts{
    CurrentPage: 1,
    PageSize: 25,
    Period: "2019-12-02",
}
s, err := client.Statistics.GetVideoSessions("videoID", opts)

//Get sessions statistics for one livestream
opts := &apivideosdk.SessionLivestreamOpts{
    CurrentPage: 1,
    PageSize: 25,
    Period: "2019-12-02",
}
s, err := client.Statistics.GetLivestreamSessions("livestreamID", opts)

//Get all events for one session
opts := &apivideosdk.SessionEventOpts{
    CurrentPage: 1,
    PageSize:    25,
}
s, err := client.Statistics.GetSessionEvents("sessionID", opts)

Did this page help you?