mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added function to sort episode by audio
This commit is contained in:
parent
6fb6b3c03c
commit
5f5ec38585
1 changed files with 39 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SortEpisodesBySeason sorts the given episodes by their seasons.
|
// SortEpisodesBySeason sorts the given episodes by their seasons.
|
||||||
|
|
@ -42,6 +43,44 @@ func SortEpisodesBySeason(episodes []*crunchyroll.Episode) [][]*crunchyroll.Epis
|
||||||
return eps
|
return eps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SortEpisodesByAudio sort the given episodes by their audio locale
|
||||||
|
func SortEpisodesByAudio(episodes []*crunchyroll.Episode) (map[crunchyroll.LOCALE][]*crunchyroll.Episode, error) {
|
||||||
|
eps := map[crunchyroll.LOCALE][]*crunchyroll.Episode{}
|
||||||
|
|
||||||
|
errChan := make(chan error)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
var lock sync.Mutex
|
||||||
|
for _, episode := range episodes {
|
||||||
|
episode := episode
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
audioLocale, err := episode.AudioLocale()
|
||||||
|
if err != nil {
|
||||||
|
errChan <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
|
if _, ok := eps[audioLocale]; !ok {
|
||||||
|
eps[audioLocale] = make([]*crunchyroll.Episode, 0)
|
||||||
|
}
|
||||||
|
eps[audioLocale] = append(eps[audioLocale], episode)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
errChan <- nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := <-errChan; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return eps, nil
|
||||||
|
}
|
||||||
|
|
||||||
// MovieListingsByDuration sorts movie listings by their duration
|
// MovieListingsByDuration sorts movie listings by their duration
|
||||||
type MovieListingsByDuration []*crunchyroll.MovieListing
|
type MovieListingsByDuration []*crunchyroll.MovieListing
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue