ytlibrarian

package module
v0.7.0-1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 18 Imported by: 6

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

View Source
var ErrCreateConflict = errors.New("cannot create duplicate item")

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 PlaylistVideos

func PlaylistVideos(c YoutubeClient, id string) ([]string, error)

PlaylistVideos retrieves the IDs of the videos in a playlist

func RemoveAllCollectionItems

func RemoveAllCollectionItems(thinger Thinger, collectionID uuid.UUID) error

RemoveAllCollectionItems removes all items in a collection

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 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 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 Librarian

type Librarian struct {
	Thinger     Thinger
	CreateTuber func(token *oauth2.Token) (Tuber, error)
	// contains filtered or unexported fields
}

Librarian provides the Thinger and Tuber creator

func New

func New(options ...Option) (*Librarian, error)

New creates a new Librarian with the provided options

func (*Librarian) Close

func (l *Librarian) Close() error

Close cleans up the Librarian clients

type Option

type Option func(*Librarian)

Option is a function that configures a Librarian

func WithThinger

func WithThinger(thinger Thinger) Option

WithThinger sets the Thinger for the Librarian

func WithTuberAuth

func WithTuberAuth(clientID, clientSecret string) Option

WithTuberAuth sets the OAuth client id and secret for the Tuber to use

type Thing

type Thing interface {
	GetID() string
	SetID(id string)
	GetType() string
	SetType(typ string)
	GetReferenceID() string
	SetReferenceID(refID string)
	GetData() string
	SetData(data string)
}

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 {
	// AddThing creates a new entity to storage
	AddThing(t Thing) error
	// UpdateThing updates a new entity in storage
	UpdateThing(t Thing) error
	// RemoveThing deletes an existing thing from storage
	RemoveThing(id string) error
	// GetThing returns a single thing instance based on its ID
	GetThing(id string) (Thing, error)
	// GetThingByReferenceID returns a single thing instance based on its ReferenceID
	GetThingByReferenceID(id string) (Thing, error)
	// GetThingsByReferenceIDs returns multiple things based on a slice of ReferenceIDs
	GetThingsByReferenceIDs(ids []string) ([]Thing, error)
	// GetAllThings retrieves every thing
	GetAllThings() ([]Thing, error)
	// GetAllThingsByType retrieves every thing for the given type
	GetAllThingsByType(thingType string) ([]Thing, error)
	// MakeRelationship creates a relational entry between two Things
	MakeRelationship(parentID, childID, data string) error
	// UpdateRelationshipData updates the data associated with the matching parent/child relationships
	UpdateRelationshipData(parentID, childID, data string) error
	// GetRelationshipData data associated with the matching parent/child relationships
	GetRelationshipData(parentID, childID string) (string, error)
	// GetParents returns IDs of all Things which are parents of the identified Thing
	GetParents(childID string) ([]Thing, error)
	// GetChildren returns IDs of all Things which are children of the identified Thing
	GetChildren(parentID string) ([]Thing, error)
	// BreakRelationship removes a relational entry between two Things
	BreakRelationship(parentID, childID string) error
	// Close the Thinger connection
	Close() error
}

Thinger defines the interface needed by any database client

type Tuber

type Tuber interface {
	// VideoDetails returns details associated with the identified video
	VideoDetails(id string) (videoThing, error)
	// ChannelDetails returns details associated with the identified video
	ChannelDetails(id string) (channelThing, error)
	// ChannelPlaylists returns all of the playlists for the given channel
	ChannelPlaylists(id string) ([]collectionThing, error)
	// ChannelVideos returns all of the videos for the given channel
	// ChannelVideos(id string) ([]videoThing, error)
	// MyPlaylists returns all of the playlists associated with the user the service is created for
	MyPlaylists() ([]collectionThing, error)
	// playlistDetails returns details associated with the identified playlist
	PlaylistDetails(id string) (collectionThing, error)
	// PlaylistInsert creates a playlist from the given Collection
	PlaylistInsert(collection collectionThing) (string, error)
	// PlaylistUpdate updates an existing playlist
	PlaylistUpdate(collection collectionThing) error
	// PlaylistDelete removes an existing playlist by ID
	PlaylistDelete(id string) error
	// PlaylistVideos retrieves the videos in a playlist
	PlaylistVideos(id string) ([]string, error)
	// PlaylistVideoInsert adds a video to a playlist
	PlaylistVideoInsert(playlistID, videoID string, pos int64) error
	// PlaylistVideoUpdate updates the position of a video
	PlaylistVideoUpdate(playlistID, videoID string, pos int64) error
	// PlaylistVideoDelete removes a video from a playlist
	PlaylistVideoDelete(playlistID, videoID string, pos int64) error
}

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 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 GetVideosByReferenceIDs

func GetVideosByReferenceIDs(thinger Thinger, user User, refIDs []string) ([]Video, error)

GetVideosByReferenceIDs retrieves the user thing by the given external IDs

func GetVideosByUser

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

GetVideosByUser retrieves the collections which belong to the given user

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) ChannelDetails

func (c YoutubeClient) ChannelDetails(id string) (channelThing, error)

ChannelDetails returns details associated with the identified video

func (YoutubeClient) ChannelPlaylists

func (c YoutubeClient) ChannelPlaylists(channelID string) ([]collectionThing, error)

ChannelPlaylists returns all of the playlists for the given channel

func (YoutubeClient) MyPlaylists

func (c YoutubeClient) MyPlaylists() ([]YoutubePlaylist, error)

myPlaylists returns all of the playlists associated with the user the service is created for

func (YoutubeClient) PlaylistDelete

func (c YoutubeClient) PlaylistDelete(id string) error

PlaylistDelete removes an existing playlist by ID

func (YoutubeClient) PlaylistDetails

func (c YoutubeClient) PlaylistDetails(id string) (collectionThing, error)

PlaylistDetails returns details associated with the identified playlist

func (YoutubeClient) PlaylistInsert

func (c YoutubeClient) PlaylistInsert(collection collectionThing) (string, error)

PlaylistInsert creates a playlist from the given Collection

func (YoutubeClient) PlaylistUpdate

func (c YoutubeClient) PlaylistUpdate(collection collectionThing) error

PlaylistUpdate updates an existing playlist's metadata

func (YoutubeClient) PlaylistVideoDelete

func (c YoutubeClient) PlaylistVideoDelete(playlistID, videoID string, pos int64) error

PlaylistVideoDelete removes a video from a playlist

func (YoutubeClient) PlaylistVideoInsert

func (c YoutubeClient) PlaylistVideoInsert(playlistID, videoID string, pos int64) error

PlaylistVideoInsert adds a video to a playlist

func (YoutubeClient) PlaylistVideoUpdate

func (c YoutubeClient) PlaylistVideoUpdate(playlistID, videoID string, pos int64) error

PlaylistVideoUpdate updates the position of a video

func (YoutubeClient) PlaylistVideos

func (c YoutubeClient) PlaylistVideos(id string) ([]string, error)

PlaylistVideos retrieves the IDs of the videos in a playlist

func (YoutubeClient) VideoDetails

func (c YoutubeClient) VideoDetails(id string) (videoThing, error)

VideoDetails returns details associated with the identified video

type YoutubePlaylist

type YoutubePlaylist = collectionThing

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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