peertube

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

README

peertube

Build status GoDoc

peertube is a simple (and incomplete) Go client for peertube.

Installation

$> go install git.sr.ht/~sbinet/peertube
$> go install git.sr.ht/~sbinet/peertube/cmd/peertube-cli

Examples

$> peertube-cli help
peertube-cli - runs peertube-cli commands and sub-commands

Commands:

    auth-add     authenticate with a PeerTube server
    auth-ls      list the known PeerTube servers
    auth-rm      remove a PeerTube login
    video-ls     list video(s) from a PeerTube server
    video-upload upload a video to a PeerTube server

Use "peertube-cli help <command>" for more information about a command.
$> peertube-cli auth-add help
Usage: peertube-cli auth-add [options]

auth-add authenticates with a PeerTube server.

ex:
 $ peertube-cli auth-add -url https://peertube.example.org -u gopher -p s3cr3t

Options:
  -p string
    	password
  -u string
    	username
  -url string
    	PeerTube server URL
$> peertube-cli video-upload help
Usage: peertube-cli video-upload [options]

video-upload uploads a video to a PeerTube server.

ex:
 $ peertube-cli video-upload /path/to/file
 $ peertube-cli video-upload -url https://peertube.example.org -u gopher /path/to/file

Options:
  -category int
    	video category (music, film, ...)
  -channel string
    	channel name or id where to upload video
  -comments
    	enable/disable comments on video (default true)
  -descr string
    	video description
  -download
    	enable/disable download of video (default true)
  -language string
    	ISO 639 language code (en, fr, ...)
  -license int
    	video license (attribution, public, no derivatives, ...)
  -name string
    	video name
  -nsfw
    	whether video is Not Safe For Work
  -p string
    	password
  -preview string
    	path to preview file for video
  -privacy int
    	video privacy
  -support string
    	video support text
  -tags string
    	comma-separated list of tags (up to 5)
  -thumbnail string
    	path to thumbnail file for video
  -u string
    	username
  -url string
    	PeerTube server URL
  -use-legacy
    	whether to use non-resumable upload scheme
  -wait-transcoding
    	whether to wait for transcoding before publishing video (default true)

Documentation

Overview

Package peertube exposes a REST-client for PeerTube.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID     int    `json:"id"`
	UserID int    `json:"userId"`
	URL    string `json:"url"`
	Name   string `json:"name"`
	Host   string `json:"host"`

	Created time.Time `json:"createdAt"`
	Updated time.Time `json:"updatedAt"`

	HostRedundancyAllowed bool `json:"hostRedundancyAllowed"`
	FollowingCount        int  `json:"followingCount"`
	FollowersCount        int  `json:"followersCount"`

	Avatars []Avatar `json:"avatars"`
	Banners []Banner `json:"banners"`
}

Account describes an account on a remote peertube server.

type Avatar

type Avatar struct {
	Width   int       `json:"width"`
	Path    string    `json:"path"`
	Created time.Time `json:"createdAt"`
	Updated time.Time `json:"updatedAt"`
}

Avatar describes an avatar on a remote peertube server.

type Banner struct {
	Width   int       `json:"width"`
	Path    string    `json:"path"`
	Created time.Time `json:"createdAt"`
	Updated time.Time `json:"updatedAt"`
}

Banner describes a banner on a remote peertube server.

type Category

type Category struct {
	ID   int    `json:"id"`
	Name string `json:"label"`
}

Category describes a video's category (Music, Films, Art, ...)

type Channel

type Channel struct {
	ID      int       `json:"id"`
	Name    string    `json:"name"`
	URL     string    `json:"url"`
	Host    string    `json:"host"`
	Created time.Time `json:"createdAt"`
	Updated time.Time `json:"updatedAt"`
	Owner   Account   `json:"ownerAccount"`

	Avatars []Avatar `json:"avatars"`

	HostRedundancyAllowed bool     `json:"hostRedundancyAllowed"`
	FollowingCount        int      `json:"followingCount"`
	FollowersCount        int      `json:"followersCount"`
	Banners               []Banner `json:"banners"`

	DisplayName string `json:"displayName"`
	Description string `json:"description"`
	Support     string `json:"support"`
	IsLocal     bool   `json:"isLocal"`
}

Channel describes an account's channel on a remote peertube server.

type Client

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

Client is a PeerTube client.

func NewClient

func NewClient(srv string, opts ...Option) (*Client, error)

NewClient creates a peertube client for the provided peertube server URL.

Example:

cli, err := peertube.NewClient("https://peertube.example.org")

func (*Client) Account

func (c *Client) Account(ctx context.Context, name string) (Account, error)

Account returns the account informations for the provided user name on the remote peertube server.

func (*Client) Accounts

func (c *Client) Accounts(ctx context.Context) ([]Account, error)

Accounts returns the list of accounts on the remote peertube server.

func (*Client) Auth

func (c *Client) Auth(ctx context.Context, usr, pwd string) error

Auth authenticates the client with the provided user and pwassword.

func (*Client) Categories

func (c *Client) Categories(ctx context.Context) ([]Category, error)

Categories returns the list of (video) categories on the remote peertube server.

func (*Client) Channels

func (c *Client) Channels(ctx context.Context, usr string) ([]Channel, error)

Channels returns the list of channels for the provided user, on the remote peertube server.

func (*Client) DelVideo

func (c *Client) DelVideo(ctx context.Context, id string) error

DelVideo deletes the video with the provided id, UUID or ShortUUID.

DelVideo needs the client to be authenticated.

func (*Client) Languages

func (c *Client) Languages(ctx context.Context) ([]Language, error)

Languages returns the list of languages on the remote peertube server.

func (*Client) Licenses

