Help us shape the future of Go! Take the 2026 Go Developer Survey

threeplay

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

3Play Go Client

Build Status codecov Go Report Card

Running tests
$ go get -t && go test

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorized represents a 401 error on API
	ErrUnauthorized = errors.New("401: API Error")
	// ErrNotFound represents a 404 error on API
	ErrNotFound = errors.New("404: API Error")
)

Functions

This section is empty.

Types

type CaptionsFormat

type CaptionsFormat string

CaptionsFormat is supported output format for captions

const (
	// SRT format for captions file
	SRT CaptionsFormat = "srt"
	// WebVTT format for captions file
	WebVTT CaptionsFormat = "vtt"
	// DFX format for captions file
	DFX CaptionsFormat = "pdfxp"
	// SMI format for captions file
	SMI CaptionsFormat = "smi"
	// STL format for captions file
	STL CaptionsFormat = "stl"
	// QT format for captions file
	QT CaptionsFormat = "qt"
	// QTXML format for captions file
	QTXML CaptionsFormat = "qtxml"
	// CPTXML format for captions file
	CPTXML CaptionsFormat = "cptxml"
	// ADBE format for captions file
	ADBE CaptionsFormat = "adbe"
)

type Client

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

Client 3Play Media API client

func NewClient

func NewClient(apiKey, apiSecret string) *Client

NewClient returns a 3Play Media client

func NewClientWithHTTPClient

func NewClientWithHTTPClient(apiKey, apiSecret string, client *http.Client) *Client

NewClientWithHTTPClient returns a 3Play Media client with a custom http client

func (*Client) AddTag

func (c *Client) AddTag(fileID uint, tag string) ([]string, error)

AddTag adds a tag to a file

func (*Client) GetCaptions

func (c *Client) GetCaptions(opts GetCaptionsOptions) ([]byte, error)

GetCaptions retrieves caption files according to the given options.

func (*Client) GetCaptionsByVideoID

func (c *Client) GetCaptionsByVideoID(id string, format CaptionsFormat) ([]byte, error)

GetCaptionsByVideoID get captions by video ID with specific format current supported formats are srt, dfxp, smi, stl, qt, qtxml, cptxml, adbe

func (*Client) GetFile

func (c *Client) GetFile(id uint) (*File, error)

GetFile gets a single file by id

func (*Client) GetFiles

func (c *Client) GetFiles(params, filters url.Values) (*FilesPage, error)

GetFiles returns a list of files, supports pagination through params and filters. For a full list of supported filtering parameters check http://support.3playmedia.com/hc/en-us/articles/227729828-Files-API-Methods

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/NYTimes/threeplay"
)

func main() {
	client := threeplay.NewClient("api-key", "secret")
	filesPage, _ := client.GetFiles(nil, nil)
	fmt.Println(filesPage.Files)

	pagination, _ := url.ParseQuery("page=2&per_page=10")

	filesPage, _ = client.GetFiles(pagination, nil)
	fmt.Println(filesPage.Files)
}

func (*Client) GetTags

func (c *Client) GetTags(fileID uint) ([]string, error)

GetTags gets the list of tags of a file

func (*Client) GetTranscript

func (c *Client) GetTranscript(fileID uint) (*Transcript, error)

GetTranscript get json transcript by file ID

func (*Client) GetTranscriptByVideoID

func (c *Client) GetTranscriptByVideoID(videoID string) (*Transcript, error)

GetTranscriptByVideoID get json transcript by video ID

func (*Client) GetTranscriptByVideoIDWithFormat

func (c *Client) GetTranscriptByVideoIDWithFormat(id string, format TranscriptFormat) ([]byte, error)

GetTranscriptByVideoIDWithFormat get transcript by video ID with specific format current supported formats are json, text and html

func (*Client) GetTranscriptWithFormat

func (c *Client) GetTranscriptWithFormat(id uint, format TranscriptFormat) ([]byte, error)

GetTranscriptWithFormat get transcript by file ID with supported formats current supported formats are json, text and html

Example
package main

import (
	"fmt"

	"github.com/NYTimes/threeplay"
)

func main() {
	client := threeplay.NewClient("api-key", "secret")
	transcript, _ := client.GetTranscriptWithFormat(123, threeplay.JSON)
	fmt.Println(transcript)
}

