backend

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplayGainNone  = string(player.ReplayGainNone)
	ReplayGainAlbum = string(player.ReplayGainAlbum)
	ReplayGainTrack = string(player.ReplayGainTrack)
)
View Source
const CachedImageValidTime = 24 * time.Hour

Variables

View Source
var (
	ErrNoServers       = errors.New("no servers set up")
	ErrAnotherInstance = errors.New("another instance is running")
)
View Source
var (
	ErrNotFound = errors.New("item not found")
)
View Source
var ErrUnreachable = errors.New("server is unreachable")
View Source
var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"}

Functions

This section is empty.

Types

type AlbumPageConfig

type AlbumPageConfig struct {
	TracklistColumns []string
}

type AlbumsPageConfig

type AlbumsPageConfig struct {
	SortOrder string
}

type App

type App struct {
	Config          *Config
	ServerManager   *ServerManager
	ImageManager    *ImageManager
	PlaybackManager *PlaybackManager
	Player          *player.Player
	UpdateChecker   UpdateChecker
	OnReactivate    func()
	// contains filtered or unexported fields
}

func StartupApp

func StartupApp(appName, appVersionTag, configFile, latestReleaseURL string) (*App, error)

func (*App) DeleteServerCacheDir

func (a *App) DeleteServerCacheDir(serverID uuid.UUID) error

func (*App) LoginToDefaultServer

func (a *App) LoginToDefaultServer(string) error

func (*App) Shutdown

func (a *App) Shutdown()

func (*App) VersionTag

func (a *App) VersionTag() string

type AppConfig

type AppConfig struct {
	WindowWidth        int
	WindowHeight       int
	LastCheckedVersion string
	EnableSystemTray   bool
	CloseToSystemTray  bool
	StartupPage        string
	AllowMultiInstance bool

	// Experimental - may be removed in future
	FontNormalTTF string
	FontBoldTTF   string
}

type ArtistPageConfig

type ArtistPageConfig struct {
	InitialView      string
	TracklistColumns []string
}

type CacheItem

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

type Config

type Config struct {
	Application    AppConfig
	Servers        []*ServerConfig
	AlbumPage      AlbumPageConfig
	AlbumsPage     AlbumsPageConfig
	ArtistPage     ArtistPageConfig
	FavoritesPage  FavoritesPageConfig
	NowPlayingPage NowPlayingPageConfig
	PlaylistPage   PlaylistPageConfig
	PlaylistsPage  PlaylistsPageConfig
	TracksPage     TracksPageConfig
	LocalPlayback  LocalPlaybackConfig
	Scrobbling     ScrobbleConfig
	ReplayGain     ReplayGainConfig
	Theme          ThemeConfig
}

func DefaultConfig

func DefaultConfig(appVersionTag string) *Config

func ReadConfigFile

func ReadConfigFile(filepath, appVersionTag string) (*Config, error)

func (*Config) WriteConfigFile

func (c *Config) WriteConfigFile(filepath string) error

type FavoritesPageConfig

type FavoritesPageConfig struct {
	InitialView      string
	TracklistColumns []string
}

type ImageCache

type ImageCache struct {
	MinSize    int
	MaxSize    int
	DefaultTTL time.Duration
	// contains filtered or unexported fields
}

A custom in-memory cache for images with the following eviction strategy:

  1. If there are fewer than MinSize items in the cache, none will be evicted
  2. If a new addition would make the cache exceed MaxSize, an item will be immediately evicted 2a. in this case, evict the LRU expired item or if none expired, the LRU item
  3. If the size of the cache is between MaxSize and MinSize, expired items will be periodically evicted 3a. in this case, again the least recently used expired items will be evicted first

func (*ImageCache) EvictExpired

func (i *ImageCache) EvictExpired()

EvictExpired evicts least recently used expired items from the cache until there are no more expired items or the cache contains MinSize elements Holds the reader lock for O(n) time and writer lock for O(n)

func (*ImageCache) Get

func (i *ImageCache) Get(key string) (image.Image, error)

func (*ImageCache) GetExtendTTL

func (i *ImageCache) GetExtendTTL(key string, ttl time.Duration) (image.Image, error)

Gets the image if it exists and extends TTL to time.Now + ttl iff the image would expire before then

func (*ImageCache) GetResetTTL

func (i *ImageCache) GetResetTTL(key string, resetTTL bool) (image.Image, error)

func (*ImageCache) GetWithNewTTL

func (i *ImageCache) GetWithNewTTL(key string, newTtl time.Duration) (image.Image, error)

func (*ImageCache) Has

func (i *ImageCache) Has(key string) bool

func (*ImageCache) Init

func (i *ImageCache) Init(ctx context.Context, evictionInterval time.Duration)

func (*ImageCache) Set

func (i *ImageCache) Set(key string, val image.Image)

func (*ImageCache) SetWithTTL

