mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Fix for #7
This commit is contained in:
parent
74e8810123
commit
458c0595e5
4 changed files with 30 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package utils
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ByteDream/crunchyroll-go"
|
||||
"sync"
|
||||
)
|
||||
|
|
@ -499,11 +500,13 @@ func (es *EpisodeStructure) GetEpisodeByFormat(format *crunchyroll.Format) (*cru
|
|||
|
||||
// GetEpisodeByURL returns an episode by its url
|
||||
func (es *EpisodeStructure) GetEpisodeByURL(url string) (*crunchyroll.Episode, error) {
|
||||
_, title, ok := crunchyroll.MatchEpisode(url)
|
||||
_, title, episodeNumber, _, ok := crunchyroll.ParseEpisodeURL(url)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid url")
|
||||
}
|
||||
|
||||
fmt.Println(title)
|
||||
|
||||
episodes, err := es.Episodes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -514,6 +517,12 @@ func (es *EpisodeStructure) GetEpisodeByURL(url string) (*crunchyroll.Episode, e
|
|||
return episode, nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, episode := range episodes {
|
||||
if episode.EpisodeNumber == episodeNumber {
|
||||
return episode, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("no episode could be found")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue