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" "bufio"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
@ -35,10 +34,6 @@ func Refresh(env *web.Env) error {
} }
defer resp.Body.Close() 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 // Read all the file (~5MB) in memory
// We do that because the ~1 000 000 upserts take too long, and the IMDB // We do that because the ~1 000 000 upserts take too long, and the IMDB
// server will cut our connection after ~2h // 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 // downloadImages will download the show images
func (s *Show) downloadImages(env *web.Env) { func (s *Show) downloadImages(env *web.Env) {
// Create the directory for the show if it doesn't exist // Download the banner
if _, err := os.Stat(s.imgDirectory()); err != nil { err := web.Download(s.Show.Banner, s.imgFile("banner"), false)
if err = os.Mkdir(s.imgDirectory(), os.ModePerm); err != nil { if err != nil {
env.Log.Warnf("couldn't create show directory %s: %s", s.imgDirectory(), err) env.Log.Errorf("failed to dowload banner: %s", err)
return
} }
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 err = web.Download(s.Show.Poster, s.imgFile("poster"), true)
for _, img := range []struct { if err != nil {
url string env.Log.Errorf("failed to dowload poster: %s", err)
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 // Download episode thumbs
@ -203,21 +180,16 @@ 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 ) : %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 // 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

View File

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