mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02: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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/ByteDream/crunchyroll-go"
|
"github.com/ByteDream/crunchyroll-go"
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -13,10 +12,6 @@ type StructureError struct {
|
||||||
error
|
error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *StructureError) Error() string {
|
|
||||||
return se.error.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsStructureError(err error) (ok bool) {
|
func IsStructureError(err error) (ok bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, ok = err.(*StructureError)
|
_, ok = err.(*StructureError)
|
||||||
|
|
@ -570,15 +565,21 @@ func (es *EpisodeStructure) OrderFormatsByEpisodeNumber() ([][]*crunchyroll.Form
|
||||||
formatsMap[episode.EpisodeNumber] = append(formatsMap[episode.EpisodeNumber], format)
|
formatsMap[episode.EpisodeNumber] = append(formatsMap[episode.EpisodeNumber], format)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := make([]int, 0, len(formatsMap))
|
var highest int
|
||||||
for k := range formatsMap {
|
for key := range formatsMap {
|
||||||
keys = append(keys, k)
|
if key > highest {
|
||||||
|
highest = key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort.Ints(keys)
|
|
||||||
|
|
||||||
var orderedFormats [][]*crunchyroll.Format
|
var orderedFormats [][]*crunchyroll.Format
|
||||||
for _, k := range keys {
|
for i := 0; i < highest; i++ {
|
||||||
orderedFormats = append(orderedFormats, formatsMap[k])
|
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
|
return orderedFormats, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue