livepeerAPI

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2022 License: MIT Imports: 18 Imported by: 9

README

go-api-client

Implementation of a client for the Livepeer API written in Go

Documentation

Overview

Package livepeer API

Index

Constants

View Source
const (
	SHORT    = 4
	DEBUG    = 5
	VERBOSE  = 6
	VVERBOSE = 7
	INSANE   = 12
	INSANE2  = 14
)
View Source
const (
	ProdServer = "livepeer.com"

	RecordingStatusWaiting = "waiting"
	RecordingStatusReady   = "ready"
)

Variables

View Source
var ErrNotExists = errors.New("not found")

ErrNotExists returned if receives a 404 error from the API

View Source
var StandardProfiles = []Profile{
	{
		Name:    "240p0",
		Fps:     0,
		Bitrate: 250000,
		Width:   426,
		Height:  240,
		Gop:     "2.0",
	},
	{
		Name:    "360p0",
		Fps:     0,
		Bitrate: 800000,
		Width:   640,
		Height:  360,
		Gop:     "2.0",
	},
	{
		Name:    "480p0",
		Fps:     0,
		Bitrate: 1600000,
		Width:   854,
		Height:  480,
		Gop:     "2.0",
	},
	{
		Name:    "720p0",
		Fps:     0,
		Bitrate: 3000000,
		Width:   1280,
		Height:  720,
		Gop:     "2.0",
	},
}

Functions

func GeolocateAPIServer

func GeolocateAPIServer() (string, error)

GeolocateAPIServer calls geolocation API endpoint to find the closest server.

func MustGeolocateAPIServer

func MustGeolocateAPIServer() string

func Timedout

func Timedout(e error) bool

Types

type Asset

type Asset struct {
	ID            string `json:"id"`
	PlaybackID    string `json:"playbackId"`
	UserID        string `json:"userId"`
	CreatedAt     int64  `json:"createdAt"`
	SourceAssetId string `json:"sourceAssetId,omitempty"`
	ObjectStoreID string `json:"objectStoreId"`
	AssetSpec
}

type AssetHash

type AssetHash struct {
	Hash      string `json:"hash"`
	Algorithm string `json:"algorithm"`
}

type AssetSpec

type AssetSpec struct {
	Name                string          `json:"name,omitempty"`
	Type                string          `json:"type"`
	Size                uint64          `json:"size"`
	Hash                []AssetHash     `json:"hash"`
	VideoSpec           *AssetVideoSpec `json:"videoSpec,omitempty"`
	PlaybackRecordingID string          `json:"playbackRecordingId,omitempty"`
}

type AssetTrack

type AssetTrack struct {
	Type        string  `json:"type"`
	Codec       string  `json:"codec"`
	StartTime   float64 `json:"startTime,omitempty"`
	DurationSec float64 `json:"duration,omitempty"`
	Bitrate     float64 `json:"bitrate,omitempty"`
	// video track fields
	Width       int     `json:"width,omitempty"`
	Height      int     `json:"height,omitempty"`
	PixelFormat string  `json:"pixelFormat,omitempty"`
	FPS         float64 `json:"fps,omitempty"`
	// auido track fields
	Channels   int `json:"channels,omitempty"`
	SampleRate int `json:"sampleRate,omitempty"`
	BitDepth   int `json:"bitDepth,omitempty"`
}

type AssetVideoSpec

type AssetVideoSpec struct {
	Format      string        `json:"format"`
	DurationSec float64       `json:"duration"`
	Bitrate     float64       `json:"bitrate,omitempty"`
	Tracks      []*AssetTrack `json:"tracks"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

API object incapsulating Livepeer's hosted API

func NewAPIClient

func NewAPIClient(opts ClientOptions) *Client

NewAPIClient creates new Livepeer API object with a full configuration.

func NewAPIClientGeolocated

func NewAPIClientGeolocated(opts ClientOptions) (*Client, string)

NewAPIClientGeolocated creates a new Livepeer API object calling the geolocation endpoint if no server is provided (by default, server is production instead)

func (*Client) Broadcasters

func (lapi *Client) Broadcasters() ([]string, error)

Broadcasters returns list of hostnames of broadcasters to use

func (*Client) CreateStream

func (lapi *Client) CreateStream(name string, presets ...string) (string, error)

CreateStream creates stream with specified name and profiles

func (*Client) CreateStreamEx

func (lapi *Client) CreateStreamEx(name string, record bool, presets []string, profiles ...Profile) (*CreateStreamResp, error)

CreateStreamEx creates stream with specified name and profiles

func (*Client) CreateStreamEx2

func (lapi *Client) CreateStreamEx2(name string, record bool, parentID string, presets []string, profiles ...Profile) (*CreateStreamResp, error)

CreateStreamEx creates stream with specified name and profiles

func (*Client) DeactivateMany

func (lapi *Client) DeactivateMany(ids []string) (int, error)

DeactivateMany sets many streams isActive field to false

func (*Client) DefaultPresets

func (lapi *Client) DefaultPresets() []string

DefaultPresets returns default presets

func (*Client) DeleteStream

func (lapi *Client) DeleteStream(id string) error

DeleteStream deletes stream

func (*Client) GetAsset

func (lapi *Client) GetAsset(id string) (*Asset, error)

func (*Client) GetMultistreamTarget

func (lapi *Client) GetMultistreamTarget(id string) (*MultistreamTarget, error)

func (*Client) GetMultistreamTargetR

func (lapi *Client) GetMultistreamTargetR(id string) (*MultistreamTarget, error)

GetMultistreamTargetR gets multistream target with retries

func (*Client) GetObjectStore

func (lapi *Client) GetObjectStore(id string) (*ObjectStore, error)

func (*Client) GetServer

func (lapi *Client) GetServer() string

GetServer returns chosen server

func (*Client) GetSessions

func (lapi *Client) GetSessions(id string, forceUrl bool) ([]UserSession, error)

GetSessions gets user's sessions for the stream by id

func (*Client) GetSessionsNew

func (lapi *Client) GetSessionsNew(id string, forceUrl bool) ([]UserSession, error)

func (*Client) GetSessionsNewR

func (lapi *Client) GetSessionsNewR(id string, forceUrl bool) ([]UserSession, error)

GetSessionsNewR gets user's sessions for the stream by id

func (*Client) GetSessionsR

func (lapi *Client) GetSessionsR(id string, forceUrl bool) ([]UserSession, error)

GetSessionsR gets user's sessions for the stream by id

func (*Client) GetStream

func (lapi *Client) GetStream(id string) (*CreateStreamResp, error)

GetStream gets stream by id

func (*Client) GetStreamByKey

func (lapi *Client) GetStreamByKey(key string) (*CreateStreamResp, error)

GetStreamByKey gets stream by streamKey

func (*Client) GetStreamByPlaybackID

func (lapi *Client) GetStreamByPlaybackID(playbackID string) (*CreateStreamResp, error)

GetStreamByPlaybackID gets stream by playbackID

func (*Client) GetTask

func (lapi *Client) GetTask(id string) (*Task, error)

func (*Client) Ingest

func (lapi *Client) Ingest(all bool) ([]Ingest, error)

Ingest returns ingest object

func (*Client) PushSegment

func (lapi *Client) PushSegment(sid string, seqNo int, dur time.Duration, segData []byte) ([][]byte, error)

func (*Client) SetActive

func (lapi *Client) SetActive(id string, active bool, startedAt time.Time) (bool, error)

SetActive set isActive

func (*Client) SetActiveR

func (lapi *Client) SetActiveR(id string, active bool, startedAt time.Time) (bool, error)

SetActiveR sets stream active with retries

func (*Client) UpdateTaskStatus

func (lapi *Client) UpdateTaskStatus(id string, phase string, progress float64) error

type ClientOptions

type ClientOptions struct {
	Server      string
	AccessToken string
	UserAgent   string
	Timeout     time.Duration
	Presets     []string
	Metrics     metrics.APIRecorder
}

Object with all options given to Livepeer API

type CreateStreamResp

type CreateStreamResp struct {
	ID                         string    `json:"id,omitempty"`
	Name                       string    `json:"name,omitempty"`
	Presets                    []string  `json:"presets,omitempty"`
	Kind                       string    `json:"kind,omitempty"`
	UserID                     string    `json:"userId,omitempty"`
	StreamKey                  string    `json:"streamKey,omitempty"`
	PlaybackID                 string    `json:"playbackId,omitempty"`
	ParentID                   string    `json:"parentId,omitempty"`
	CreatedAt                  int64     `json:"createdAt,omitempty"`
	LastSeen                   int64     `json:"lastSeen,omitempty"`
	SourceSegments             int64     `json:"sourceSegments,omitempty"`
	TranscodedSegments         int64     `json:"transcodedSegments,omitempty"`
	SourceSegmentsDuration     float64   `json:"sourceSegmentsDuration,omitempty"`
	TranscodedSegmentsDuration float64   `json:"transcodedSegmentsDuration,omitempty"`
	Deleted                    bool      `json:"deleted,omitempty"`
	Record                     bool      `json:"record"`
	Profiles                   []Profile `json:"profiles,omitempty"`
	Errors                     []string  `json:"errors,omitempty"`
	Multistream                struct {
		Targets []MultistreamTargetRef `json:"targets,omitempty"`
	} `json:"multistream"`
}

CreateStreamResp returned by API

type ExportTaskParams

type ExportTaskParams struct {
	Custom *struct {
		URL     string            `json:"url"`
		Method  string            `json:"method,omitempty"`
		Headers map[string]string `json:"headers,omitempty"`
	} `json:"custom,omitempty"`
	IPFS *struct {
		Pinata *struct {
			JWT       string `json:"jwt,omitempty"`
			APIKey    string `json:"apiKey,omitempty"`
			APISecret string `json:"apiSecret,omitempty"`
		} `json:"pinata,omitempty"`
		NFTMetadata map[string]interface{} `json:"nftMetadata,omitempty"`
	} `json:"ipfs,omitempty"`
}

type ImportTaskParams

type ImportTaskParams struct {
	URL               string `json:"url,omitempty"`
	UploadedObjectKey string `json:"uploadedObjectKey,omitempty"`
}

type Ingest

type Ingest struct {
	Base     string `json:"base,omitempty"`
	Playback string `json:"playback,omitempty"`
	Ingest   string `json:"ingest,omitempty"`
}

Ingest object

type MultistreamTarget

type MultistreamTarget struct {
	ID        string `json:"id,omitempty"`
	URL       string `json:"url,omitempty"`
	Name      string `json:"name,omitempty"`
	UserID    string `json:"userId,omitempty"`
	Disabled  bool   `json:"disabled,omitempty"`
	CreatedAt int64  `json:"createdAt,omitempty"`
}

type MultistreamTargetRef

type MultistreamTargetRef struct {
	Profile   string `json:"profile,omitempty"`
	VideoOnly bool   `json:"videoOnly,omitempty"`
	ID        string `json:"id,omitempty"`
}

type ObjectStore

type ObjectStore struct {
	ID        string `json:"id"`
	UserId    string `json:"userId"`
	CreatedAt int64  `json:"createdAt"`
	URL       string `json:"url"`
	Name      string `json:"name,omitempty"`
	PublicURL string `json:"publicUrl,omitempty"`
	Disabled  bool   `json:"disabled"`
}

type Profile

type Profile struct {
	Name    string `json:"name,omitempty"`
	Width   int    `json:"width,omitempty"`
	Height  int    `json:"height,omitempty"`
	Bitrate int    `json:"bitrate,omitempty"`
	Fps     int    `json:"fps"`
	FpsDen  int    `json:"fpsDen,omitempty"`
	Gop     string `json:"gop,omitempty"`
	Profile string `json:"profile,omitempty"` // enum: - H264Baseline - H264Main - H264High - H264ConstrainedHigh
	Encoder string `json:"encoder,omitempty"` // enum: - h264, h265, vp8, vp9
}

Profile transcoding profile

type Task

type Task struct {
	ID            string `json:"id"`
	UserID        string `json:"userId"`
	CreatedAt     int64  `json:"createdAt"`
	InputAssetID  string `json:"inputAssetId,omitempty"`
	OutputAssetID string `json:"outputAssetId,omitempty"`
	Type          string `json:"type"`
	Params        struct {
		Import    *ImportTaskParams    `json:"import"`
		Export    *ExportTaskParams    `json:"export"`
		Transcode *TranscodeTaskParams `json:"transcode"`
	} `json:"params"`
	Status TaskStatus `json:"status"`
}

type TaskStatus

type TaskStatus struct {
	Phase     string  `json:"phase"`
	Progress  float64 `json:"progress"`
	UpdatedAt int64   `json:"updatedAt,omitempty"`
}

type TranscodeTaskParams

type TranscodeTaskParams struct {
	Profile Profile `json:"profile,omitempty"`
}

type UserSession

type UserSession struct {
	CreateStreamResp
	RecordingStatus string `json:"recordingStatus,omitempty"` // ready, waiting
	RecordingURL    string `json:"recordingUrl,omitempty"`
	Mp4Url          string `json:"mp4Url,omitempty"`
}

UserSession user's sessions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL