youtubetoolkit

package module
v0.0.0-...-e687133 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

README

youtubetoolkit

usage overview

When launching the CLI with a command for the first time, it will print a URL that you must open in your browser (if it fails to automagically open a browser for you) to authorize the CLI to act on your behalf on your YouTube account. The flag --token allows you to specify the filename where the CLI will store the auth token.

Data output will be printed to STDOUT, while info and errors to STDERR. Commands like subscribe and playlist add can receive data from STDIN. This allows you to do your wizardry with OS pipes and i/o redirections.

For example, you can do something like this to copy subscriptions from one account to another:

$ youtubetoolkit -t account1 subscriptions list | youtubetoolkit -t account2 subscriptions add

Or you can add to a playlist the last 7 days video uploads from a list of channels:

$ youtubetoolkit lastuploads < channelIds.csv | youtubetoolkit playlists new test-playlist

Complete list of commands:

youtubetoolkit lastuploads --days <#>

youtubetoolkit subscriptions list
youtubetoolkit subscriptions add <channel id>
youtubetoolkit subscriptions del <channel id>

youtubetoolkit playlists
youtubetoolkit playlists new <playlist name>
youtubetoolkit playlists del <playlist id>

youtubetoolkit playlist --id <playlist_id>
youtubetoolkit playlist --id <playlist_id> add <video id>

Output formats available: --csv, --table, --jsonl.

Please use CLI flag --help to get additional help for every single command.

install

go install ./cmd/youtubetoolkit

requirement

To use the toolkit you need a OAuth2.0 client id and secret from Google Cloud:

  • create a new project
  • enable YouTube Data API v3
  • configure the OAuth consent screen
    • for the sake of simplicity, set "External" type, don't publish the app (leave it in "testing"), and add your email to test users
  • create a new OAuth Client ID credential and download the JSON file when prompted
    • the application type must be "Desktop app"
  • rename the json file to client_secret.json (it's the default filename the CLI will search for)
    • needless to say, do NOT disclose this file

As you may know, YouTube API access is subject to quotas. A GCloud dev project should have a total of 10000 units per day, plenty for read-only operations (only 1 unit) but not for creating/inserting things. API operations like subscribing to a channel, creating a playlist, adding a video to a playlist all cost 50 units. Or 200 inserts per day before running into "quota exceeded" errors. The CLI will output the quota impact after every execution.

contributing

Pull requests are always welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlowOption

type FlowOption func(*flowconfig)

func CSVFirstFieldOnlySource

func CSVFirstFieldOnlySource(input io.Reader) FlowOption

CSVFirstFieldOnlySource sets a CSV reader as source and emit only the first field/column (or the entire line if the input isn't a proper CSV)

func CSVSink

func CSVSink(output io.Writer, columns *[]string) FlowOption

CSVSink sets a CSV writer as sink. The columns param selects the fields of Item to be written in the CSV output.

func JSONLinesSink

func JSONLinesSink(output io.Writer) FlowOption

JSONLinesSink sets a JSON Lines as sink.

func NullSink

func NullSink() FlowOption

NullSink sets a discard sink.

func SingleStringSource

func SingleStringSource(input string) FlowOption

SingleStringSource sets the source to only emit the param input string.

func TableSink

func TableSink(output io.Writer, columns *[]string) FlowOption

TableSink sets a text/tabwriter as sink for a human readable output. The columns param selects the fields of Item to be written in the output.

type Item

type Item interface {
	// AsRecord returns a string slice with the values of
	// this Item selected by the fields param.
	AsRecord(fields *[]string) []string
}

type MultiErrors

type MultiErrors []error

MultiErrors is used when one error is not enough

func (MultiErrors) Error

func (e MultiErrors) Error() string

type Toolkit

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

func New

func New() *Toolkit

func NewWithService

func NewWithService(svc YoutubeService) *Toolkit

func (*Toolkit) AddVideoToPlaylist

func (tk *Toolkit) AddVideoToPlaylist(playlistId string, opts ...FlowOption) error

AddVideoToPlaylist adds videos to a playlist. Flow: source and sink are required

func (*Toolkit) DeletePlaylist

func (tk *Toolkit) DeletePlaylist(playlistId string) error

DeletePlaylist deletes a user playlist.

func (*Toolkit) LastUploads

func (tk *Toolkit) LastUploads(since time.Time, opts ...FlowOption) error

CSVLastUploads gets the latest channels' video uploads since the time argument. Videos are sorted by the published date (oldest first). Flow: source and sink are required

func (*Toolkit) NewPlaylist

func (tk *Toolkit) NewPlaylist(title string) (string, error)

NewPlaylist creates a new private playlist. Returns the playlist ID or error.

func (*Toolkit) Playlist

func (tk *Toolkit) Playlist(playlistId string, opts ...FlowOption) error

Playlist gets a playlist's videos. Flow: only sink is required

func (*Toolkit) Playlists

func (tk *Toolkit) Playlists(opts ...FlowOption) error

Playlists gets all user playlists. Flow: only sink is required

func (*Toolkit) SetLogWriter

func (tk *Toolkit) SetLogWriter(output io.Writer)

func (*Toolkit) SetService

func (tk *Toolkit) SetService(service YoutubeService)

func (*Toolkit) Subscribe

func (tk *Toolkit) Subscribe(opts ...FlowOption) error

Subscribe adds channels to user subscriptions. Flow: source and sink are required

func (*Toolkit) Subscriptions

func (tk *Toolkit) Subscriptions(opts ...FlowOption) error

Subscriptions gets all channels from user subscription. Flow: only sink is required

func (*Toolkit) Unsubscribe

func (tk *Toolkit) Unsubscribe(channelId string) error

Unsubscribe removes channel from user subscriptions.

type YoutubeService

type YoutubeService interface {
	SubscriptionsList(out chan<- *bigg.Sub) error
	SubscriptionInsert(channelId string) (*bigg.Sub, error)
	SubscriptionDelete(channelId string) error
	PlaylistsList(out chan<- *bigg.Playlist) error
	PlaylistInsert(title string) (*bigg.Playlist, error)
	PlaylistDelete(playlistId string) error
	PlaylistItemsList(id string, filter func(*bigg.PlaylistItem) (bool, error), out chan<- *bigg.PlaylistItem) error
	PlaylistItemsInsert(playlistId, videoId string) (*bigg.PlaylistItem, error)
	GetChannelInfo(id string) (*bigg.Channel, error)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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