ytlibrarian

package module
v0.3.2-1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2021 License: MIT Imports: 19 Imported by: 1

README

ytlibrarian

GoDoc

A relatively simple service which provides a way to manage collections of YouTube videos and playlists with custom metadata allowing more featurefull management

Documentation

Index

Constants

View Source
const (
	// ItemUser       = thingTypeUser
	ItemVideo      = thingTypeVideo
	ItemChannel    = thingTypeChannel
	ItemCollection = thingTypeCollection
)

Item types

Variables

This section is empty.

Functions

func AddOrUpdateCustomDataToChannel

func AddOrUpdateCustomDataToChannel(thinger Thinger, channel Channel, user User, data string) error

AddOrUpdateCustomDataToChannel links the given data to a Channel on behalf of a User

func AddOrUpdateCustomDataToVideo

func AddOrUpdateCustomDataToVideo(thinger Thinger, video Video, user User, data string) error

AddOrUpdateCustomDataToVideo links the given data to a Video on behalf of a User

func AppendCollectionItem

func AppendCollectionItem(thinger Thinger, user User, collectionID, itemID uuid.UUID) error

AppendCollectionItem adds an item to the end of a collection

func GetUserChannelCustomData

func GetUserChannelCustomData(thinger Thinger, channel Channel, user User) (string, error)

GetUserChannelCustomData retrieves the given data to a Channel on behalf of a User

func GetUserCollectionCustomData

func GetUserCollectionCustomData(thinger Thinger, collection Collection, user User) (string, error)

GetUserCollectionCustomData retrieves the given data to a Collection on behalf of a User

func GetUserVideoCustomData

func GetUserVideoCustomData(thinger Thinger, video Video, user User) (string, error)

GetUserVideoCustomData retrieves the given data to a Video on behalf of a User

func InsertCollectionItem

func InsertCollectionItem(thinger Thinger, user User, collectionID, itemID uuid.UUID, itemPos int) error

InsertCollectionItem adds an item to a collection

func LinkChannelToUser

func LinkChannelToUser(thinger Thinger, channel Channel, user User, details string) error

LinkChannelToUser adds a relationship between a channel and a user

func LinkCollectionToUser

func LinkCollectionToUser(thinger Thinger, collection Collection, user User, details string) error

LinkCollectionToUser adds a relationship between a user and a given collection as well as the items

func LinkVideoToUser

func LinkVideoToUser(thinger Thinger, video Video, user User, details string) error

LinkVideoToUser adds a relationship between a video and a user

func ListenAndServe

func ListenAndServe(port string, store Thinger) error

ListenAndServe provides the HTTP server handler

func RemoveChannelByID

func RemoveChannelByID(thinger Thinger, id uuid.UUID) error

RemoveChannelByID removes the identified collection from the Thinger

func RemoveCollectionByID

func RemoveCollectionByID(thinger Thinger, id uuid.UUID) error

RemoveCollectionByID removes the identified collection from the Thinger

func RemoveCollectionItem

func RemoveCollectionItem(thinger Thinger, user User, collectionID uuid.UUID, itemPos int) error

RemoveCollectionItem removes items in a Collection

func RemoveUserByID

func RemoveUserByID(thinger Thinger, id uuid.UUID) error

RemoveUserByID removes an identified User from the given Thinger

func RemoveUserChannelCustomData

func RemoveUserChannelCustomData(thinger Thinger, channel Channel, user User) error

RemoveUserChannelCustomData ... guess what this do!

func RemoveUserCollectionCustomData

func RemoveUserCollectionCustomData(thinger Thinger, collection Collection, user User) error

RemoveUserCollectionCustomData ... guess what this do!

func RemoveUserVideoCustomData

func RemoveUserVideoCustomData(thinger Thinger, video Video, user User) error

RemoveUserVideoCustomData ... guess what this do!

func RemoveVideoByID

func RemoveVideoByID(thinger Thinger, id uuid.UUID) error

RemoveVideoByID removes the identified collection from the Thinger

func ScorchedEarth

func ScorchedEarth(store Thinger, delUser bool)

func UnlinkChannelAndUser

func UnlinkChannelAndUser(thinger Thinger, channel Channel, user User) error

UnlinkChannelAndUser removes relationship between a channel and a user

func UnlinkCollectionAndUser

func UnlinkCollectionAndUser(thinger Thinger, collection Collection, user User) error

UnlinkCollectionAndUser removes relationship between a collection and a user

func UnlinkVideoAndUser

func UnlinkVideoAndUser(thinger Thinger, video Video, user User) error

UnlinkVideoAndUser removes relationship between a video and a user

func UnpublishCollection

func UnpublishCollection(thinger Thinger, tuber Tuber, id uuid.UUID) error

UnpublishCollection inserts or updates the identified collection to the given tuber service

func UpdateCollectionCustomData

func UpdateCollectionCustomData(thinger Thinger, collection Collection, user User, data string) error

UpdateCollectionCustomData links the given data to a Collection on behalf of a User

func UpdateCollectionItem

func UpdateCollectionItem(thinger Thinger, user User, collectionID, itemID uuid.UUID, itemPos int) (err error)

UpdateCollectionItem adds/removes/changes a single collection item

func UpdateCollectionItems

func UpdateCollectionItems(thinger Thinger, user User, items CollectionItems) error

UpdateCollectionItems adds/removes/changes items in a Collection

func UpdateUser

func UpdateUser(thinger Thinger, user User) error

UpdateUser updates an existing User in the given Thinger

Types

type BulkItemError

type BulkItemError struct {
	IDs    []string
	Errors []error
}

BulkItemError collects the multiple errors encountered when collecting multiples

func (*BulkItemError) Error

func (e *BulkItemError) Error() string

type Channel

type Channel struct {
	UserLinked bool   `json:"userLinked,omitempty"`
	Data       string `json:"data,omitempty"`
	// contains filtered or unexported fields
}

Channel is a reference to a channel along with metadata associated with the requesting user

func AddChannel

func AddChannel(thinger Thinger, tuber Tuber, id string) (channel Channel, err error)

AddChannel retrieves channel details from a Tuber and adds a Channel Thing to the given Thinger

func GetChannelByID

func GetChannelByID(thinger Thinger, user User, id uuid.UUID) (Channel, error)

GetChannelByID retrieves the collection which matches the given ID

func GetChannelByReferenceID

func GetChannelByReferenceID(thinger Thinger, user User, refID string) (Channel, error)

GetChannelByReferenceID retrieves the user thing by the given external ID

func GetChannelsByUser

func GetChannelsByUser(thinger Thinger, user User) ([]Channel, error)

GetChannelsByUser retrieves the collections which belong to the given user

type ChannelRequest

type ChannelRequest struct {
	Data string `json:"data,omitempty"`
}

ChannelRequest is used with the PUT /channels endpoint

type Collection

type Collection struct {
	Data string `json:"data,omitempty"`
	// contains filtered or unexported fields
}

Collection is a reference to a channel along with metadata associated with the requesting user

func AddCollection

func AddCollection(thinger Thinger, tuber Tuber, user User, id string) (collection Collection, err error)

AddCollection retrieves collection details from a Tuber and adds a Collection Thing to the given Thinger

func CreateCollection

func CreateCollection(thinger Thinger, collection Collection, user User) (Collection, error)

CreateCollection creates a new collection in the thinger that is not associated with an external thing

func GetCollectionByID

func GetCollectionByID(thinger Thinger, user User, id uuid.UUID) (Collection, error)

GetCollectionByID retrieves the collection which matches the given ID

func GetCollectionByReferenceID

func GetCollectionByReferenceID(thinger Thinger, user User, refID string) (Collection, error)

GetCollectionByReferenceID retrieves the user thing by the given external ID

func GetCollectionsByUser

func GetCollectionsByUser(thinger Thinger, user User) ([]Collection, error)

GetCollectionsByUser retrieves the collections which belong to the given user

func PublishCollection

func PublishCollection(thinger Thinger, tuber Tuber, user User, id uuid.UUID) (collection Collection, err error)

PublishCollection inserts or updates the identified collection to the given tuber service

func UpdateCollection

func UpdateCollection(thinger Thinger, collection Collection, user User) (Collection, error)

UpdateCollection updates an existing collection in the thinger

type CollectionItem

type CollectionItem struct {
	Kind     string `json:"kind"`
	ID       string `json:"id"`
	Position int    `json:"position"`
}

CollectionItem defines the minimum data to identify an item in a collection and its position

type CollectionItemAdd

type CollectionItemAdd struct {
	ID string `json:"id,omitempty"`
}

CollectionItemAdd adds the indicated item by internal ID

type CollectionItems

type CollectionItems struct {
	CollectionID string           `json:"collectionId"`
	Items        []CollectionItem `json:"items,omitempty"`
	Data         string           `json:"data,omitempty"`
}

CollectionItems collects the items within a collection

func AddCollectionItems

func AddCollectionItems(thinger Thinger, tuber Tuber, user User, collection Collection) (CollectionItems, error)

AddCollectionItems retrieves collection items from a Tuber and adds a Collection Thing to the given Thinger

func GetCollectionItems

func GetCollectionItems(thinger Thinger, collectionID uuid.UUID) (CollectionItems, error)

GetCollectionItems retrieves the collection which matches the given ID

type GcpDatastoreClient

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

GcpDatastoreClient is the client struct

func NewGcpDatastoreClient

func NewGcpDatastoreClient(projectID string) (c *GcpDatastoreClient, err error)

NewGcpDatastoreClient creates a new GcpDatastoreClient

type Librarian

type Librarian struct {
	Thinger     Thinger
	CreateTuber func(token *oauth2.Token) (Tuber, error)
}

Librarian provides the Thinger and Tuber creator

func New

func New() (*Librarian, error)

New creates a new Librarian to the ytlibrarian database

func (*Librarian) Close

func (l *Librarian) Close() error

Close cleans up the Librarian clients

type ThingNotFoundError

type ThingNotFoundError struct {
	ID  string
	Err error
}

ThingNotFoundError is an error thingy that can be checked for when a Thing was not found

func (*ThingNotFoundError) Error

func (e *ThingNotFoundError) Error() string

type ThingNotLinkedError

type ThingNotLinkedError struct {
	ThingID string
	Err     error
}

ThingNotLinkedError is an error thingy that can be checked for when a Thing was not found

func (*ThingNotLinkedError) Error

func (e *ThingNotLinkedError) Error() string

type Thinger

type Thinger interface {
	// contains filtered or unexported methods
}

Thinger defines the interface needed by any database client

type Tuber

type Tuber interface {

	// channelVideos returns all of the videos for the given channel
	// channelVideos(id string) ([]videoThing, error)
	GetMyPlaylists() ([]collectionThing, error)
	// contains filtered or unexported methods
}

Tuber defines the interface needed by the service where videos and stuff will be sourced from

type User

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

User is a reference to ... user ... data

func AddUser

func AddUser(thinger Thinger, user User) (User, error)

AddUser adds a User to the given Thinger

func GetUserByReferenceID

func GetUserByReferenceID(thinger Thinger, refID string) (User, error)

GetUserByReferenceID retrieves the user thing by the given external ID

type UserNotLinkedError

type UserNotLinkedError struct {
	UserID string
	Err    error
}

UserNotLinkedError is an error thingy that can be checked for when a Thing was not found

func (*UserNotLinkedError) Error

func (e *UserNotLinkedError) Error() string

type UserRequest

type UserRequest struct {
	ReferenceID string `json:"reference_id,omitempty"`
	Data        string `json:"data,omitempty"`
}

UserRequest is used with the POST /users endpoint

type Video

type Video struct {
	UserLinked bool   `json:"userLinked,omitempty"`
	Data       string `json:"data,omitempty"`
	// contains filtered or unexported fields
}

Video is a reference to a video along with metadata associated with the requesting user

func AddVideo

func AddVideo(thinger Thinger, tuber Tuber, id string) (video Video, err error)

AddVideo if missing from Thinger retrieves video details from the Tuber and adds it

func GetVideoByID

func GetVideoByID(thinger Thinger, user User, id uuid.UUID) (Video, error)

GetVideoByID retrieves the collection which matches the given ID

func GetVideoByReferenceID

func GetVideoByReferenceID(thinger Thinger, user User, refID string) (Video, error)

GetVideoByReferenceID retrieves the user thing by the given external ID

func GetVideosByUser

func GetVideosByUser(thinger Thinger, user User) ([]Video, error)

GetVideosByUser retrieves the collections which belong to the given user

type VideoRequest

type VideoRequest struct {
	Data string `json:"data,omitempty"`
}

VideoRequest is used with the PUT /videos endpoint

type YoutubeClient

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

YoutubeClient is a Tuber implementation that communicates with YouTube

func NewYoutubeClient

func NewYoutubeClient(clientID, secret string, token *oauth2.Token) (*YoutubeClient, error)

NewYoutubeClient creates an instance of the YouTube Service for the given user

func (YoutubeClient) GetMyPlaylists

func (c YoutubeClient) GetMyPlaylists() ([]collectionThing, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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