Skip to content

Commit

Permalink
Merge pull request #45 from xxxserxxx/search-subsonic-fix
Browse files Browse the repository at this point in the history
Album search results from Navidrome were not being added to the album column
  • Loading branch information
spezifisch authored Oct 11, 2024
2 parents 97f01f6 + b3643ae commit d7c625f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 15 additions & 3 deletions page_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -247,18 +247,30 @@ 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 {
s.logger.PrintError("addArtistToQueue unable to get album artist from server", err)
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
}
Expand Down
5 changes: 4 additions & 1 deletion subsonic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -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"`
Expand Down

0 comments on commit d7c625f

Please sign in to comment.