diff --git a/backend/shows/episodes.go b/backend/shows/episodes.go index 152cf4e..7ef3708 100644 --- a/backend/shows/episodes.go +++ b/backend/shows/episodes.go @@ -15,8 +15,7 @@ import ( // Episode represents an episode type Episode struct { - client *papi.Client - pShow *papi.Show + show *Show *polochon.ShowEpisode } @@ -33,11 +32,11 @@ func (e *Episode) MarshalJSON() ([]byte, error) { var container string // If the episode is present, fill the downloadURL - if e.pShow != nil { - pEpisode := e.pShow.GetEpisode(e.Season, e.Episode) + if e.show.pShow != nil { + pEpisode := e.show.pShow.GetEpisode(e.Season, e.Episode) if pEpisode != nil { // Get the DownloadURL - downloadURL, _ = e.client.DownloadURL( + downloadURL, _ = e.show.client.DownloadURL( &papi.Episode{ ShowImdbID: e.ShowImdbID, Episode: e.Episode, @@ -52,7 +51,7 @@ func (e *Episode) MarshalJSON() ([]byte, error) { // Append the Subtitles for _, l := range pEpisode.Subtitles { - subtitleURL, _ := e.client.SubtitleURL(pEpisode, l) + subtitleURL, _ := e.show.client.SubtitleURL(pEpisode, l) subs = append(subs, subtitles.Subtitle{ Language: l, URL: subtitleURL, @@ -72,6 +71,7 @@ func (e *Episode) MarshalJSON() ([]byte, error) { AudioCodec string `json:"audio_codec"` VideoCodec string `json:"video_codec"` Container string `json:"container"` + Thumb string `json:"thumb"` }{ alias: (*alias)(e), PolochonURL: downloadURL, @@ -81,18 +81,22 @@ func (e *Episode) MarshalJSON() ([]byte, error) { AudioCodec: audioCodec, VideoCodec: videoCodec, Container: container, + Thumb: e.getThumbURL(), } return json.Marshal(episodeToMarshal) } +func (e *Episode) getThumbURL() string { + return e.show.GetImageURL(fmt.Sprintf("%d-%d", e.Season, e.Episode)) +} + // NewEpisode returns an Episode -func NewEpisode(client *papi.Client, pShow *papi.Show, imdbID string, season, episode int) *Episode { +func NewEpisode(show *Show, season, episode int) *Episode { return &Episode{ - client: client, - pShow: pShow, + show: show, ShowEpisode: &polochon.ShowEpisode{ - ShowImdbID: imdbID, + ShowImdbID: show.ImdbID, Season: season, Episode: episode, }, diff --git a/backend/shows/handlers.go b/backend/shows/handlers.go index 1d34f6c..093486e 100644 --- a/backend/shows/handlers.go +++ b/backend/shows/handlers.go @@ -333,7 +333,13 @@ func RefreshEpisodeHandler(env *web.Env, w http.ResponseWriter, r *http.Request) env.Log.Warnf("Error getting show %q", err) } - e := NewEpisode(client, pShow, id, season, episode) + s := &Show{ + Show: &polochon.Show{ImdbID: id}, + pShow: pShow, + client: client, + } + + e := NewEpisode(s, season, episode) // Refresh the episode err = e.Refresh(env, env.Config.Show.Detailers) if err != nil { diff --git a/backend/shows/shows.go b/backend/shows/shows.go index 6393476..5de72ec 100644 --- a/backend/shows/shows.go +++ b/backend/shows/shows.go @@ -48,8 +48,7 @@ func (s *Show) MarshalJSON() ([]byte, error) { for _, e := range s.Show.Episodes { showToMarshal.Episodes = append(showToMarshal.Episodes, Episode{ ShowEpisode: e, - client: s.client, - pShow: s.pShow, + show: s, }) } return json.Marshal(showToMarshal) @@ -174,6 +173,18 @@ func (s *Show) downloadImages(env *web.Env) { if err != nil { env.Log.Errorf("failed to dowload poster: %s", err) } + + // Download episode thumbs + for _, e := range s.Episodes { + if e.Thumb == "" { + continue + } + + err = web.Download(e.Thumb, s.imgFile(fmt.Sprintf("%d-%d", e.Season, e.Episode)), false) + if err != nil { + env.Log.Errorf("failed to dowload the thumb for season %d episode %d: %s", e.Season, e.Episode, err) + } + } } // imgURL returns the default image url