69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
|
|
polochon "github.com/odwrtw/polochon/lib"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// GetDetails implements the polochon Detailer interface
|
|
func (b *Backend) GetDetails(media interface{}, log *logrus.Entry) error {
|
|
switch t := media.(type) {
|
|
case *polochon.Show:
|
|
return b.GetShowDetails(t, log)
|
|
case *polochon.ShowEpisode:
|
|
return b.GetShowEpisodeDetails(t, log)
|
|
case *polochon.Movie:
|
|
return b.GetMovieDetails(t, log)
|
|
default:
|
|
return errors.New("invalid type")
|
|
}
|
|
}
|
|
|
|
// GetMovieDetails gets details for movies
|
|
func (b *Backend) GetMovieDetails(pMovie *polochon.Movie, log *logrus.Entry) error {
|
|
// Get the movie
|
|
if err := GetMovie(b.Database, pMovie); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf("got movie %s from backend", pMovie.ImdbID)
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetShowDetails gets details for shows
|
|
func (b *Backend) GetShowDetails(pShow *polochon.Show, log *logrus.Entry) error {
|
|
// Get the show
|
|
if err := GetShow(b.Database, pShow); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf("got show %s from backend", pShow.ImdbID)
|
|
// Get the show's episodes
|
|
err := GetEpisodes(b.Database, pShow, log)
|
|
if err != nil {
|
|
log.Warnf("error while getting episodes: %s", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetShowEpisodeDetails gets details for episodes
|
|
func (b *Backend) GetShowEpisodeDetails(pEpisode *polochon.ShowEpisode, log *logrus.Entry) error {
|
|
// Get the episode
|
|
if err := GetEpisode(b.Database, pEpisode); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf(
|
|
"got episode S%02dE%02d %s from backend",
|
|
pEpisode.Season,
|
|
pEpisode.Episode,
|
|
pEpisode.ShowImdbID,
|
|
)
|
|
|
|
return nil
|
|
}
|