Documentation ¶
Index ¶
- Variables
- func AuthToToken(auth string) (*oauth2.Token, error)
- func ChunkSlice[T any](slice []T, chunkSize int) [][]T
- func CompareImages(url1, url2 url.URL) (bool, error)
- func CompareNames(name1, name2 string) float64
- func GenerateULID() string
- func GenerateWord() string
- func GetEntityURL(base string, etype EntityType, id RemoteID) url.URL
- func IsContextError(err error) bool
- func IsNil(values ...any) bool
- func IsValidPort(val int) error
- func LoadImageFromUrl(url url.URL) (image.Image, error)
- func Max(a, b int) int
- func Normalize(str string) string
- func NormalizeStringSliceSearchablePart(slice []string) []string
- func NumDiff(v1, v2 uint64) uint64
- func NumDiffWeight(v1, v2 uint64, weightMap map[uint64]float64) float64
- func OpenBrowser(url string) error
- func SameNameSlices(s1, s2 []string) float64
- func SearchableNormalized(who, what string) string
- func SearchablePart(str string) string
- func SearchablePart2(str string) string
- func Time(timestamp int64) time.Time
- func TimeNano(timestamp int64) time.Time
- func TimeNowStr() string
- func Timestamp(time time.Time) int64
- func TimestampNano(time time.Time) int64
- func TimestampNanoNow() int64
- func TimestampNow() int64
- func TokenToAuth(tok *oauth2.Token) (string, error)
- type Account
- type AccountActions
- type EntityID
- type EntityType
- type ErrAccountNotExists
- type ErrNoAvailableRemotes
- type ErrRemoteNotFound
- type LikedActions
- type PlaylistActions
- type Remote
- type RemoteActions
- type RemoteAlbum
- type RemoteArtist
- type RemoteEntity
- type RemoteID
- type RemoteName
- type RemotePlaylist
- type RemoteRepository
- type RemoteTrack
- type RepositoryID
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotImplemented = errors.New("not implemented") ErrNoRemoteActions = errors.New("remote actions not available") )
Functions ¶
func GenerateULID ¶
func GenerateULID() string
func GetEntityURL ¶
func GetEntityURL(base string, etype EntityType, id RemoteID) url.URL
func IsValidPort ¶
func LoadImageFromUrl ¶
Supports jpeg and png.
func NormalizeStringSliceSearchablePart ¶
Normalized vals in slice. Skips empty strings, cuts strings with SearchablePart.
func NumDiffWeight ¶
Number difference depend on weightMap.
Example:
v1 = 8, v2 = 10, weightMap = {0: 1.0, 1: 0.8, 2: 0.1}.
Result: 0.1.
func SearchableNormalized ¶
Who + " " + SearchablePart(what) - all in Normalize().
func SearchablePart ¶
Get first word of str. It might be more convenient to find something that way.
If splitted len == 0, returns str.
func SearchablePart2 ¶
Get first two words of str. It might be more convenient to find something that way.
Returns str, one or two words.
Types ¶
type Account ¶
type Account interface { // Unique ID for account. ID() RepositoryID // Account remote. RemoteName() RemoteName // Any text specified by the user so that he can distinguish one account from another. Alias() string // Set account alias. SetAlias(string) error // Account auth data like json tokens. Auth() string // Set account auth. SetAuth(string) error // Actions from remote account. Actions() (AccountActions, error) // Time when account was added. AddedAt() time.Time // Delete account from repository. Delete() error Repository() (RemoteRepository, error) }
Remote account.
type AccountActions ¶
type AccountActions interface { LikedAlbums() LikedActions LikedArtists() LikedActions LikedTracks() LikedActions Playlist() PlaylistActions }
Actions for remote account.
Only ErrNotImplemented can be returned as an error. But you must implement at least LikedArtists().
type EntityType ¶
type EntityType string
const ( EntityTypeAlbum EntityType = "album" EntityTypeArtist EntityType = "artist" EntityTypeTrack EntityType = "track" EntityTypePlaylist EntityType = "playlist" )
func (*EntityType) FromString ¶
func (e *EntityType) FromString(val string)
func (EntityType) String ¶
func (e EntityType) String() string
type ErrAccountNotExists ¶
type ErrAccountNotExists struct { Prefix, ID string }
func NewErrAccountNotExists ¶
func NewErrAccountNotExists(prefix string, id string) ErrAccountNotExists
func (ErrAccountNotExists) Error ¶
func (e ErrAccountNotExists) Error() string
type ErrNoAvailableRemotes ¶
type ErrNoAvailableRemotes struct { }
func NewErrNoAvailableRemotes ¶
func NewErrNoAvailableRemotes() ErrNoAvailableRemotes
func (ErrNoAvailableRemotes) Error ¶
func (e ErrNoAvailableRemotes) Error() string
type ErrRemoteNotFound ¶
type ErrRemoteNotFound struct {
Name RemoteName
}
func NewErrRemoteNotFound ¶
func NewErrRemoteNotFound(name RemoteName) ErrRemoteNotFound
func (ErrRemoteNotFound) Error ¶
func (e ErrRemoteNotFound) Error() string
type LikedActions ¶
type LikedActions interface { // Examples: get liked artists. Liked(context.Context) ([]RemoteEntity, error) // Examples: like artists. Like(ctx context.Context, ids []RemoteID) error // Examples: unlike artists. Unlike(ctx context.Context, ids []RemoteID) error }
Actions for entities created by the remote.
Example: artist, track, album.
type PlaylistActions ¶
type PlaylistActions interface { // Get user playlists. MyPlaylists(context.Context) ([]RemotePlaylist, error) // Create playlist. Create(ctx context.Context, name string, isVisible bool, description *string) (RemotePlaylist, error) // Delete my playlists. Delete(ctx context.Context, entities []RemoteID) error // Get playlist by ID. Playlist(context.Context, RemoteID) (RemotePlaylist, error) }
Playlist actions.
type Remote ¶
type Remote interface { // Provides repository for interacting with various things. // // Called once, after starting the program. Boot(RemoteRepository) error // Unique remote name. Name() RemoteName // Get repository. Repository() RemoteRepository // Assign actions for account. AssignAccountActions(Account) (AccountActions, error) // Get actions for remote. // // Example: take one of the accounts, and perform this actions from it. Actions() (RemoteActions, error) // Get url to entity. EntityURL(etype EntityType, id RemoteID) url.URL }
Example: music streaming service.
type RemoteActions ¶
type RemoteActions interface { // Get artist by ID. Artist(context.Context, RemoteID) (RemoteArtist, error) // Get track by ID. Track(context.Context, RemoteID) (RemoteTrack, error) // Get album by ID. Album(context.Context, RemoteID) (RemoteAlbum, error) // Search albums. SearchAlbums(context.Context, RemoteAlbum) ([10]RemoteAlbum, error) // Search artists. SearchArtists(context.Context, RemoteArtist) ([10]RemoteArtist, error) // Search tracks. SearchTracks(context.Context, RemoteTrack) ([10]RemoteTrack, error) }
General actions for remote.
type RemoteAlbum ¶
type RemoteAlbum interface { RemoteEntity // https://en.wikipedia.org/wiki/Universal_Product_Code UPC() *string // https://en.wikipedia.org/wiki/International_Article_Number EAN() *string Artists() []RemoteArtist TrackCount() int // Release year. Year() int // Cover (prefer 100x100). CoverURL() *url.URL }
Album from remote.
type RemoteArtist ¶
type RemoteArtist interface { RemoteEntity // Albums names (oldest first). OldestAlbumsNames(ctx context.Context) ([20]string, error) // Singles names (oldest first). OldestSinglesNames(ctx context.Context) ([20]string, error) }
Artist from remote.
type RemoteEntity ¶
type RemoteEntity interface { // Example: Spotify. RemoteName() RemoteName // Example: Spotify artist ID. ID() RemoteID // Example: Spotify artist name. Name() string }
Remote entity.
type RemoteName ¶
type RemoteName string
Example: "Spotify".
func (*RemoteName) FromString ¶
func (r *RemoteName) FromString(val string)
func (RemoteName) String ¶
func (r RemoteName) String() string
type RemotePlaylist ¶
type RemotePlaylist interface { RemoteEntity FromAccount() Account // Should be nil only if remote doesn't support set descriptions. Description() *string // Playlist tracks. Tracks(context.Context) ([]RemoteTrack, error) // Rename playlist. Rename(context.Context, string) error // Set playlist description. SetDescription(context.Context, string) error // Add tracks to playlist. AddTracks(context.Context, []RemoteID) error // Remove tracks from playlist. RemoveTracks(context.Context, []RemoteID) error // Is playlist visible? // // Can return error only if remote doesn't support vis. IsVisible() (bool, error) // Set playlist visibility. True = visible. SetIsVisible(context.Context, bool) error }
User playlist from remote.
type RemoteRepository ¶
type RemoteRepository interface { // Unique ID. ID() RepositoryID // Remote name. Name() RemoteName // Alias: any text specified by the user so that he can distinguish one account from another. // // Auth: any auth like json tokens. // // After creating the account, the AssignActions method will be called in the remote. CreateAccount(alias string, auth string) (Account, error) // All accounts in remote. Accounts(ctx context.Context) ([]Account, error) // Get account by ID. Returns nil, nil if account not found. Account(id RepositoryID) (Account, error) // Global remote actions. Actions() (RemoteActions, error) }
Remote repository.
type RemoteTrack ¶
type RemoteTrack interface { RemoteEntity // https://en.wikipedia.org/wiki/International_Standard_Recording_Code ISRC() *string Artists() []RemoteArtist Album() (RemoteAlbum, error) // Length of track in ms. LengthMs() int // Release year. Year() int // Cover (prefer 100x100). CoverURL() *url.URL }
Track from remote.
type RepositoryID ¶
type RepositoryID string
Example: ID in database.
func (RepositoryID) String ¶
func (e RepositoryID) String() string