begin the refactoring - doesnt compile
This commit is contained in:
@@ -26,9 +26,9 @@ type RatingFavoriteParameters struct {
|
||||
}
|
||||
|
||||
type Favorites struct {
|
||||
Albums []Album
|
||||
Artists []Artist
|
||||
Tracks []Track
|
||||
Albums []*Album
|
||||
Artists []*Artist
|
||||
Tracks []*Track
|
||||
}
|
||||
|
||||
type MediaProvider interface {
|
||||
@@ -48,19 +48,19 @@ type MediaProvider interface {
|
||||
|
||||
IterateTracks(searchQuery string) TrackIterator
|
||||
|
||||
GetRandomTracks(genre string, count int) ([]Track, error)
|
||||
GetRandomTracks(genre string, count int) ([]*Track, error)
|
||||
|
||||
GetSimilarTracks(artistID string, count int) ([]Track, error)
|
||||
GetSimilarTracks(artistID string, count int) ([]*Track, error)
|
||||
|
||||
GetArtists() ([]Artist, error)
|
||||
GetArtists() ([]*Artist, error)
|
||||
|
||||
GetGenres() ([]Genre, error)
|
||||
GetGenres() ([]*Genre, error)
|
||||
|
||||
GetFavorites() (Favorites, error)
|
||||
|
||||
GetStreamURL(trackID string) (string, error)
|
||||
|
||||
SetFavorite(params RatingFavoriteParameters) error
|
||||
SetFavorite(params RatingFavoriteParameters, favorite bool) error
|
||||
|
||||
SetRating(params RatingFavoriteParameters, rating int) error
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type Album struct {
|
||||
|
||||
type AlbumWithTracks struct {
|
||||
Album
|
||||
Tracks []Track
|
||||
Tracks []*Track
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
@@ -26,14 +26,14 @@ type Artist struct {
|
||||
|
||||
type ArtistWithAlbums struct {
|
||||
Artist
|
||||
Albums []Album
|
||||
Albums []*Album
|
||||
}
|
||||
|
||||
type ArtistInfo struct {
|
||||
Biography string
|
||||
LastFMUrl string
|
||||
ImageURL string
|
||||
SimilarArtists []Artist
|
||||
SimilarArtists []*Artist
|
||||
}
|
||||
|
||||
type Genre struct {
|
||||
@@ -54,11 +54,14 @@ type Track struct {
|
||||
ArtistIDs []string
|
||||
ArtistNames []string
|
||||
Album string
|
||||
AlbumID string
|
||||
Year int
|
||||
Rating int
|
||||
Favorite bool
|
||||
Size int64
|
||||
PlayCount int
|
||||
FilePath string
|
||||
BitRate int
|
||||
}
|
||||
|
||||
type Playlist struct {
|
||||
@@ -73,5 +76,5 @@ type Playlist struct {
|
||||
|
||||
type PlaylistWithTracks struct {
|
||||
Playlist
|
||||
Tracks []Track
|
||||
Tracks []*Track
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ type baseIter struct {
|
||||
serverPos int
|
||||
s *subsonic.Client
|
||||
opts map[string]string
|
||||
prefetched []mediaprovider.Album
|
||||
prefetched []*mediaprovider.Album
|
||||
prefetchedPos int
|
||||
done bool
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (r *baseIter) Next() *mediaprovider.Album {
|
||||
if r.prefetched != nil && r.prefetchedPos < len(r.prefetched) {
|
||||
a := r.prefetched[r.prefetchedPos]
|
||||
r.prefetchedPos++
|
||||
return &a
|
||||
return a
|
||||
}
|
||||
r.prefetched = nil
|
||||
for { // keep fetching until we are done or have mathcing results
|
||||
@@ -129,8 +129,7 @@ func (r *baseIter) Next() *mediaprovider.Album {
|
||||
}
|
||||
*/
|
||||
|
||||
ret := r.prefetched[0]
|
||||
return &ret
|
||||
return r.prefetched[0]
|
||||
}
|
||||
|
||||
type searchIter struct {
|
||||
@@ -207,8 +206,7 @@ func (s *searchIter) Next() *mediaprovider.Album {
|
||||
s.prefetchedPos = 0
|
||||
}
|
||||
|
||||
al := toAlbum(a)
|
||||
return &al
|
||||
return toAlbum(a)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -323,8 +321,7 @@ func (r *randomIter) Next() *mediaprovider.Album {
|
||||
r.prefetchedPos = 0
|
||||
}
|
||||
|
||||
al := toAlbum(a)
|
||||
return &al
|
||||
return toAlbum(a)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,7 +2,6 @@ package subsonic
|
||||
|
||||
import (
|
||||
"image"
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
"sync"
|
||||
@@ -115,12 +114,12 @@ func (s *subsonicMediaProvider) GetArtistInfo(artistID string) (*mediaprovider.A
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetArtists() ([]mediaprovider.Artist, error) {
|
||||
func (s *subsonicMediaProvider) GetArtists() ([]*mediaprovider.Artist, error) {
|
||||
idxs, err := s.client.GetArtists(map[string]string{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var artists []mediaprovider.Artist
|
||||
var artists []*mediaprovider.Artist
|
||||
for _, idx := range idxs.Index {
|
||||
for _, ar := range idx.Artist {
|
||||
artists = append(artists, toArtistFromID3(ar))
|
||||
@@ -130,7 +129,11 @@ func (s *subsonicMediaProvider) GetArtists() ([]mediaprovider.Artist, error) {
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetCoverArt(id string, size int) (image.Image, error) {
|
||||
return s.client.GetCoverArt(id, map[string]string{"size": strconv.Itoa(size)})
|
||||
params := map[string]string{}
|
||||
if size > 0 {
|
||||
params["size"] = strconv.Itoa(size)
|
||||
}
|
||||
return s.client.GetCoverArt(id, params)
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetFavorites() (mediaprovider.Favorites, error) {
|
||||
@@ -145,13 +148,13 @@ func (s *subsonicMediaProvider) GetFavorites() (mediaprovider.Favorites, error)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetGenres() ([]mediaprovider.Genre, error) {
|
||||
func (s *subsonicMediaProvider) GetGenres() ([]*mediaprovider.Genre, error) {
|
||||
g, err := s.client.GetGenres()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sharedutil.MapSlice(g, func(g *subsonic.Genre) mediaprovider.Genre {
|
||||
return mediaprovider.Genre{
|
||||
return sharedutil.MapSlice(g, func(g *subsonic.Genre) *mediaprovider.Genre {
|
||||
return &mediaprovider.Genre{
|
||||
Name: g.Name,
|
||||
AlbumCount: g.AlbumCount,
|
||||
TrackCount: g.SongCount,
|
||||
@@ -178,7 +181,7 @@ func (s *subsonicMediaProvider) GetPlaylists() ([]mediaprovider.Playlist, error)
|
||||
return sharedutil.MapSlice(pl, toPlaylist), nil
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetRandomTracks(genreName string, count int) ([]mediaprovider.Track, error) {
|
||||
func (s *subsonicMediaProvider) GetRandomTracks(genreName string, count int) ([]*mediaprovider.Track, error) {
|
||||
opts := map[string]string{"size": strconv.Itoa(count)}
|
||||
if genreName != "" {
|
||||
opts["genre"] = genreName
|
||||
@@ -190,7 +193,7 @@ func (s *subsonicMediaProvider) GetRandomTracks(genreName string, count int) ([]
|
||||
return sharedutil.MapSlice(tr, toTrack), nil
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) GetSimilarTracks(artistID string, count int) ([]mediaprovider.Track, error) {
|
||||
func (s *subsonicMediaProvider) GetSimilarTracks(artistID string, count int) ([]*mediaprovider.Track, error) {
|
||||
tr, err := s.client.GetSimilarSongs2(artistID, map[string]string{"count": strconv.Itoa(count)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -216,12 +219,16 @@ func (s *subsonicMediaProvider) Scrobble(trackID string, submission bool) error
|
||||
"submission": strconv.FormatBool(submission)})
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) SetFavorite(params mediaprovider.RatingFavoriteParameters) error {
|
||||
return s.client.Star(subsonic.StarParameters{
|
||||
func (s *subsonicMediaProvider) SetFavorite(params mediaprovider.RatingFavoriteParameters, favorite bool) error {
|
||||
subParams := subsonic.StarParameters{
|
||||
AlbumIDs: params.AlbumIDs,
|
||||
ArtistIDs: params.ArtistIDs,
|
||||
SongIDs: params.TrackIDs,
|
||||
})
|
||||
}
|
||||
if favorite {
|
||||
return s.client.Star(subParams)
|
||||
}
|
||||
return s.client.Unstar(subParams)
|
||||
}
|
||||
|
||||
func (s *subsonicMediaProvider) SetRating(params mediaprovider.RatingFavoriteParameters, rating int) error {
|
||||
@@ -263,12 +270,11 @@ func (s *subsonicMediaProvider) SetRating(params mediaprovider.RatingFavoritePar
|
||||
return err
|
||||
}
|
||||
|
||||
func toTrack(ch *subsonic.Child) mediaprovider.Track {
|
||||
func toTrack(ch *subsonic.Child) *mediaprovider.Track {
|
||||
if ch == nil {
|
||||
log.Println("subsonicMediaProvider: toTrack called on nil track")
|
||||
return mediaprovider.Track{}
|
||||
return nil
|
||||
}
|
||||
return mediaprovider.Track{
|
||||
return &mediaprovider.Track{
|
||||
ID: ch.ID,
|
||||
CoverArtID: ch.CoverArt,
|
||||
ParentID: ch.Parent,
|
||||
@@ -280,19 +286,21 @@ func toTrack(ch *subsonic.Child) mediaprovider.Track {
|
||||
ArtistIDs: []string{ch.ArtistID},
|
||||
ArtistNames: []string{ch.Artist},
|
||||
Album: ch.Album,
|
||||
AlbumID: ch.AlbumID,
|
||||
Year: ch.Year,
|
||||
Rating: ch.UserRating,
|
||||
Favorite: !ch.Starred.IsZero(),
|
||||
PlayCount: int(ch.PlayCount),
|
||||
FilePath: ch.Path,
|
||||
BitRate: ch.BitRate,
|
||||
}
|
||||
}
|
||||
|
||||
func toAlbum(al *subsonic.AlbumID3) mediaprovider.Album {
|
||||
func toAlbum(al *subsonic.AlbumID3) *mediaprovider.Album {
|
||||
if al == nil {
|
||||
log.Println("subsonicMediaProvider: toAlbum called on nil album")
|
||||
return mediaprovider.Album{}
|
||||
return nil
|
||||
}
|
||||
return mediaprovider.Album{
|
||||
return &mediaprovider.Album{
|
||||
ID: al.ID,
|
||||
CoverArtID: al.CoverArt,
|
||||
Name: al.Name,
|
||||
@@ -306,23 +314,21 @@ func toAlbum(al *subsonic.AlbumID3) mediaprovider.Album {
|
||||
}
|
||||
}
|
||||
|
||||
func toArtist(ar *subsonic.Artist) mediaprovider.Artist {
|
||||
func toArtist(ar *subsonic.Artist) *mediaprovider.Artist {
|
||||
if ar == nil {
|
||||
log.Println("subsonicMediaProvider: toArtist called on nil artist")
|
||||
return mediaprovider.Artist{}
|
||||
return nil
|
||||
}
|
||||
return mediaprovider.Artist{
|
||||
return &mediaprovider.Artist{
|
||||
ID: ar.ID,
|
||||
Name: ar.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func toArtistFromID3(ar *subsonic.ArtistID3) mediaprovider.Artist {
|
||||
func toArtistFromID3(ar *subsonic.ArtistID3) *mediaprovider.Artist {
|
||||
if ar == nil {
|
||||
log.Println("subsonicMediaProvider: toArtistFromID3 called on nil artistID3")
|
||||
return mediaprovider.Artist{}
|
||||
return nil
|
||||
}
|
||||
return mediaprovider.Artist{
|
||||
return &mediaprovider.Artist{
|
||||
ID: ar.ID,
|
||||
Name: ar.Name,
|
||||
AlbumCount: ar.AlbumCount,
|
||||
|
||||
@@ -58,7 +58,7 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
|
||||
|
||||
tr := a.curAlbum.Tracks[a.curTrackIdx]
|
||||
a.curTrackIdx += 1
|
||||
return &tr
|
||||
return tr
|
||||
}
|
||||
|
||||
type searchTracksIterator struct {
|
||||
@@ -109,8 +109,7 @@ func (s *searchTracksIterator) Next() *mediaprovider.Track {
|
||||
s.prefetched = s.prefetched[:0]
|
||||
s.prefetchedPos = 0
|
||||
}
|
||||
track := toTrack(tr)
|
||||
return &track
|
||||
return toTrack(tr)
|
||||
}
|
||||
|
||||
// no more results
|
||||
|
||||
Reference in New Issue
Block a user