func (i *ImageCache) SetWithTTL(key string, val image.Image, ttl time.Duration)

holds writer lock for O(i.MaxSize) worst case

type ImageManager

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

func NewImageManager

func NewImageManager(ctx context.Context, s *ServerManager, baseCacheDir string) *ImageManager

func (*ImageManager) FetchAndCacheArtistImage

func (i *ImageManager) FetchAndCacheArtistImage(artistID string, imgURL string) (image.Image, error)

func (*ImageManager) GetCachedArtistImage

func (i *ImageManager) GetCachedArtistImage(artistID string) (image.Image, bool)

func (*ImageManager) GetCoverThumbnail

func (i *ImageManager) GetCoverThumbnail(coverID string) (image.Image, error)

func (*ImageManager) GetCoverThumbnailFromCache

func (i *ImageManager) GetCoverThumbnailFromCache(coverID string) (image.Image, bool)

func (*ImageManager) GetCoverThumbnailWithTTL

func (i *ImageManager) GetCoverThumbnailWithTTL(coverID string, ttl time.Duration) (image.Image, error)

func (*ImageManager) GetFullSizeCoverArt

func (i *ImageManager) GetFullSizeCoverArt(coverID string) (image.Image, error)

func (*ImageManager) RefreshCachedArtistImageIfExpired

func (i *ImageManager) RefreshCachedArtistImageIfExpired(artistID string, imgURL string) error

type LocalPlaybackConfig

type LocalPlaybackConfig struct {
	AudioDeviceName       string
	AudioExclusive        bool
	InMemoryCacheSizeMB   int
	Volume                int
	EqualizerEnabled      bool
	EqualizerPreamp       float64
	GraphicEqualizerBands []float64
}

type NowPlayingPageConfig

type NowPlayingPageConfig struct {
	TracklistColumns []string
}

type PlaybackManager

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

A high-level Subsonic-aware playback backend. Manages loading tracks into the Player queue, sending callbacks on play time updates and track changes.

func NewPlaybackManager

func NewPlaybackManager(
	ctx context.Context,
	s *ServerManager,
	p *player.Player,
	scrobbleCfg *ScrobbleConfig,
) *PlaybackManager

func (*PlaybackManager) DisableCallbacks

func (p *PlaybackManager) DisableCallbacks()

Should only be called before quitting. Disables playback state callbacks being sent

func (*PlaybackManager) GetPlayQueue

func (p *PlaybackManager) GetPlayQueue() []*mediaprovider.Track

func (*PlaybackManager) IsSeeking

func (p *PlaybackManager) IsSeeking() bool

func (*PlaybackManager) LoadAlbum

func (p *PlaybackManager) LoadAlbum(albumID string, appendToQueue bool, shuffle bool) error

Loads the specified album into the play queue.

func (*PlaybackManager) LoadPlaylist

func (p *PlaybackManager) LoadPlaylist(playlistID string, appendToQueue bool, shuffle bool) error

Loads the specified playlist into the play queue.

func (*PlaybackManager) LoadTracks

func (p *PlaybackManager) LoadTracks(tracks []*mediaprovider.Track, appendToQueue, shuffle bool) error

func (*PlaybackManager) NowPlaying

func (p *PlaybackManager) NowPlaying() *mediaprovider.Track

Gets the curently playing song, if any.

func (*PlaybackManager) NowPlayingIndex added in v0.4.0

func (p *PlaybackManager) NowPlayingIndex() int

func (*PlaybackManager) OnLoopModeChange added in v0.4.0

func (p *PlaybackManager) OnLoopModeChange(cb func(string))

Registers a callback that is notified whenever the loop mode changes.

func (*PlaybackManager) OnPlayTimeUpdate

func (p *PlaybackManager) OnPlayTimeUpdate(cb func(float64, float64))

Registers a callback that is notified whenever the play time should be updated.

func (*PlaybackManager) OnSongChange

func (p *PlaybackManager) OnSongChange(cb func(nowPlaying *mediaprovider.Track, justScrobbledIfAny *mediaprovider.Track))

Sets a callback that is notified whenever a new song begins playing.

func (*PlaybackManager) OnTrackFavoriteStatusChanged

func (p *PlaybackManager) OnTrackFavoriteStatusChanged(id string, fav bool)

Any time the user changes the favorite status of a track elsewhere in the app, this should be called to ensure the in-memory track model is updated.

func (*PlaybackManager) OnTrackRatingChanged

func (p *PlaybackManager) OnTrackRatingChanged(id string, rating int)

Any time the user changes the rating of a track elsewhere in the app, this should be called to ensure the in-memory track model is updated.

func (*PlaybackManager) PlayAlbum

func (p *PlaybackManager) PlayAlbum(albumID string, firstTrack int, shuffle bool) error

func (*PlaybackManager) PlayFromBeginning

func (p *PlaybackManager) PlayFromBeginning() error

func (*PlaybackManager) PlayPlaylist

func (p *PlaybackManager) PlayPlaylist(playlistID string, firstTrack int, shuffle bool) error

func (*PlaybackManager) PlayRandomSongs

func (p *PlaybackManager) PlayRandomSongs(genreName string)

func (*PlaybackManager) PlaySimilarSongs

func (p *PlaybackManager) PlaySimilarSongs(id string)

func (*PlaybackManager) PlayTrackAt

func (p *PlaybackManager) PlayTrackAt(idx int) error

func (*PlaybackManager) RemoveTracksFromQueue

func (p *PlaybackManager) RemoveTracksFromQueue(trackIDs []string)

func (*PlaybackManager) SetNextLoopMode added in v0.4.0

func (p *PlaybackManager) SetNextLoopMode() error

Changes the loop mode of the player to the next one. Useful for toggling UI elements, to change modes without knowing the current player mode.

func (*PlaybackManager) SetReplayGainOptions

func (p *PlaybackManager) SetReplayGainOptions(config ReplayGainConfig)

func (*PlaybackManager) StopAndClearPlayQueue

func (p *PlaybackManager) StopAndClearPlayQueue()

Stop playback and clear the play queue.

type PlaylistPageConfig

type PlaylistPageConfig struct {
	TracklistColumns []string
}

type PlaylistsPageConfig

type PlaylistsPageConfig struct {
	InitialView string
}

type ReplayGainConfig

type ReplayGainConfig struct {
	Mode            string
	PreampGainDB    float64
	PreventClipping bool
}

type ScrobbleConfig

type ScrobbleConfig struct {
	Enabled              bool
	ThresholdTimeSeconds int
	ThresholdPercent     int
}

type ServerConfig

type ServerConfig struct {
	ServerConnection
	ID       uuid.UUID
	Nickname string
	Default  bool
}

type ServerConnection

type ServerConnection struct {
	Hostname    string
	AltHostname string
	Username    string
	LegacyAuth  bool
}

type ServerManager

type ServerManager struct {
	LoggedInUser string
	ServerID     uuid.UUID
	Server       mediaprovider.MediaProvider
	// contains filtered or unexported fields
}

func NewServerManager

func NewServerManager(appName string, config *Config) *ServerManager

func (*ServerManager) AddServer

func (s *ServerManager) AddServer(nickname string, connection ServerConnection) *ServerConfig

func (*ServerManager) ConnectToServer

func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error

func (*ServerManager) DeleteServer

func (s *ServerManager) DeleteServer(serverID uuid.UUID)

func (*ServerManager) GetDefaultServer

func (s *ServerManager) GetDefaultServer() *ServerConfig

func (*ServerManager) GetServerPassword

func (s *ServerManager) GetServerPassword(serverID uuid.UUID) (string, error)

func (*ServerManager) Logout

func (s *ServerManager) Logout(deletePassword bool)

func (*ServerManager) OnLogout

func (s *ServerManager) OnLogout(cb func())

Sets a callback that is invoked when the user logs out of a server.

func (*ServerManager) OnServerConnected

func (s *ServerManager) OnServerConnected(cb func())

Sets a callback that is invoked when a server is connected to.

func (*ServerManager) SetDefaultServer

func (s *ServerManager) SetDefaultServer(serverID uuid.UUID)

func (*ServerManager) SetPrefetchAlbumCoverCallback

func (s *ServerManager) SetPrefetchAlbumCoverCallback(cb func(string))

func (*ServerManager) SetServerPassword

func (s *ServerManager) SetServerPassword(server *ServerConfig, password string) error

func (*ServerManager) TestConnectionAndAuth

func (s *ServerManager) TestConnectionAndAuth(
	connection ServerConnection, password string, timeout time.Duration,
) error

type ThemeConfig

type ThemeConfig struct {
	ThemeFile  string
	Appearance string
}

type TracksPageConfig

type TracksPageConfig struct {
	TracklistColumns []string
}

type UpdateChecker

type UpdateChecker struct {
	OnUpdatedVersionFound func()
	// contains filtered or unexported fields
}

A component to check for updates from the Github releases/latest URL.

func NewUpdateChecker

func NewUpdateChecker(appVersionTag, latestReleaseURL string, lastCheckedTag *string) UpdateChecker

func (*UpdateChecker) CheckLatestVersionTag

func (u *UpdateChecker) CheckLatestVersionTag() string

func (*UpdateChecker) LatestReleaseURL

func (u *UpdateChecker) LatestReleaseURL() *url.URL

func (*UpdateChecker) Start

func (u *UpdateChecker) Start(ctx context.Context, interval time.Duration)

Start automatically polling for updates in the background. Quits when the given ctx's Done channel returns a value.

func (*UpdateChecker) VersionTagFound

func (u *UpdateChecker) VersionTagFound() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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