Categorygithub.com/AIOZNetwork/w3stream-go-client
repositorypackage
1.0.8
Repository: https://github.com/aioznetwork/w3stream-go-client.git
Documentation: pkg.go.dev

# README

W3Stream Go client

W3Stream is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Project description

W3Stream's Go client streamlines the coding process. Chunking files is handled for you, as is pagination and refreshing your tokens.

Getting started

Installation

go get github.com/AIOZNetwork/w3stream-go-client

Code sample

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


import (
	"context"
	"fmt"
	"os"
 
	w3streamsdk "github.com/AIOZNetwork/w3stream-go-client"
)
 
func main() {
    // Connect to production environment
    publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
    secretKey := "YOUR_SECRET_KEY" // Replace with your actual API secret key
	apiCreds := w3streamsdk.AuthCredentials{
		PublicKey: publicKey,
		SecretKey: secretKey,
	}
    client := w3streamsdk.ClientBuilder(apiCreds).Build()
 
    // Create a video object
	title := "Sample Video Title"
	videoData := w3streamsdk.CreateVideoRequest{
		Title: &title,
	}
	createResult, err := client.Video.Create(videoData)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating video: %v\n", err)
		return
	}
 
    videoId := createResult.Data.Id // Get the video ID from the response
 
    // Open the video file
    videoFile, err := os.Open("./path/to/video.mp4")
    if err != nil {
        fmt.Println("Error opening video file:", err)
        return
    }
    defer videoFile.Close() // Close the file after use
 
    fileInfo, err := videoFile.Stat()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error getting file info: %v\n", err)
        return
    }
 
    fileSize := fileInfo.Size()
    fileName := fileInfo.Name()
 
    // Option 1: Use client upload with videoId
	err = client.UploadVideo(context.Background(), *videoId, fileName, videoFile, fileSize)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error uploading video with client: %v\n", err)
		return
	}
 
    // Option 2: Upload parts yourself
    // This example is commented out as you already used option 1
	//_, err = client.Video.UploadPart(*videoId, nil, nil, "./path/to/video.mp4", videoFile, fileInfo.Size())
	//if err != nil {
	//	fmt.Fprintf(os.Stderr, "Error uploading video part: %v\n", err)
	//	return
	//}
	//
	//success, err := client.Video.UploadVideoComplete(*videoId)
	//if err != nil {
	//	fmt.Fprintf(os.Stderr, "Error completing video upload: %v\n", err)
	//	return
	//}
	//
	//jsonString, err := json.MarshalIndent(success, "", "  ")
	//if err != nil {
	//	fmt.Fprintf(os.Stderr, "Error marshalling response: %v\n", err)
	//	return
	//}
	//fmt.Println(string(jsonString))
    fmt.Println("Video uploaded successfully!")
}

Documentation

API endpoints

All urls are relative to https://api.w3stream.xyz/api

ApiKey

Retrieve an instance of the ApiKey API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
apiKeyApi := client.ApiKey
Endpoints
MethodHTTP requestDescription
CreatePost /api_keysCreate API key
UpdatePatch /api_keys/{id}Rename api key
DeleteDelete /api_keys/{id}Delete API key
ListGet /api_keysGet list API keys

LiveStream

Retrieve an instance of the LiveStream API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
liveStreamApi := client.LiveStream
Endpoints
MethodHTTP requestDescription
CreateLiveStreamKeyPost /live_streamsCreate live stream key
CreateStreamingPost /live_streams/{id}/streamingsCreate a new live stream video
DeleteLiveStreamKeyDelete /live_streams/{id}Delete live stream key
DeleteStreamingDelete /live_streams/{id}/streamings/{stream_id}Delete live stream video
GetLiveStreamKeyGet /live_streams/{id}Get live stream key
GetLiveStreamKeysGet /live_streamsGet live stream key list
GetLiveStreamPlayerInfoGet /live_streams/player/{id}/videosGet live stream video public
GetLiveStreamVideoGet /live_streams/{id}/videosGet live stream video
GetLiveStreamVideosPost /live_streams/{id}/videosGet live stream videos
GetStreamingGet /live_streams/{id}/streamings/{stream_id}Get live stream video streaming
GetStreamingsGet /live_streams/{id}/streamingsGet live stream video streamings
UpdateLiveStreamKeyPut /live_streams/{id}Update live stream key
UpdateLiveStreamVideoPut /live_streams/{id}/streamingsUpdate live stream video

