From 464636daa43fd8f6216429024e412941674cf01b Mon Sep 17 00:00:00 2001 From: bytedream Date: Mon, 13 Sep 2021 10:45:13 +0200 Subject: [PATCH] Fixed incomplete return of `OrderFormatsByEpisodeNumber` --- utils/structure.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/utils/structure.go b/utils/structure.go index f898c15..48c3319 100644 --- a/utils/structure.go +++ b/utils/structure.go @@ -3,7 +3,6 @@ package utils import ( "errors" "github.com/ByteDream/crunchyroll-go" - "sort" "sync" ) @@ -13,10 +12,6 @@ type StructureError struct { error } -func (se *StructureError) Error() string { - return se.error.Error() -} - func IsStructureError(err error) (ok bool) { if err != nil { _, ok = err.(*StructureError) @@ -570,15 +565,21 @@ func (es *EpisodeStructure) OrderFormatsByEpisodeNumber() ([][]*crunchyroll.Form formatsMap[episode.EpisodeNumber] = append(formatsMap[episode.EpisodeNumber], format) } - keys := make([]int, 0, len(formatsMap)) - for k := range formatsMap { - keys = append(keys, k) + var highest int + for key := range formatsMap { + if key > highest { + highest = key + } } - sort.Ints(keys) var orderedFormats [][]*crunchyroll.Format - for _, k := range keys { - orderedFormats = append(orderedFormats, formatsMap[k]) + for i := 0; i < highest; i++ { + if formats, ok := formatsMap[i]; ok { + orderedFormats = append(orderedFormats, formats) + } else { + // simply adds nil in case that no episode with number i exists + orderedFormats = append(orderedFormats, nil) + } } return orderedFormats, nil }