imagePath #20

Merged
gregdel merged 1 commits from imagePath into master 2020-04-07 15:57:07 +00:00

View File

@ -160,18 +160,41 @@ func (s *Show) GetImageURL(imgType string) string {
// downloadImages will download the show images // downloadImages will download the show images
func (s *Show) downloadImages(env *web.Env) { func (s *Show) downloadImages(env *web.Env) {
// Download the banner // Create the directory for the show if it doesn't exist
err := web.Download(s.Show.Banner, s.imgFile("banner"), false) if _, err := os.Stat(s.imgDirectory()); err != nil {
if err != nil { if err = os.Mkdir(s.imgDirectory(), os.ModePerm); err != nil {
env.Log.Errorf("failed to dowload banner: %s", err) env.Log.Warnf("couldn't create show directory %s: %s", s.imgDirectory(), err)
return
}
} }
err = web.Download(s.Show.Fanart, s.imgFile("fanart"), false) // Download the show images
if err != nil { for _, img := range []struct {
env.Log.Errorf("failed to dowload fanart: %s", err) url string
} urlType string
err = web.Download(s.Show.Poster, s.imgFile("poster"), true) scale bool
if err != nil { }{
env.Log.Errorf("failed to dowload poster: %s", err) {
url: s.Show.Banner,
urlType: "banner",
scale: false,
},
{
url: s.Show.Fanart,
urlType: "fanart",
scale: false,
},
{
url: s.Show.Poster,
urlType: "poster",
scale: true,
},
} {
if img.url == "" {
continue
}
if err := web.Download(img.url, s.imgFile(img.urlType), img.scale); err != nil {
env.Log.Errorf("failed to dowload %s: %s", img.urlType, err)
}
} }
// Download episode thumbs // Download episode thumbs
@ -180,16 +203,21 @@ func (s *Show) downloadImages(env *web.Env) {
continue continue
} }
err = web.Download(e.Thumb, s.imgFile(fmt.Sprintf("%d-%d", e.Season, e.Episode)), false) err := web.Download(e.Thumb, s.imgFile(fmt.Sprintf("%d-%d", e.Season, e.Episode)), false)
if err != nil { if err != nil {
env.Log.Errorf("failed to dowload the thumb for season %d episode %d: %s", e.Season, e.Episode, err) env.Log.Errorf("failed to dowload the thumb for season %d episode %d ( %s ) : %s", e.Season, e.Episode, e.Thumb, err)
} }
} }
} }
// imgURL returns the default image url // imgURL returns the default image url
func (s *Show) imgURL(imgType string) string { func (s *Show) imgURL(imgType string) string {
return fmt.Sprintf("shows/%s-%s.jpg", s.ImdbID, imgType) return fmt.Sprintf("shows/%s/%s.jpg", s.ImdbID, imgType)
}
// imgDirectory returns the directory containing all the show images
func (s *Show) imgDirectory() string {
return filepath.Join(s.publicDir, "img", fmt.Sprintf("shows/%s", s.ImdbID))
} }
// imgFile returns the image location on disk // imgFile returns the image location on disk