Change the shows image path
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

From img/shows/ttXXXXX-1-1.png and img/shows/ttXXXXX-banner.png
To   img/shows/ttXXXXX/1-1.png and img/shows/ttXXXXX/banner.png

Rewrite things while we're here

Example of scripts to migrate from old path to new path:

dir="shows"
for file in "$dir"/*; do
        # Replace the first - by a / in order to get the new image path
        newfile=$(echo "$file" | sed 's/-/\//')
        # Delete everything after the first - in order to get the show path
        showpath=$(echo "$file" | sed 's/-.*//')
        [ ! -d "$showpath" ] && mkdir "$showpath"
        mv "$file" "$newfile"
done
This commit is contained in:
Lucas BEE 2020-04-07 17:46:42 +02:00
parent e5b4639cab
commit 54bbbf84f4

View File

@ -160,18 +160,41 @@ func (s *Show) GetImageURL(imgType string) string {
// downloadImages will download the show images
func (s *Show) downloadImages(env *web.Env) {
// Download the banner
err := web.Download(s.Show.Banner, s.imgFile("banner"), false)
if err != nil {
env.Log.Errorf("failed to dowload banner: %s", err)
// Create the directory for the show if it doesn't exist
if _, err := os.Stat(s.imgDirectory()); err != nil {
if err = os.Mkdir(s.imgDirectory(), os.ModePerm); err != nil {
env.Log.Warnf("couldn't create show directory %s: %s", s.imgDirectory(), err)
return
}
}
err = web.Download(s.Show.Fanart, s.imgFile("fanart"), false)
if err != nil {
env.Log.Errorf("failed to dowload fanart: %s", err)
}
err = web.Download(s.Show.Poster, s.imgFile("poster"), true)
if err != nil {
env.Log.Errorf("failed to dowload poster: %s", err)
// Download the show images
for _, img := range []struct {
url string
urlType string
scale bool
}{
{
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
@ -180,16 +203,21 @@ func (s *Show) downloadImages(env *web.Env) {
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 {
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
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