feat: Add sorting options for Artists

Include both `Album Count` and `Random` sortings for the Artists page.

This change also fixes the Artist search feature in Jellyfin, which was
broken because of an open issue on Jellyfin [1]. The current workaround
is to do the filtering locally after receiving all results from Jellyfin
API.

Also, as the Jellyfin API doesn't include a sorting option for
`AlbumCount`, we need to disable pagination when that option is
selected, to receive all artists, and run the sorting locally.

[1] Related issue: https://github.com/jellyfin/jellyfin/issues/8222
This commit is contained in:
Michael Manganiello
2024-04-13 21:04:51 -03:00
parent 1e05d88a8d
commit 14bfaac7a2
3 changed files with 130 additions and 20 deletions
+16 -4
View File
@@ -5,6 +5,8 @@ import (
"io"
"net/url"
"strings"
"github.com/deluan/sanitize"
)
type MediaIterator[M any] interface {
@@ -96,11 +98,15 @@ func (f albumFilter) Matches(album *Album) bool {
type ArtistFilter = MediaFilter[Artist, ArtistFilterOptions]
type ArtistFilterOptions struct{}
type ArtistFilterOptions struct {
SearchQuery string
}
// Clone returns a deep copy of the filter options
func (o ArtistFilterOptions) Clone() ArtistFilterOptions {
return ArtistFilterOptions{}
return ArtistFilterOptions{
SearchQuery: o.SearchQuery,
}
}
type artistFilter struct {
@@ -126,14 +132,20 @@ func (a artistFilter) Clone() ArtistFilter {
// Returns true if the filter is the nil filter - i.e. matches everything
func (a artistFilter) IsNil() bool {
return true
return a.options.SearchQuery == ""
}
func (f artistFilter) Matches(artist *Artist) bool {
if artist == nil {
return false
}
return false
if f.options.SearchQuery != "" && !strings.Contains(
sanitize.Accents(strings.ToLower(artist.Name)),
sanitize.Accents(strings.ToLower(f.options.SearchQuery)),
) {
return false
}
return true
}
type RatingFavoriteParameters struct {