add back prefetching album cover callback to iterators
This commit is contained in:
+3
-3
@@ -63,9 +63,9 @@ func StartupApp(appName, appVersionTag, configFile, latestReleaseURL string) (*A
|
|||||||
a.ServerManager = NewServerManager(appName)
|
a.ServerManager = NewServerManager(appName)
|
||||||
a.PlaybackManager = NewPlaybackManager(a.bgrndCtx, a.ServerManager, a.Player, &a.Config.Scrobbling)
|
a.PlaybackManager = NewPlaybackManager(a.bgrndCtx, a.ServerManager, a.Player, &a.Config.Scrobbling)
|
||||||
a.ImageManager = NewImageManager(a.bgrndCtx, a.ServerManager, configdir.LocalCache(a.appName))
|
a.ImageManager = NewImageManager(a.bgrndCtx, a.ServerManager, configdir.LocalCache(a.appName))
|
||||||
//a.LibraryManager.PreCacheCoverFn = func(coverID string) {
|
a.ServerManager.SetPrefetchAlbumCoverCallback(func(coverID string) {
|
||||||
//_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||||
//}
|
})
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ type Favorites struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MediaProvider interface {
|
type MediaProvider interface {
|
||||||
|
SetPrefetchCoverCallback(cb func(coverArtID string))
|
||||||
|
|
||||||
GetAlbum(albumID string) (*AlbumWithTracks, error)
|
GetAlbum(albumID string) (*AlbumWithTracks, error)
|
||||||
|
|
||||||
GetArtist(artistID string) (*ArtistWithAlbums, error)
|
GetArtist(artistID string) (*ArtistWithAlbums, error)
|
||||||
|
|||||||
@@ -60,28 +60,28 @@ func filterMatches(f mediaprovider.AlbumFilter, album *subsonic.AlbumID3) bool {
|
|||||||
|
|
||||||
func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
||||||
if sortOrder == "" && len(filter.Genres) == 1 {
|
if sortOrder == "" && len(filter.Genres) == 1 {
|
||||||
return s.newBaseIter("byGenre", filter, map[string]string{"genre": filter.Genres[0]})
|
return s.newBaseIter("byGenre", filter, s.prefetchCoverCB, map[string]string{"genre": filter.Genres[0]})
|
||||||
}
|
}
|
||||||
if sortOrder == "" && filter.ExcludeUnfavorited {
|
if sortOrder == "" && filter.ExcludeUnfavorited {
|
||||||
return s.newBaseIter("starred", filter, make(map[string]string))
|
return s.newBaseIter("starred", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
}
|
}
|
||||||
switch sortOrder {
|
switch sortOrder {
|
||||||
case AlbumSortRecentlyAdded:
|
case AlbumSortRecentlyAdded:
|
||||||
return s.newBaseIter("newest", filter, make(map[string]string))
|
return s.newBaseIter("newest", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
case AlbumSortRecentlyPlayed:
|
case AlbumSortRecentlyPlayed:
|
||||||
return s.newBaseIter("recent", filter, make(map[string]string))
|
return s.newBaseIter("recent", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
case AlbumSortFrequentlyPlayed:
|
case AlbumSortFrequentlyPlayed:
|
||||||
return s.newBaseIter("frequent", filter, make(map[string]string))
|
return s.newBaseIter("frequent", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
case AlbumSortRandom:
|
case AlbumSortRandom:
|
||||||
return s.newRandomIter()
|
return s.newRandomIter(filter, s.prefetchCoverCB)
|
||||||
case AlbumSortTitleAZ:
|
case AlbumSortTitleAZ:
|
||||||
return s.newBaseIter("alphabeticalByName", filter, make(map[string]string))
|
return s.newBaseIter("alphabeticalByName", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
case AlbumSortArtistAZ:
|
case AlbumSortArtistAZ:
|
||||||
return s.newBaseIter("alphabeticalByArtist", filter, make(map[string]string))
|
return s.newBaseIter("alphabeticalByArtist", filter, s.prefetchCoverCB, make(map[string]string))
|
||||||
case AlbumSortYearAscending:
|
case AlbumSortYearAscending:
|
||||||
return s.newBaseIter("byYear", filter, map[string]string{"fromYear": "0", "toYear": "3000"})
|
return s.newBaseIter("byYear", filter, s.prefetchCoverCB, map[string]string{"fromYear": "0", "toYear": "3000"})
|
||||||
case AlbumSortYearDescending:
|
case AlbumSortYearDescending:
|
||||||
return s.newBaseIter("byYear", filter, map[string]string{"fromYear": "3000", "toYear": "0"})
|
return s.newBaseIter("byYear", filter, s.prefetchCoverCB, map[string]string{"fromYear": "3000", "toYear": "0"})
|
||||||
default:
|
default:
|
||||||
log.Printf("Undefined album sort order: %s", sortOrder)
|
log.Printf("Undefined album sort order: %s", sortOrder)
|
||||||
return nil
|
return nil
|
||||||
@@ -89,12 +89,13 @@ func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) SearchAlbums(searchQuery string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
func (s *subsonicMediaProvider) SearchAlbums(searchQuery string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
||||||
return s.newSearchIter(searchQuery, filter)
|
return s.newSearchIter(searchQuery, filter, s.prefetchCoverCB)
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseIter struct {
|
type baseIter struct {
|
||||||
listType string
|
listType string
|
||||||
filter mediaprovider.AlbumFilter
|
filter mediaprovider.AlbumFilter
|
||||||
|
prefetchCB func(string)
|
||||||
serverPos int
|
serverPos int
|
||||||
s *subsonic.Client
|
s *subsonic.Client
|
||||||
opts map[string]string
|
opts map[string]string
|
||||||
@@ -103,12 +104,13 @@ type baseIter struct {
|
|||||||
done bool
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) newBaseIter(listType string, filter mediaprovider.AlbumFilter, opts map[string]string) *baseIter {
|
func (s *subsonicMediaProvider) newBaseIter(listType string, filter mediaprovider.AlbumFilter, cb func(string), opts map[string]string) *baseIter {
|
||||||
return &baseIter{
|
return &baseIter{
|
||||||
listType: listType,
|
prefetchCB: cb,
|
||||||
filter: filter,
|
listType: listType,
|
||||||
s: s.client,
|
filter: filter,
|
||||||
opts: opts,
|
s: s.client,
|
||||||
|
opts: opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,20 +143,18 @@ func (r *baseIter) Next() *mediaprovider.Album {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.prefetchedPos = 1
|
r.prefetchedPos = 1
|
||||||
/*
|
if r.prefetchCB != nil {
|
||||||
if r.l.PreCacheCoverFn != nil {
|
for _, album := range r.prefetched {
|
||||||
for _, album := range r.prefetched {
|
go r.prefetchCB(album.CoverArtID)
|
||||||
go r.l.PreCacheCoverFn(album.CoverArt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
return r.prefetched[0]
|
return r.prefetched[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
type searchIter struct {
|
type searchIter struct {
|
||||||
searchIterBase
|
searchIterBase
|
||||||
|
|
||||||
|
prefetchCB func(string)
|
||||||
filter mediaprovider.AlbumFilter
|
filter mediaprovider.AlbumFilter
|
||||||
prefetched []*subsonic.AlbumID3
|
prefetched []*subsonic.AlbumID3
|
||||||
prefetchedPos int
|
prefetchedPos int
|
||||||
@@ -162,12 +162,13 @@ type searchIter struct {
|
|||||||
done bool
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) newSearchIter(query string, filter mediaprovider.AlbumFilter) *searchIter {
|
func (s *subsonicMediaProvider) newSearchIter(query string, filter mediaprovider.AlbumFilter, cb func(string)) *searchIter {
|
||||||
return &searchIter{
|
return &searchIter{
|
||||||
searchIterBase: searchIterBase{
|
searchIterBase: searchIterBase{
|
||||||
query: query,
|
query: query,
|
||||||
s: s.client,
|
s: s.client,
|
||||||
},
|
},
|
||||||
|
prefetchCB: cb,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
albumIDset: make(map[string]bool),
|
albumIDset: make(map[string]bool),
|
||||||
}
|
}
|
||||||
@@ -241,16 +242,16 @@ func (s *searchIter) addNewAlbums(al []*subsonic.AlbumID3) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.prefetched = append(s.prefetched, album)
|
s.prefetched = append(s.prefetched, album)
|
||||||
/*
|
if s.prefetchCB != nil {
|
||||||
if s.l.PreCacheCoverFn != nil {
|
go s.prefetchCB(album.CoverArt)
|
||||||
go s.l.PreCacheCoverFn(album.CoverArt)
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
s.albumIDset[album.ID] = true
|
s.albumIDset[album.ID] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type randomIter struct {
|
type randomIter struct {
|
||||||
|
filter mediaprovider.AlbumFilter
|
||||||
|
prefetchCB func(coverArtID string)
|
||||||
albumIDSet map[string]bool
|
albumIDSet map[string]bool
|
||||||
s *subsonic.Client
|
s *subsonic.Client
|
||||||
prefetched []*subsonic.AlbumID3
|
prefetched []*subsonic.AlbumID3
|
||||||
@@ -266,8 +267,10 @@ type randomIter struct {
|
|||||||
done bool
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) newRandomIter() *randomIter {
|
func (s *subsonicMediaProvider) newRandomIter(filter mediaprovider.AlbumFilter, cb func(string)) *randomIter {
|
||||||
return &randomIter{
|
return &randomIter{
|
||||||
|
filter: filter,
|
||||||
|
prefetchCB: cb,
|
||||||
s: s.client,
|
s: s.client,
|
||||||
albumIDSet: make(map[string]bool),
|
albumIDSet: make(map[string]bool),
|
||||||
}
|
}
|
||||||
@@ -293,13 +296,11 @@ func (r *randomIter) Next() *mediaprovider.Album {
|
|||||||
}
|
}
|
||||||
r.offset += len(albums)
|
r.offset += len(albums)
|
||||||
for _, album := range albums {
|
for _, album := range albums {
|
||||||
if _, ok := r.albumIDSet[album.ID]; !ok {
|
if _, ok := r.albumIDSet[album.ID]; !ok && filterMatches(r.filter, album) {
|
||||||
r.prefetched = append(r.prefetched, album)
|
r.prefetched = append(r.prefetched, album)
|
||||||
/*
|
if r.prefetchCB != nil {
|
||||||
if r.l.PreCacheCoverFn != nil {
|
go r.prefetchCB(album.CoverArt)
|
||||||
go r.l.PreCacheCoverFn(album.CoverArt)
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
r.albumIDSet[album.ID] = true
|
r.albumIDSet[album.ID] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,14 +316,12 @@ func (r *randomIter) Next() *mediaprovider.Album {
|
|||||||
}
|
}
|
||||||
var hitCount int
|
var hitCount int
|
||||||
for _, album := range albums {
|
for _, album := range albums {
|
||||||
if _, ok := r.albumIDSet[album.ID]; !ok {
|
if _, ok := r.albumIDSet[album.ID]; !ok && filterMatches(r.filter, album) {
|
||||||
hitCount++
|
hitCount++
|
||||||
r.prefetched = append(r.prefetched, album)
|
r.prefetched = append(r.prefetched, album)
|
||||||
/*
|
if r.prefetchCB != nil {
|
||||||
if r.l.PreCacheCoverFn != nil {
|
go r.prefetchCB(album.CoverArt)
|
||||||
go r.l.PreCacheCoverFn(album.CoverArt)
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
r.albumIDSet[album.ID] = true
|
r.albumIDSet[album.ID] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type subsonicMediaProvider struct {
|
type subsonicMediaProvider struct {
|
||||||
client *subsonic.Client
|
client *subsonic.Client
|
||||||
|
prefetchCoverCB func(coverArtID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubsonicMediaProvider(subsonicClient *subsonic.Client) mediaprovider.MediaProvider {
|
func SubsonicMediaProvider(subsonicClient *subsonic.Client) mediaprovider.MediaProvider {
|
||||||
return &subsonicMediaProvider{client: subsonicClient}
|
return &subsonicMediaProvider{client: subsonicClient}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *subsonicMediaProvider) SetPrefetchCoverCallback(cb func(coverArtID string)) {
|
||||||
|
s.prefetchCoverCB = cb
|
||||||
|
}
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) CreatePlaylist(name string, trackIDs []string) error {
|
func (s *subsonicMediaProvider) CreatePlaylist(name string, trackIDs []string) error {
|
||||||
return s.client.CreatePlaylistWithTracks(trackIDs, map[string]string{"name": name})
|
return s.client.CreatePlaylistWithTracks(trackIDs, map[string]string{"name": name})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type ServerManager struct {
|
|||||||
ServerID uuid.UUID
|
ServerID uuid.UUID
|
||||||
Server mediaprovider.MediaProvider
|
Server mediaprovider.MediaProvider
|
||||||
|
|
||||||
|
prefetchCoverCB func(string)
|
||||||
appName string
|
appName string
|
||||||
onServerConnected []func()
|
onServerConnected []func()
|
||||||
onLogout []func()
|
onLogout []func()
|
||||||
@@ -29,12 +30,20 @@ func NewServerManager(appName string) *ServerManager {
|
|||||||
return &ServerManager{appName: appName}
|
return &ServerManager{appName: appName}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerManager) SetPrefetchAlbumCoverCallback(cb func(string)) {
|
||||||
|
s.prefetchCoverCB = cb
|
||||||
|
if s.Server != nil {
|
||||||
|
s.Server.SetPrefetchCoverCallback(cb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error {
|
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error {
|
||||||
cli, err := s.testConnectionAndCreateClient(conf.ServerConnection, password)
|
cli, err := s.testConnectionAndCreateClient(conf.ServerConnection, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Server = subsonicMP.SubsonicMediaProvider(cli)
|
s.Server = subsonicMP.SubsonicMediaProvider(cli)
|
||||||
|
s.Server.SetPrefetchCoverCallback(s.prefetchCoverCB)
|
||||||
s.LoggedInUser = conf.Username
|
s.LoggedInUser = conf.Username
|
||||||
s.ServerID = conf.ID
|
s.ServerID = conf.ID
|
||||||
for _, cb := range s.onServerConnected {
|
for _, cb := range s.onServerConnected {
|
||||||
|
|||||||
Reference in New Issue
Block a user