Compare commits

..

No commits in common. "54bbbf84f4094fe3ef70635593d7b93c571dae01" and "98eb833dc0e861a8d1426201d064d3036b4bc650" have entirely different histories.

3 changed files with 14 additions and 52 deletions

View File

@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"net/http"
"strconv"
@ -35,10 +34,6 @@ func Refresh(env *web.Env) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got HTTP error %s", resp.Status)
}
// Read all the file (~5MB) in memory
// We do that because the ~1 000 000 upserts take too long, and the IMDB
// server will cut our connection after ~2h

View File

@ -160,41 +160,18 @@ func (s *Show) GetImageURL(imgType string) string {
// downloadImages will download the show images
func (s *Show) downloadImages(env *web.Env) {
// 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
// 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)
}
err = web.Download(s.Show.Fanart, s.imgFile("fanart"), false)
if err != nil {
env.Log.Errorf("failed to dowload fanart: %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)
}
err = web.Download(s.Show.Poster, s.imgFile("poster"), true)
if err != nil {
env.Log.Errorf("failed to dowload poster: %s", err)
}
// Download episode thumbs
@ -203,21 +180,16 @@ 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 ) : %s", e.Season, e.Episode, e.Thumb, err)
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
func (s *Show) imgURL(imgType string) string {
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))
return fmt.Sprintf("shows/%s-%s.jpg", s.ImdbID, imgType)
}
// imgFile returns the image location on disk

View File

@ -1,7 +1,6 @@
package web
import (
"fmt"
"image"
"image/jpeg"
"net/http"
@ -27,10 +26,6 @@ var Download = func(srcURL, dest string, scale bool) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got HTTP error %s", resp.Status)
}
image, _, err := image.Decode(resp.Body)
if err != nil {
return err