func (c *Client) Licenses(ctx context.Context) ([]License, error)

Licenses returns the list of licenses on the remote peertube server.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, vid VideoUpload) (Video, error)

Upload uploads the provided video to the remote peertube server.

Upload needs the client to be authenticated. Upload uses a resumable protocol to upload the video.

func (*Client) UploadLegacy

func (c *Client) UploadLegacy(ctx context.Context, vid VideoUpload) (Video, error)

UploadLegacy uploads the provided video to the remote peertube server, using a "legacy" protocol.

UploadLegacy needs the client to be authenticated.

func (*Client) UploadResumable

func (c *Client) UploadResumable(ctx context.Context, vid VideoUpload) (Video, error)

UploadResumable uploads the provided video to the remote peertube server, using a "resumable" protocol.

UploadResumable needs the client to be authenticated.

func (*Client) Video added in v0.4.0

func (c *Client) Video(ctx context.Context, id, pwd string) (Video, error)

Video returns the video informations for the provided id, UUID or ShortUUID.

If the video is not password protected, pwd can be left empty.

func (*Client) Videos

func (c *Client) Videos(ctx context.Context, usr string) iter.Seq2[Video, error]

Videos returns the list of videos for the provided user, on the remote peertube server.

type Error

type Error struct {
	Detail string `json:"detail"`
	Docs   string `json:"docs"`
	Status int    `json:"status"`
	Title  string `json:"title"`
	Type   string `json:"type"`
}

Error describes errors returned by a remote peertube server.

func (Error) Error

func (e Error) Error() string

type File

type File interface {
	fs.File
	Name() string
}

File models a named file interface.

type Language

type Language struct {
	ID   string `json:"id"`
	Name string `json:"label"`
}

Language describes a video's language ("en", "fr", ...)

type License

type License struct {
	ID   int    `json:"id"`
	Name string `json:"label"`
}

License describes a video's license (Public Domain, Share Alike, ...)

type Option

type Option func(c *Client) error

Option configures a peertube client.

func WithUser

func WithUser(usr string) Option

WithUser instructs a peertube client to use the provided user.

type Privacy

type Privacy struct {
	ID   int    `json:"id"`
	Name string `json:"label"`
}

Privacy describes a video's privacy level (public, unlisted, private, ...)

type PrivacyKind

type PrivacyKind int

PrivacyKind is an enum-like modelization for privacy.

const (
	PrivPublic            PrivacyKind = 1
	PrivUnlisted          PrivacyKind = 2
	PrivPrivate           PrivacyKind = 3
	PrivInternal          PrivacyKind = 4
	PrivPasswordProtected PrivacyKind = 5
)

List of privacy's values and names.

type Video

type Video struct {
	ID        int    `json:"id"`
	UUID      string `json:"uuid"`
	ShortUUID string `json:"shortUUID"`
	IsLive    bool   `json:"isLive"`

	Created               time.Time `json:"createdAt"`
	Updated               time.Time `json:"updatedAt"`
	Published             time.Time `json:"publishedAt"`
	OriginallyPublishedAt time.Time `json:"originallyPublishedAt"`

	Category Category `json:"category"`
	License  License  `json:"licence"`
	Language Language `json:"language"`
	Privacy  Privacy  `json:"privacy"`

	Name            string  `json:"name"`
	Description     string  `json:"description"`
	Duration        int     `json:"duration"`
	AspectRatio     float64 `json:"aspectRatio"`
	IsLocal         bool    `json:"isLocal"`
	ThumbnailPath   string  `json:"thumbnailPath"`
	PreviewPath     string  `json:"previewPath"`
	EmbedPath       string  `json:"embedPath"`
	Views           int     `json:"views"`
	Likes           int     `json:"likes"`
	Dislikes        int     `json:"dislikes"`
	NSFW            bool    `json:"nsfw"`
	WaitTranscoding bool    `json:"waitTranscoding"`

	Account Account `json:"account"`
	Channel Channel `json:"channel"`
}

Video describes a video on a remote peertube server.

type VideoUpload

type VideoUpload struct {
	ChannelID int    `json:"channelId"`
	Name      string `json:"name"`
	File      File   `json:"videofile"`

	Category        int    `json:"category"`
	CommentsEnabled bool   `json:"commentsEnabled"`
	DownloadEnabled bool   `json:"downloadEnabled"`
	Description     string `json:"description"`
	Language        string `json:"language"`
	License         int    `json:"licence"`
	NSFW            bool   `json:"nsfw"`

	OriginallyPublishedAt time.Time `json:"originallyPublishedAt"`

	PreviewFile    File        `json:"previewfile"`
	Privacy        PrivacyKind `json:"privacy"`
	ScheduleUpdate struct {
		UpdateAt time.Time   `json:"updateAt"`
		Privacy  PrivacyKind `json:"privacy"`
	} `json:"scheduleUpdate"`
	Support string `json:"support"`

	Tags          []string `json:"tags"`
	ThumbnailFile File     `json:"thumbnailfile"`

	VideoPasswords []string `json:"videoPasswords"`

	WaitTranscoding bool `json:"waitTranscoding"`
}

VideoUpload describes data and metadata about a video before upload to a remote peertube server.

func NewVideoUpload

func NewVideoUpload(chanID int, name, fname string) (VideoUpload, error)

NewVideoUpload creates a video upload parameter set. NewVideoUpload configures for a video upload to the provided channel ID, with the provided video name and path to video file.

Directories

Path Synopsis
cmd
peertube-cli
Command peertube-cli communicates with a PeerTube instance using its REST API.
Command peertube-cli communicates with a PeerTube instance using its REST API.
internal

Jump to

Keyboard shortcuts

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