func (*Client) RemoveTag

func (c *Client) RemoveTag(fileID uint, tag string) ([]string, error)

RemoveTag removes a tag of a file

func (*Client) UpdateFile

func (c *Client) UpdateFile(fileID uint, data url.Values) error

UpdateFile updates a File metadata

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/NYTimes/threeplay"
)

func main() {
	client := threeplay.NewClient("api-key", "api-secret")
	data, _ := url.ParseQuery("name=another-name")
	err := client.UpdateFile(1687446, data)
	if err != nil {
		fmt.Println(err)
	}
}

func (*Client) UploadFileFromURL

func (c *Client) UploadFileFromURL(fileURL string, options url.Values) (uint, error)

UploadFileFromURL uploads a file to threeplay using the file's URL and returns the file ID.

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/NYTimes/threeplay"
)

func main() {
	client := threeplay.NewClient("api-key", "secret")
	data, _ := url.ParseQuery("video_id=123&attribute1=abc")
	fileID, _ := client.UploadFileFromURL("http://somewhere.com/video.mp4", data)
	fmt.Println(fileID)
}

type Error

type Error struct {
	IsError bool              `json:"iserror"`
	Errors  map[string]string `json:"errors"`
}

Error representation of 3Play API error

type File

type File struct {
	ID                   uint   `json:"id"`
	ProjectID            uint   `json:"project_id"`
	BatchID              uint   `json:"batch_id"`
	Duration             uint   `json:"duration"`
	Attribute1           string `json:"attribute1"`
	Attribute2           string `json:"attribute2"`
	Attribute3           string `json:"attribute3"`
	VideoID              string `json:"video_id"`
	Name                 string `json:"name"`
	CallbackURL          string `json:"callback_url"`
	Description          string `json:"description"`
	CreatedAt            string `json:"created_at"`
	UpdatedAt            string `json:"updated_at"`
	WordCount            uint   `json:"word_count"`
	ThumbnailURL         string `json:"thumbnail_url"`
	LanguageID           int    `json:"language_id"`
	DefaultServiceTypeID int    `json:"default_service_type_id"`
	Downloaded           bool   `json:"downloaded"`
	State                string `json:"state"`
	TurnaroundLevelID    int    `json:"turnaround_level_id"`
	Deadline             string `json:"deadline"`
	BatchName            string `json:"batch_name"`
	ErrorDescription     string `json:"error_description"`
}

File representation

type FilesPage

type FilesPage struct {
	Files   []File `json:"files"`
	Summary `json:"summary"`
}

FilesPage representation

type GetCaptionsOptions

type GetCaptionsOptions struct {
	// FileID should be specified to download the captions file by its ID.
	// This option is mutually exclusive with VideoID.
	FileID uint

	// VideoID should be specified to download the captions file specifying
	// the video ID. This option is mutually exclusive with FileID.
	VideoID string

	// Format specifies the standard format that should be used. Please
	// refer to the constants exported by this package to see the available
	// formats. This option is mutually exclusive with Outputformat.
	Format CaptionsFormat

	// OutputFormat specifies the custom format that should be used.
	// This option is mutually exclusive with Format.
	OutputFormat string
}

GetCaptionsOptions represents the set of options that can be provided when obtaining a captions file.

type Summary

type Summary struct {
	CurrentPage  json.Number `json:"current_page"`
	PerPage      json.Number `json:"per_page"`
	TotalEntries json.Number `json:"total_entries"`
	TotalPages   json.Number `json:"total_pages"`
}

Summary representation

type Transcript

type Transcript struct {
	Words      []Word            `json:"words"`
	Paragraphs []int             `json:"paragraphs"`
	Speakers   map[string]string `json:"speakers"`
}

Transcript video transcript

type TranscriptFormat

type TranscriptFormat string

TranscriptFormat supported output formats for transcripts

const (
	// JSON format for transcripted file
	JSON TranscriptFormat = "json"
	// TXT format output for transcripted file
	TXT TranscriptFormat = "txt"
	// HTML format output for transcripted file
	HTML TranscriptFormat = "html"
)

type Word

type Word [2]string

Word words

Jump to

Keyboard shortcuts

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