mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Deprecated find video and optimized find episode (as result of #22)
This commit is contained in:
parent
e2f42493ac
commit
2e9ce3cf52
1 changed files with 18 additions and 10 deletions
|
|
@ -306,6 +306,10 @@ func (c *Crunchyroll) Search(query string, limit uint) (s []*Series, m []*Movie,
|
||||||
// FindVideoByName finds a Video (Season or Movie) by its name.
|
// FindVideoByName finds a Video (Season or Movie) by its name.
|
||||||
// Use this in combination with ParseVideoURL and hand over the corresponding results
|
// Use this in combination with ParseVideoURL and hand over the corresponding results
|
||||||
// to this function.
|
// to this function.
|
||||||
|
//
|
||||||
|
// Deprecated: Use Search instead. The first result sometimes isn't the correct one
|
||||||
|
// so this function is inaccurate in some cases.
|
||||||
|
// See https://github.com/ByteDream/crunchyroll-go/issues/22 for more information.
|
||||||
func (c *Crunchyroll) FindVideoByName(seriesName string) (Video, error) {
|
func (c *Crunchyroll) FindVideoByName(seriesName string) (Video, error) {
|
||||||
s, m, err := c.Search(seriesName, 1)
|
s, m, err := c.Search(seriesName, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -324,27 +328,31 @@ func (c *Crunchyroll) FindVideoByName(seriesName string) (Video, error) {
|
||||||
// Use this in combination with ParseEpisodeURL and hand over the corresponding results
|
// Use this in combination with ParseEpisodeURL and hand over the corresponding results
|
||||||
// to this function.
|
// to this function.
|
||||||
func (c *Crunchyroll) FindEpisodeByName(seriesName, episodeTitle string) ([]*Episode, error) {
|
func (c *Crunchyroll) FindEpisodeByName(seriesName, episodeTitle string) ([]*Episode, error) {
|
||||||
video, err := c.FindVideoByName(seriesName)
|
series, _, err := c.Search(seriesName, 5)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
seasons, err := video.(*Series).Seasons()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchingEpisodes []*Episode
|
var matchingEpisodes []*Episode
|
||||||
for _, season := range seasons {
|
for _, s := range series {
|
||||||
episodes, err := season.Episodes()
|
seasons, err := s.Seasons()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, episode := range episodes {
|
|
||||||
if episode.SlugTitle == episodeTitle {
|
for _, season := range seasons {
|
||||||
matchingEpisodes = append(matchingEpisodes, episode)
|
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
|
return matchingEpisodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue