All checks were successful
continuous-integration/drone/push Build is passing
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
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
|
|
}
|
|
|
|
// Add the movie images
|
|
imgURL := fmt.Sprintf("movies/%s.jpg", pMovie.ImdbID)
|
|
imgFile := filepath.Join(b.PublicDir, "img", imgURL)
|
|
posterURL := ""
|
|
if _, err := os.Stat(imgFile); !os.IsNotExist(err) {
|
|
posterURL = b.ImgURLPrefix + imgURL
|
|
}
|
|
pMovie.Thumb = posterURL
|
|
|
|
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
|
|
}
|