mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-09 06:46:37 +08:00
优化
This commit is contained in:
@@ -276,7 +276,9 @@ func (e *EmbyService) seasonsForSeries(series embySeriesGroup) []embySeasonGroup
|
|||||||
}
|
}
|
||||||
season.Episodes = append(season.Episodes, episode)
|
season.Episodes = append(season.Episodes, episode)
|
||||||
}
|
}
|
||||||
sort.Ints(order)
|
sort.SliceStable(order, func(i, j int) bool {
|
||||||
|
return embySeasonSortOrder(order[i]) < embySeasonSortOrder(order[j])
|
||||||
|
})
|
||||||
out := make([]embySeasonGroup, 0, len(order))
|
out := make([]embySeasonGroup, 0, len(order))
|
||||||
for _, seasonNum := range order {
|
for _, seasonNum := range order {
|
||||||
out = append(out, *bySeason[seasonNum])
|
out = append(out, *bySeason[seasonNum])
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -272,6 +273,11 @@ func TestEmbySeparatesOVAAndOADFromSeasonOne(t *testing.T) {
|
|||||||
if len(seasonItems) != 3 {
|
if len(seasonItems) != 3 {
|
||||||
t.Fatalf("expected season 1, OVA and OAD separately, got %#v", seasonItems)
|
t.Fatalf("expected season 1, OVA and OAD separately, got %#v", seasonItems)
|
||||||
}
|
}
|
||||||
|
for i, want := range []int{1, embySeasonOVA, embySeasonOAD} {
|
||||||
|
if seasonItems[i]["IndexNumber"] != want {
|
||||||
|
t.Fatalf("season order [%d] = %#v, want %d", i, seasonItems[i], want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
seasonByIndex := make(map[int]map[string]any, len(seasonItems))
|
seasonByIndex := make(map[int]map[string]any, len(seasonItems))
|
||||||
for _, season := range seasonItems {
|
for _, season := range seasonItems {
|
||||||
@@ -306,6 +312,35 @@ func TestEmbySeparatesOVAAndOADFromSeasonOne(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmbySeasonSortOrderMatchesWeb(t *testing.T) {
|
||||||
|
seasons := []int{
|
||||||
|
embySeasonNCED,
|
||||||
|
embySeasonOAD,
|
||||||
|
2,
|
||||||
|
embySeasonTheatrical,
|
||||||
|
1,
|
||||||
|
embySeasonGenericSpecial,
|
||||||
|
embySeasonOVA,
|
||||||
|
}
|
||||||
|
sort.SliceStable(seasons, func(i, j int) bool {
|
||||||
|
return embySeasonSortOrder(seasons[i]) < embySeasonSortOrder(seasons[j])
|
||||||
|
})
|
||||||
|
want := []int{
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
embySeasonGenericSpecial,
|
||||||
|
embySeasonTheatrical,
|
||||||
|
embySeasonOVA,
|
||||||
|
embySeasonOAD,
|
||||||
|
embySeasonNCED,
|
||||||
|
}
|
||||||
|
for i := range want {
|
||||||
|
if seasons[i] != want[i] {
|
||||||
|
t.Fatalf("season order = %#v, want %#v", seasons, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmbySeasonCandidatesCoverPersistedSpecialNumbers(t *testing.T) {
|
func TestEmbySeasonCandidatesCoverPersistedSpecialNumbers(t *testing.T) {
|
||||||
for _, persisted := range []int{0, -1} {
|
for _, persisted := range []int{0, -1} {
|
||||||
candidates := embySeasonCandidates(persisted)
|
candidates := embySeasonCandidates(persisted)
|
||||||
|
|||||||
@@ -208,6 +208,42 @@ func seasonName(seasonNum int) string {
|
|||||||
return fmt.Sprintf("第 %d 季", seasonNum)
|
return fmt.Sprintf("第 %d 季", seasonNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// embySeasonSortOrder mirrors the web UI's seasonSortOrder: regular seasons
|
||||||
|
// first in ascending order, followed by specials in a stable category order.
|
||||||
|
func embySeasonSortOrder(seasonNum int) int {
|
||||||
|
if seasonNum > 0 {
|
||||||
|
return seasonNum
|
||||||
|
}
|
||||||
|
switch seasonNum {
|
||||||
|
case embySeasonGenericSpecial:
|
||||||
|
return 1000
|
||||||
|
case embySeasonTheatrical:
|
||||||
|
return 1001
|
||||||
|
case embySeasonOVA:
|
||||||
|
return 1002
|
||||||
|
case embySeasonOAD:
|
||||||
|
return 1003
|
||||||
|
case embySeasonOVD:
|
||||||
|
return 1004
|
||||||
|
case embySeasonONA:
|
||||||
|
return 1005
|
||||||
|
case embySeasonExtra:
|
||||||
|
return 1006
|
||||||
|
case embySeasonBonus:
|
||||||
|
return 1007
|
||||||
|
case embySeasonOmake:
|
||||||
|
return 1008
|
||||||
|
case embySeasonPictureDrama:
|
||||||
|
return 1009
|
||||||
|
case embySeasonNCOP:
|
||||||
|
return 1010
|
||||||
|
case embySeasonNCED:
|
||||||
|
return 1011
|
||||||
|
default:
|
||||||
|
return 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func sortSeriesGroups(groups []embySeriesGroup, p ItemsParams) {
|
func sortSeriesGroups(groups []embySeriesGroup, p ItemsParams) {
|
||||||
switch primarySupportedEmbySort(p.SortBy, false) {
|
switch primarySupportedEmbySort(p.SortBy, false) {
|
||||||
case "sortname", "name":
|
case "sortname", "name":
|
||||||
|
|||||||
Reference in New Issue
Block a user