Server changes/Sonarr
This commit is contained in:
@@ -138,6 +138,51 @@ func (s *Store) LibraryCandidates(ctx context.Context, genres []string, limit in
|
||||
return collectPayloads(rows)
|
||||
}
|
||||
|
||||
// CuratedCandidates filters the imported catalogue for a server-authored shelf. Arrays
|
||||
// are matched case-insensitively because Emby studio capitalisation is not consistent.
|
||||
func (s *Store) CuratedCandidates(
|
||||
ctx context.Context,
|
||||
itemTypes, genres, studios []string,
|
||||
limit int,
|
||||
) ([]json.RawMessage, error) {
|
||||
if len(itemTypes) == 0 || (len(genres) == 0 && len(studios) == 0) {
|
||||
return nil, nil
|
||||
}
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT payload
|
||||
FROM library_items
|
||||
WHERE type = ANY($1)
|
||||
AND (
|
||||
cardinality($2::text[]) = 0 OR
|
||||
EXISTS (
|
||||
SELECT 1 FROM unnest(genres) AS genre
|
||||
WHERE lower(genre) = ANY($2)
|
||||
)
|
||||
)
|
||||
AND (
|
||||
cardinality($3::text[]) = 0 OR
|
||||
EXISTS (
|
||||
SELECT 1 FROM unnest(studios) AS studio
|
||||
WHERE lower(studio) = ANY($3)
|
||||
)
|
||||
)
|
||||
ORDER BY community_rating DESC NULLS LAST, date_created DESC NULLS LAST
|
||||
LIMIT $4`,
|
||||
itemTypes, lowerStrings(genres), lowerStrings(studios), limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: curated candidates: %w", err)
|
||||
}
|
||||
return collectPayloads(rows)
|
||||
}
|
||||
|
||||
func lowerStrings(values []string) []string {
|
||||
out := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
out = append(out, strings.ToLower(strings.TrimSpace(value)))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Store) LibraryStats(ctx context.Context) (LibraryStats, error) {
|
||||
stats := LibraryStats{ByType: map[string]int64{}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user