Players

Retrieve an instance of the Players API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
playersApi := client.Players
Endpoints
MethodHTTP requestDescription
CreatePost /playersCreate a player theme
GetGet /players/{id}Get a player theme by ID
UpdatePatch /players/{id}Update a player theme by ID
DeleteDelete /players/{id}Delete a player theme by ID
ListGet /playersList all player themes
UploadLogoPost /players/{id}/logoUpload a logo for a player theme by ID
DeleteLogoDelete /players/{id}/logoDelete a logo for a player theme by ID
AddPlayerPost /players/add-playerAdd a player theme to a video
RemovePlayerPost /players/remove-playerRemove a player theme from a video

Playlist

Retrieve an instance of the Playlist API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
playlistApi := client.Playlist
Endpoints
MethodHTTP requestDescription
AddVideoToPlaylistPost /playlists/{id}/itemsAdd a video to a playlist
CreatePlaylistPost /playlists/createCreate a playlist
DeletePlaylistByIdDelete /playlists/{id}Delete a playlist by ID
DeletePlaylistThumbnailDelete /playlists/{id}/thumbnailDelete a playlist thumbnail
GetPlaylistByIdGet /playlists/{id}Get playlist by ID
GetPlaylistPublicInfoGet /playlists/{id}/player.jsonGet a playlist public
GetPlaylistsPost /playlistsGet user's playlists
MoveVideoInPlaylistPut /playlists/{id}/itemsMove a video in a playlist
RemoveVideoFromPlaylistDelete /playlists/{id}/items/{item_id}Remove a video from a playlist
UpdatePlaylistPatch /playlists/{id}Update a playlist

Video

Retrieve an instance of the Video API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
videoApi := client.Video
Endpoints
MethodHTTP requestDescription
CreatePost /videos/createCreate video object
UpdatePatch /videos/{id}update video info
DeleteDelete /videos/{id}Delete video
UploadThumbnailPost /videos/{id}/thumbnailUpload video thumbnail
CreateCaptionPost /videos/{id}/captions/{lan}Create a new video caption
DeleteCaptionDelete /videos/{id}/captions/{lan}Delete a video caption
GetCaptionsGet /videos/{id}/captionsGet video captions
GetCostGet /videos/costget video transcoding cost
GetDetailGet /videos/{id}get video detail
GetVideoListPost /videosGet user videos list
GetVideoPlayerInfoGet /videos/{id}/player.jsonGet video player info
SetDefaultCaptionPatch /videos/{id}/captions/{lan}Set default caption
UploadPartPost /videos/{id}/partUpload part of video
UploadVideoCompleteGet /videos/{id}/completeGet upload video when complete

VideoChapter

Retrieve an instance of the VideoChapter API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
videoChapterApi := client.VideoChapter
Endpoints
MethodHTTP requestDescription
CreatePost /videos/{id}/chapters/{lan}Create a video chapter
GetGet /videos/{id}/chaptersGet video chapters
DeleteDelete /videos/{id}/chapters/{lan}Delete a video chapter

Webhook

Retrieve an instance of the Webhook API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
	PublicKey: publicKey,
	SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
webhookApi := client.Webhook
Endpoints
MethodHTTP requestDescription
CreatePost /webhooksCreate webhook
GetGet /webhooks/{id}Get user's webhook by id
UpdatePatch /webhooks/{id}Update event webhook
DeleteDelete /webhooks/{id}Delete webhook
ListGet /webhooksGet list webhooks
CheckPost /webhooks/check/{id}Check webhook by id

Models

Have you gotten use from this API client?

Please take a moment to leave a star on the client ⭐

This helps other users to find the clients and also helps us understand which clients are most popular. Thank you!