mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Fixed incomplete return of OrderFormatsByEpisodeNumber
This commit is contained in:
parent
5921c132e3
commit
464636daa4
1 changed files with 12 additions and 11 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue