Skip to content

Commit

Permalink
Merge pull request #57 from xxxserxxx/ticket_11_sort_by_disknumber
Browse files Browse the repository at this point in the history
Adds ticket #11, sort by dis[c]number
  • Loading branch information
spezifisch authored Oct 11, 2024
2 parents d1c50dc + b552c58 commit 3afa955
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions page_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ func (b *BrowserPage) handleAddArtistToQueue() {
return
}

sort.Sort(b.currentDirectory.Entities)

for _, entity := range b.currentDirectory.Entities {
if entity.IsDirectory {
b.addDirectoryToQueue(&entity)
Expand Down
23 changes: 19 additions & 4 deletions subsonic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net/http"
"net/url"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -207,11 +208,19 @@ func (s SubsonicEntities) Less(i, j int) bool {
}
return true
}
// If the tracks are the same, sort alphabetically
if s[i].Track == s[j].Track {
return s[i].Title < s[j].Title
// Disk and track numbers are only relevant within the same parent
if s[i].Parent == s[j].Parent {
// sort first by DiskNumber
if s[i].DiscNumber == s[j].DiscNumber {
// Tracks on the same disk are sorted by track
return s[i].Track < s[j].Track
}
return s[i].DiscNumber < s[j].DiscNumber
}
return s[i].Track < s[j].Track
// If we get here, the songs are either from different albums, or else
// they're on the same disk

return s[i].Title < s[j].Title
}

type SubsonicIndexes struct {
Expand Down Expand Up @@ -300,6 +309,8 @@ func (connection *SubsonicConnection) GetArtist(id string) (*SubsonicResponse, e
connection.directoryCache[id] = *resp
}

sort.Sort(resp.Directory.Entities)

return resp, nil
}

Expand All @@ -324,6 +335,8 @@ func (connection *SubsonicConnection) GetAlbum(id string) (*SubsonicResponse, er
connection.directoryCache[id] = *resp
}

sort.Sort(resp.Directory.Entities)

return resp, nil
}

Expand All @@ -345,6 +358,8 @@ func (connection *SubsonicConnection) GetMusicDirectory(id string) (*SubsonicRes
connection.directoryCache[id] = *resp
}

sort.Sort(resp.Directory.Entities)

return resp, nil
}

Expand Down

0 comments on commit 3afa955

Please sign in to comment.