mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Initial commit
This commit is contained in:
commit
5f1d811c66
23 changed files with 3612 additions and 0 deletions
54
utils/sort.go
Normal file
54
utils/sort.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"github.com/ByteDream/crunchyroll"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MovieListingsByDuration sorts movie listings by their duration
|
||||
type MovieListingsByDuration []*crunchyroll.MovieListing
|
||||
|
||||
func (mlbd MovieListingsByDuration) Len() int {
|
||||
return len(mlbd)
|
||||
}
|
||||
func (mlbd MovieListingsByDuration) Swap(i, j int) {
|
||||
mlbd[i], mlbd[j] = mlbd[j], mlbd[i]
|
||||
}
|
||||
func (mlbd MovieListingsByDuration) Less(i, j int) bool {
|
||||
return mlbd[i].DurationMS < mlbd[j].DurationMS
|
||||
}
|
||||
|
||||
// EpisodesByDuration episodes by their duration
|
||||
type EpisodesByDuration []*crunchyroll.Episode
|
||||
|
||||
func (ebd EpisodesByDuration) Len() int {
|
||||
return len(ebd)
|
||||
}
|
||||
func (ebd EpisodesByDuration) Swap(i, j int) {
|
||||
ebd[i], ebd[j] = ebd[j], ebd[i]
|
||||
}
|
||||
func (ebd EpisodesByDuration) Less(i, j int) bool {
|
||||
return ebd[i].DurationMS < ebd[j].DurationMS
|
||||
}
|
||||
|
||||
// FormatsByResolution sort formats after their resolution
|
||||
type FormatsByResolution []*crunchyroll.Format
|
||||
|
||||
func (fbr FormatsByResolution) Len() int {
|
||||
return len(fbr)
|
||||
}
|
||||
func (fbr FormatsByResolution) Swap(i, j int) {
|
||||
fbr[i], fbr[j] = fbr[j], fbr[i]
|
||||
}
|
||||
func (fbr FormatsByResolution) Less(i, j int) bool {
|
||||
iSplitRes := strings.Split(fbr[i].Video.Resolution, "x")
|
||||
iResX, _ := strconv.Atoi(iSplitRes[0])
|
||||
iResY, _ := strconv.Atoi(iSplitRes[1])
|
||||
|
||||
jSplitRes := strings.Split(fbr[j].Video.Resolution, "x")
|
||||
jResX, _ := strconv.Atoi(jSplitRes[0])
|
||||
jResY, _ := strconv.Atoi(jSplitRes[1])
|
||||
|
||||
return iResX+iResY < jResX+jResY
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue