From 61bf0771630adecd0a0ace708ec70422091f545d Mon Sep 17 00:00:00 2001 From: mikuta0407 Date: Sun, 9 Jun 2024 01:39:38 +0900 Subject: [PATCH 1/2] fix sort for dir, tracks --- server/ctrlsubsonic/handlers_by_folder.go | 8 ++++++++ server/ctrlsubsonic/spec/construct_by_folder.go | 1 + 2 files changed, 9 insertions(+) diff --git a/server/ctrlsubsonic/handlers_by_folder.go b/server/ctrlsubsonic/handlers_by_folder.go index 2f20017b..6a43f9c6 100644 --- a/server/ctrlsubsonic/handlers_by_folder.go +++ b/server/ctrlsubsonic/handlers_by_folder.go @@ -3,6 +3,7 @@ package ctrlsubsonic import ( "fmt" "net/http" + "sort" "strings" "github.com/jinzhu/gorm" @@ -82,9 +83,13 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response { Preload("AlbumRating", "user_id=?", user.ID). Order("albums.right_path COLLATE NOCASE"). Find(&childFolders) + // sort by TagYear + sort.Slice(childFolders, func(i, j int) bool { return childFolders[i].TagYear < childFolders[j].TagYear }) + for _, ch := range childFolders { childrenObj = append(childrenObj, spec.NewTCAlbumByFolder(ch)) } + // start looking for child childTracks in the current dir var childTracks []*db.Track c.dbc. @@ -97,6 +102,9 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response { Order("filename"). Find(&childTracks) + // sort by tracknumber for if file name is 1, 2, ... 10, 11... + sort.Slice(childTracks, func(i, j int) bool { return childTracks[i].TagTrackNumber < childTracks[j].TagTrackNumber }) + transcodeMeta := streamGetTranscodeMeta(c.dbc, user.ID, params.GetOr("c", "")) for _, ch := range childTracks { diff --git a/server/ctrlsubsonic/spec/construct_by_folder.go b/server/ctrlsubsonic/spec/construct_by_folder.go index f8f35d34..c39b695e 100644 --- a/server/ctrlsubsonic/spec/construct_by_folder.go +++ b/server/ctrlsubsonic/spec/construct_by_folder.go @@ -40,6 +40,7 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild { ParentID: f.ParentSID(), CreatedAt: f.CreatedAt, AverageRating: formatRating(f.AverageRating), + Year: f.TagYear, } if f.AlbumStar != nil { trCh.Starred = &f.AlbumStar.StarDate From e0931132d92ef39a8d9e60e618e7a062a8a4ed1e Mon Sep 17 00:00:00 2001 From: mikuta0407 Date: Sun, 9 Jun 2024 14:10:18 +0000 Subject: [PATCH 2/2] fixup! fix sort for dir, tracks --- server/ctrlsubsonic/handlers_by_folder.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/ctrlsubsonic/handlers_by_folder.go b/server/ctrlsubsonic/handlers_by_folder.go index 6a43f9c6..5a0c776f 100644 --- a/server/ctrlsubsonic/handlers_by_folder.go +++ b/server/ctrlsubsonic/handlers_by_folder.go @@ -3,7 +3,6 @@ package ctrlsubsonic import ( "fmt" "net/http" - "sort" "strings" "github.com/jinzhu/gorm" @@ -81,10 +80,9 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response { Where("parent_id=?", id.Value). Preload("AlbumStar", "user_id=?", user.ID). Preload("AlbumRating", "user_id=?", user.ID). + Order("tag_year"). Order("albums.right_path COLLATE NOCASE"). Find(&childFolders) - // sort by TagYear - sort.Slice(childFolders, func(i, j int) bool { return childFolders[i].TagYear < childFolders[j].TagYear }) for _, ch := range childFolders { childrenObj = append(childrenObj, spec.NewTCAlbumByFolder(ch)) @@ -99,12 +97,10 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response { Preload("Artists"). Preload("TrackStar", "user_id=?", user.ID). Preload("TrackRating", "user_id=?", user.ID). + Order("tag_track_number"). Order("filename"). Find(&childTracks) - // sort by tracknumber for if file name is 1, 2, ... 10, 11... - sort.Slice(childTracks, func(i, j int) bool { return childTracks[i].TagTrackNumber < childTracks[j].TagTrackNumber }) - transcodeMeta := streamGetTranscodeMeta(c.dbc, user.ID, params.GetOr("c", "")) for _, ch := range childTracks {