diff --git a/page_search.go b/page_search.go index f69e623..e9824ba 100644 --- a/page_search.go +++ b/page_search.go @@ -228,7 +228,7 @@ func (s *SearchPage) search() { s.artists = append(s.artists, &artist) } for _, album := range res.SearchResults.Album { - s.albumList.AddItem(tview.Escape(album.Album), "", 0, nil) + s.albumList.AddItem(tview.Escape(album.Name), "", 0, nil) s.albums = append(s.albums, &album) } for _, song := range res.SearchResults.Song { @@ -247,8 +247,8 @@ func (s *SearchPage) addArtistToQueue(entity subsonic.Ider) { s.logger.Printf("addArtistToQueue: GetArtist %s -- %s", entity.ID(), err.Error()) return } - artistName := response.Artist.Name + artistId := response.Artist.Id for _, album := range response.Artist.Album { response, err = s.ui.connection.GetAlbum(album.Id) if err != nil { @@ -256,9 +256,21 @@ func (s *SearchPage) addArtistToQueue(entity subsonic.Ider) { return } sort.Sort(response.Album.Song) + // We make sure we add only albums who's artists match the artist + // being added; this prevents collection albums with many different + // artists that show up in the Album column having _all_ of the songs + // on the album -- even ones that don't match the artist -- from + // being added when the user adds an album from the search results. for _, e := range response.Album.Song { + // Depending on the server implementation, the server may or may not + // respond with a list of artists. If either the Artist field matches, + // or the artist name is in a list of artists, then we add the song. + if e.ArtistId == artistId { + s.ui.addSongToQueue(&e) + continue + } for _, art := range e.Artists { - if art.Name == artistName { + if art.Id == artistId { s.ui.addSongToQueue(&e) break } diff --git a/subsonic/api.go b/subsonic/api.go index db8691d..e2c42fa 100644 --- a/subsonic/api.go +++ b/subsonic/api.go @@ -33,7 +33,7 @@ type SubsonicConnection struct { func Init(logger logger.LoggerInterface) *SubsonicConnection { return &SubsonicConnection{ clientName: "example", - clientVersion: "1.0.0", + clientVersion: "1.8.0", logger: logger, directoryCache: make(map[string]SubsonicResponse), @@ -125,6 +125,7 @@ func (s Artist) ID() string { type Album struct { Id string `json:"id"` Created string `json:"created"` + ArtistId string `json:"artistId"` Artist string `json:"artist"` Artists []Artist `json:"artists"` DisplayArtist string `json:"displayArtist"` @@ -138,6 +139,7 @@ type Album struct { Genres []Genre `json:"genres"` Year int `json:"year"` Song SubsonicEntities `json:"song"` + CoverArt string `json:"coverArt"` } func (s Album) ID() string { @@ -153,6 +155,7 @@ type SubsonicEntity struct { IsDirectory bool `json:"isDir"` Parent string `json:"parent"` Title string `json:"title"` + ArtistId string `json:"artistId"` Artist string `json:"artist"` Artists []Artist `json:"artists"` Duration int `json:"duration"`