Skip to content

Commit 61bf077

Browse files
committed
fix sort for dir, tracks
1 parent 0e45f5e commit 61bf077

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

server/ctrlsubsonic/handlers_by_folder.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ctrlsubsonic
33
import (
44
"fmt"
55
"net/http"
6+
"sort"
67
"strings"
78

89
"github.com/jinzhu/gorm"
@@ -82,9 +83,13 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
8283
Preload("AlbumRating", "user_id=?", user.ID).
8384
Order("albums.right_path COLLATE NOCASE").
8485
Find(&childFolders)
86+
// sort by TagYear
87+
sort.Slice(childFolders, func(i, j int) bool { return childFolders[i].TagYear < childFolders[j].TagYear })
88+
8589
for _, ch := range childFolders {
8690
childrenObj = append(childrenObj, spec.NewTCAlbumByFolder(ch))
8791
}
92+
8893
// start looking for child childTracks in the current dir
8994
var childTracks []*db.Track
9095
c.dbc.
@@ -97,6 +102,9 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
97102
Order("filename").
98103
Find(&childTracks)
99104

105+
// sort by tracknumber for if file name is 1, 2, ... 10, 11...
106+
sort.Slice(childTracks, func(i, j int) bool { return childTracks[i].TagTrackNumber < childTracks[j].TagTrackNumber })
107+
100108
transcodeMeta := streamGetTranscodeMeta(c.dbc, user.ID, params.GetOr("c", ""))
101109

102110
for _, ch := range childTracks {

server/ctrlsubsonic/spec/construct_by_folder.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild {
4040
ParentID: f.ParentSID(),
4141
CreatedAt: f.CreatedAt,
4242
AverageRating: formatRating(f.AverageRating),
43+
Year: f.TagYear,
4344
}
4445
if f.AlbumStar != nil {
4546
trCh.Starred = &f.AlbumStar.StarDate

0 commit comments

Comments
 (0)