translate sort order strings
This commit is contained in:
@@ -9,17 +9,13 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const (
|
||||
ArtistSortAlbumCount string = "Album Count"
|
||||
ArtistSortNameAZ string = "Name (A-Z)"
|
||||
ArtistSortRandom string = "Random"
|
||||
)
|
||||
const ()
|
||||
|
||||
func (j *jellyfinMediaProvider) ArtistSortOrders() []string {
|
||||
return []string{
|
||||
ArtistSortAlbumCount,
|
||||
ArtistSortNameAZ,
|
||||
ArtistSortRandom,
|
||||
mediaprovider.ArtistSortAlbumCount,
|
||||
mediaprovider.ArtistSortNameAZ,
|
||||
mediaprovider.ArtistSortRandom,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +25,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
||||
var sortFn func([]*jellyfin.Artist) []*jellyfin.Artist
|
||||
|
||||
if sortOrder == "" {
|
||||
sortOrder = ArtistSortNameAZ // default
|
||||
sortOrder = mediaprovider.ArtistSortNameAZ // default
|
||||
}
|
||||
switch sortOrder {
|
||||
case ArtistSortAlbumCount:
|
||||
case mediaprovider.ArtistSortAlbumCount:
|
||||
// Pagination needs to be disabled, to retrieve all results in a single request, and correctly sort them.
|
||||
disablePagination = true
|
||||
sortFn = func(artists []*jellyfin.Artist) []*jellyfin.Artist {
|
||||
@@ -41,10 +37,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
||||
})
|
||||
return artists
|
||||
}
|
||||
case ArtistSortNameAZ:
|
||||
case mediaprovider.ArtistSortNameAZ:
|
||||
jfSort.Field = jellyfin.SortByName
|
||||
jfSort.Mode = jellyfin.SortAsc
|
||||
case ArtistSortRandom:
|
||||
case mediaprovider.ArtistSortRandom:
|
||||
jfSort.Field = jellyfin.SortByRandom
|
||||
}
|
||||
|
||||
|
||||
@@ -9,44 +9,35 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const (
|
||||
AlbumSortRecentlyAdded string = "Recently Added"
|
||||
AlbumSortRandom string = "Random"
|
||||
AlbumSortTitleAZ string = "Title (A-Z)"
|
||||
AlbumSortArtistAZ string = "Artist (A-Z)"
|
||||
AlbumSortYearAscending string = "Year (ascending)"
|
||||
AlbumSortYearDescending string = "Year (descending)"
|
||||
)
|
||||
|
||||
func (j *jellyfinMediaProvider) AlbumSortOrders() []string {
|
||||
return []string{
|
||||
AlbumSortRecentlyAdded,
|
||||
AlbumSortRandom,
|
||||
AlbumSortTitleAZ,
|
||||
AlbumSortArtistAZ,
|
||||
AlbumSortYearAscending,
|
||||
AlbumSortYearDescending,
|
||||
mediaprovider.AlbumSortRecentlyAdded,
|
||||
mediaprovider.AlbumSortRandom,
|
||||
mediaprovider.AlbumSortTitleAZ,
|
||||
mediaprovider.AlbumSortArtistAZ,
|
||||
mediaprovider.AlbumSortYearAscending,
|
||||
mediaprovider.AlbumSortYearDescending,
|
||||
}
|
||||
}
|
||||
|
||||
func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
||||
var jfSort jellyfin.Sort
|
||||
switch sortOrder {
|
||||
case AlbumSortRecentlyAdded:
|
||||
case mediaprovider.AlbumSortRecentlyAdded:
|
||||
jfSort.Field = jellyfin.SortByDateCreated
|
||||
jfSort.Mode = jellyfin.SortDesc
|
||||
case AlbumSortRandom:
|
||||
case mediaprovider.AlbumSortRandom:
|
||||
jfSort.Field = jellyfin.SortByRandom
|
||||
case AlbumSortArtistAZ:
|
||||
case mediaprovider.AlbumSortArtistAZ:
|
||||
jfSort.Field = jellyfin.SortByArtist
|
||||
jfSort.Mode = jellyfin.SortAsc
|
||||
case AlbumSortTitleAZ:
|
||||
case mediaprovider.AlbumSortTitleAZ:
|
||||
jfSort.Field = jellyfin.SortByName
|
||||
jfSort.Mode = jellyfin.SortAsc
|
||||
case AlbumSortYearAscending:
|
||||
case mediaprovider.AlbumSortYearAscending:
|
||||
jfSort.Field = jellyfin.SortByYear
|
||||
jfSort.Mode = jellyfin.SortAsc
|
||||
case AlbumSortYearDescending:
|
||||
case mediaprovider.AlbumSortYearDescending:
|
||||
jfSort.Field = jellyfin.SortByYear
|
||||
jfSort.Mode = jellyfin.SortDesc
|
||||
}
|
||||
@@ -64,7 +55,7 @@ func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
|
||||
return sharedutil.MapSlice(al, toAlbum), nil
|
||||
}
|
||||
|
||||
if sortOrder == AlbumSortRandom {
|
||||
if sortOrder == mediaprovider.AlbumSortRandom {
|
||||
determFetcher := func(offs, limit int) ([]*mediaprovider.Album, error) {
|
||||
al, err := j.client.GetAlbums(jellyfin.QueryOpts{
|
||||
Sort: jellyfin.Sort{Field: "SortName", Mode: jellyfin.SortAsc},
|
||||
|
||||
@@ -9,6 +9,25 @@ import (
|
||||
"github.com/deluan/sanitize"
|
||||
)
|
||||
|
||||
const (
|
||||
// set of all supported album sorts across all media providers
|
||||
// these strings may be translated
|
||||
AlbumSortRecentlyAdded string = "Recently Added"
|
||||
AlbumSortRecentlyPlayed string = "Recently Played"
|
||||
AlbumSortFrequentlyPlayed string = "Frequently Played"
|
||||
AlbumSortRandom string = "Random"
|
||||
AlbumSortTitleAZ string = "Title (A-Z)"
|
||||
AlbumSortArtistAZ string = "Artist (A-Z)"
|
||||
AlbumSortYearAscending string = "Year (ascending)"
|
||||
AlbumSortYearDescending string = "Year (descending)"
|
||||
|
||||
// set of all supported artist sorts across all media providers
|
||||
// these strings may be translated
|
||||
ArtistSortAlbumCount string = "Album Count"
|
||||
ArtistSortNameAZ string = "Name (A-Z)"
|
||||
ArtistSortRandom string = "Random"
|
||||
)
|
||||
|
||||
type MediaIterator[M any] interface {
|
||||
Next() *M
|
||||
}
|
||||
|
||||
@@ -11,27 +11,16 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const (
|
||||
AlbumSortRecentlyAdded string = "Recently Added"
|
||||
AlbumSortRecentlyPlayed string = "Recently Played"
|
||||
AlbumSortFrequentlyPlayed string = "Frequently Played"
|
||||
AlbumSortRandom string = "Random"
|
||||
AlbumSortTitleAZ string = "Title (A-Z)"
|
||||
AlbumSortArtistAZ string = "Artist (A-Z)"
|
||||
AlbumSortYearAscending string = "Year (ascending)"
|
||||
AlbumSortYearDescending string = "Year (descending)"
|
||||
)
|
||||
|
||||
func (s *subsonicMediaProvider) AlbumSortOrders() []string {
|
||||
return []string{
|
||||
AlbumSortRecentlyAdded,
|
||||
AlbumSortRecentlyPlayed,
|
||||
AlbumSortFrequentlyPlayed,
|
||||
AlbumSortRandom,
|
||||
AlbumSortTitleAZ,
|
||||
AlbumSortArtistAZ,
|
||||
AlbumSortYearAscending,
|
||||
AlbumSortYearDescending,
|
||||
mediaprovider.AlbumSortRecentlyAdded,
|
||||
mediaprovider.AlbumSortRecentlyPlayed,
|
||||
mediaprovider.AlbumSortFrequentlyPlayed,
|
||||
mediaprovider.AlbumSortRandom,
|
||||
mediaprovider.AlbumSortTitleAZ,
|
||||
mediaprovider.AlbumSortArtistAZ,
|
||||
mediaprovider.AlbumSortYearAscending,
|
||||
mediaprovider.AlbumSortYearDescending,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,28 +75,28 @@ func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
|
||||
return s.baseIterFromSimpleSortOrder("starred", modifiedFilter)
|
||||
}
|
||||
if sortOrder == "" {
|
||||
sortOrder = AlbumSortRecentlyAdded // default
|
||||
sortOrder = mediaprovider.AlbumSortRecentlyAdded // default
|
||||
}
|
||||
switch sortOrder {
|
||||
case AlbumSortRecentlyAdded:
|
||||
case mediaprovider.AlbumSortRecentlyAdded:
|
||||
return s.baseIterFromSimpleSortOrder("newest", filter)
|
||||
case AlbumSortRecentlyPlayed:
|
||||
case mediaprovider.AlbumSortRecentlyPlayed:
|
||||
return s.baseIterFromSimpleSortOrder("recent", filter)
|
||||
case AlbumSortFrequentlyPlayed:
|
||||
case mediaprovider.AlbumSortFrequentlyPlayed:
|
||||
return s.baseIterFromSimpleSortOrder("frequent", filter)
|
||||
case AlbumSortRandom:
|
||||
case mediaprovider.AlbumSortRandom:
|
||||
return s.newRandomIter(filter, s.prefetchCoverCB)
|
||||
case AlbumSortTitleAZ:
|
||||
case mediaprovider.AlbumSortTitleAZ:
|
||||
return s.baseIterFromSimpleSortOrder("alphabeticalByName", filter)
|
||||
case AlbumSortArtistAZ:
|
||||
case mediaprovider.AlbumSortArtistAZ:
|
||||
return s.baseIterFromSimpleSortOrder("alphabeticalByArtist", filter)
|
||||
case AlbumSortYearAscending:
|
||||
case mediaprovider.AlbumSortYearAscending:
|
||||
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
||||
return s.client.GetAlbumList2("byYear",
|
||||
map[string]string{"fromYear": "0", "toYear": "3000", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
||||
}
|
||||
return helpers.NewAlbumIterator(makeFetchFn(fetchFn), filter, s.prefetchCoverCB)
|
||||
case AlbumSortYearDescending:
|
||||
case mediaprovider.AlbumSortYearDescending:
|
||||
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
||||
return s.client.GetAlbumList2("byYear",
|
||||
map[string]string{"fromYear": "3000", "toYear": "0", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
||||
|
||||
@@ -14,17 +14,11 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const (
|
||||
ArtistSortAlbumCount string = "Album Count"
|
||||
ArtistSortNameAZ string = "Name (A-Z)"
|
||||
ArtistSortRandom string = "Random"
|
||||
)
|
||||
|
||||
func (s *subsonicMediaProvider) ArtistSortOrders() []string {
|
||||
return []string{
|
||||
ArtistSortAlbumCount,
|
||||
ArtistSortNameAZ,
|
||||
ArtistSortRandom,
|
||||
mediaprovider.ArtistSortAlbumCount,
|
||||
mediaprovider.ArtistSortNameAZ,
|
||||
mediaprovider.ArtistSortRandom,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +31,10 @@ func filterArtistMatches(f mediaprovider.ArtistFilter, artist *subsonic.ArtistID
|
||||
|
||||
func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediaprovider.ArtistFilter) mediaprovider.ArtistIterator {
|
||||
if sortOrder == "" {
|
||||
sortOrder = ArtistSortNameAZ // default
|
||||
sortOrder = mediaprovider.ArtistSortNameAZ // default
|
||||
}
|
||||
switch sortOrder {
|
||||
case ArtistSortAlbumCount:
|
||||
case mediaprovider.ArtistSortAlbumCount:
|
||||
return s.baseArtistIterFromSimpleSortOrder(
|
||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||
slices.SortStableFunc(artists, func(a, b *subsonic.ArtistID3) int {
|
||||
@@ -50,7 +44,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
||||
},
|
||||
filter,
|
||||
)
|
||||
case ArtistSortNameAZ:
|
||||
case mediaprovider.ArtistSortNameAZ:
|
||||
return s.baseArtistIterFromSimpleSortOrder(
|
||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||
c := collate.New(language.English, collate.Loose)
|
||||
@@ -61,7 +55,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
||||
},
|
||||
filter,
|
||||
)
|
||||
case ArtistSortRandom:
|
||||
case mediaprovider.ArtistSortRandom:
|
||||
return s.baseArtistIterFromSimpleSortOrder(
|
||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||
newArtists := make([]*subsonic.ArtistID3, len(artists))
|
||||
|
||||
@@ -12,7 +12,7 @@ func (s *subsonicMediaProvider) IterateTracks(searchQuery string) mediaprovider.
|
||||
return &allTracksIterator{
|
||||
s: s,
|
||||
albumIter: s.IterateAlbums(
|
||||
AlbumSortArtistAZ,
|
||||
mediaprovider.AlbumSortArtistAZ,
|
||||
mediaprovider.NewAlbumFilter(mediaprovider.AlbumFilterOptions{}),
|
||||
),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user