mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Removed FindVideo & FindEpisode; added FindVideoByName & FindEpisodeByName
This commit is contained in:
parent
87f57bacfc
commit
6b2d7c6e27
1 changed files with 37 additions and 43 deletions
|
|
@ -280,55 +280,49 @@ func (c *Crunchyroll) Search(query string, limit uint) (s []*Series, m []*Movie,
|
||||||
return s, m, nil
|
return s, m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindVideo finds a Video (Season or Movie) by a crunchyroll link
|
// FindVideoByName finds a Video (Season or Movie) by its name.
|
||||||
// e.g. https://www.crunchyroll.com/darling-in-the-franxx
|
// Use this in combination with ParseVideoURL and hand over the corresponding results
|
||||||
func (c *Crunchyroll) FindVideo(seriesUrl string) (Video, error) {
|
// to this function.
|
||||||
if series, ok := ParseVideoURL(seriesUrl); ok {
|
func (c *Crunchyroll) FindVideoByName(seriesName string) (Video, error) {
|
||||||
s, m, err := c.Search(series, 1)
|
s, m, err := c.Search(seriesName, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
|
||||||
|
|
||||||
if len(s) > 0 {
|
|
||||||
return s[0], nil
|
|
||||||
} else if len(m) > 0 {
|
|
||||||
return m[0], nil
|
|
||||||
}
|
|
||||||
return nil, errors.New("no series or movie could be found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("invalid url")
|
if len(s) > 0 {
|
||||||
|
return s[0], nil
|
||||||
|
} else if len(m) > 0 {
|
||||||
|
return m[0], nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("no series or movie could be found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindEpisode finds an episode by its crunchyroll link
|
// FindEpisodeByName finds an episode by its crunchyroll series name and episode title.
|
||||||
// e.g. https://www.crunchyroll.com/darling-in-the-franxx/episode-1-alone-and-lonesome-759575
|
// Use this in combination with ParseEpisodeURL and hand over the corresponding results
|
||||||
func (c *Crunchyroll) FindEpisode(url string) ([]*Episode, error) {
|
// to this function.
|
||||||
if series, title, _, _, ok := ParseEpisodeURL(url); ok {
|
func (c *Crunchyroll) FindEpisodeByName(seriesName, episodeTitle string) ([]*Episode, error) {
|
||||||
video, err := c.FindVideo(fmt.Sprintf("https://www.crunchyroll.com/%s", series))
|
video, err := c.FindVideoByName(seriesName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
seasons, err := video.(*Series).Seasons()
|
seasons, err := video.(*Series).Seasons()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
|
||||||
|
|
||||||
var matchingEpisodes []*Episode
|
|
||||||
for _, season := range seasons {
|
|
||||||
episodes, err := season.Episodes()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, episode := range episodes {
|
|
||||||
if episode.SlugTitle == title {
|
|
||||||
matchingEpisodes = append(matchingEpisodes, episode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matchingEpisodes, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("invalid url")
|
var matchingEpisodes []*Episode
|
||||||
|
for _, season := range seasons {
|
||||||
|
episodes, err := season.Episodes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, episode := range episodes {
|
||||||
|
if episode.SlugTitle == episodeTitle {
|
||||||
|
matchingEpisodes = append(matchingEpisodes, episode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchingEpisodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchEpisode tries to extract the crunchyroll series name and title out of the given url
|
// MatchEpisode tries to extract the crunchyroll series name and title out of the given url
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue