Compare commits

..

3 Commits

Author SHA1 Message Date
937b12bb67 Update polochon
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-03 14:18:59 +02:00
91bf3f8cdb Improve GetDetails and Search
We now use the right log object with prefix and return an error on
GetDetails only if the error is Fatal
2020-04-03 14:18:50 +02:00
8a07623668 Edit show.NewWithClient
The func now takes a full polochon.Show instead of just an ImdbID, so
that it we have more than an ImdbID (a TvdbID for example), we can
transmit it to the show.Show
2020-04-03 13:48:12 +02:00
7 changed files with 32 additions and 21 deletions

View File

@ -141,7 +141,7 @@ func GetShows(env *web.Env, user *models.User, source string, category string, f
for _, id := range media.IDs { for _, id := range media.IDs {
pShow, _ := pShows.Has(id) pShow, _ := pShows.Has(id)
wShow, _ := wShows.IsShowInWishlist(id) wShow, _ := wShows.IsShowInWishlist(id)
show := shows.NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) show := shows.NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -11,6 +11,7 @@ import (
"git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/models"
"git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/subtitles"
"git.quimbo.fr/odwrtw/canape/backend/web" "git.quimbo.fr/odwrtw/canape/backend/web"
"github.com/odwrtw/errors"
"github.com/odwrtw/papi" "github.com/odwrtw/papi"
polochon "github.com/odwrtw/polochon/lib" polochon "github.com/odwrtw/polochon/lib"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -97,9 +98,11 @@ func (m *Movie) GetDetails(env *web.Env, detailers []polochon.Detailer) error {
m.Detailers = detailers m.Detailers = detailers
// GetDetail // GetDetail
err := polochon.GetDetails(m.Movie, env.Log) err := polochon.GetDetails(m.Movie, log)
if err != nil { if err != nil {
return err if errors.IsFatal(err) {
return err
}
} }
log.Debug("got details from detailers") log.Debug("got details from detailers")

View File

@ -8,6 +8,7 @@ import (
"git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/models"
"git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/subtitles"
"git.quimbo.fr/odwrtw/canape/backend/web" "git.quimbo.fr/odwrtw/canape/backend/web"
"github.com/odwrtw/errors"
"github.com/odwrtw/papi" "github.com/odwrtw/papi"
polochon "github.com/odwrtw/polochon/lib" polochon "github.com/odwrtw/polochon/lib"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -211,9 +212,11 @@ func (e *Episode) GetEpisodeDetails(env *web.Env, detailers []polochon.Detailer)
e.ShowEpisode.Detailers = detailers e.ShowEpisode.Detailers = detailers
// Get the details // Get the details
err := polochon.GetDetails(e.ShowEpisode, env.Log) err := polochon.GetDetails(e.ShowEpisode, log)
if err != nil { if err != nil {
return err if errors.IsFatal(err) {
return err
}
} }
log.Debug("got details from detailers") log.Debug("got details from detailers")

View File

@ -43,7 +43,7 @@ func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) err
log.Println("Got error getting wishlisted show ", err) log.Println("Got error getting wishlisted show ", err)
} }
s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First try from the db // First try from the db
first := []polochon.Detailer{env.Backend.Detailer} first := []polochon.Detailer{env.Backend.Detailer}
// Then try from the polochon detailers // Then try from the polochon detailers
@ -89,7 +89,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
log.Println("Got error getting wishlisted show ", err) log.Println("Got error getting wishlisted show ", err)
} }
s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) s := NewWithClient(&polochon.Show{ImdbID: id}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// Refresh the polochon detailers // Refresh the polochon detailers
detailers := env.Config.Show.Detailers detailers := env.Config.Show.Detailers
err = s.Refresh(env, detailers) err = s.Refresh(env, detailers)
@ -128,11 +128,13 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
searchers := env.Config.Show.Searchers searchers := env.Config.Show.Searchers
// Iterate on all the searchers to search for the show // Iterate on all the searchers to search for the show
for _, searcher := range searchers { for _, searcher := range searchers {
result, err := searcher.SearchShow(search, env.Log) log := env.Log.WithField("searcher", searcher.Name())
result, err := searcher.SearchShow(search, log)
if err != nil { if err != nil {
env.Log.Errorf("error while searching show : %s", err) log.Errorf("error while searching show : %s", err)
continue continue
} }
log.Debug("found show")
// Add the results to the list of results // Add the results to the list of results
shows = append(shows, result...) shows = append(shows, result...)
} }
@ -161,7 +163,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
for _, s := range shows { for _, s := range shows {
pShow, _ := pShows.Has(s.ImdbID) pShow, _ := pShows.Has(s.ImdbID)
wShow, _ := wShows.IsShowInWishlist(s.ImdbID) wShow, _ := wShows.IsShowInWishlist(s.ImdbID)
show := NewWithClient(s.ImdbID, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) show := NewWithClient(s, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First try from the db // First try from the db
first := []polochon.Detailer{env.Backend.Detailer} first := []polochon.Detailer{env.Backend.Detailer}
@ -240,7 +242,8 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
showList := []*Show{} showList := []*Show{}
for _, wishedShow := range wShows.List() { for _, wishedShow := range wShows.List() {
pShow, _ := pShows.Has(wishedShow.ImdbID) pShow, _ := pShows.Has(wishedShow.ImdbID)
show := NewWithClient(wishedShow.ImdbID, client, pShow, wishedShow, env.Config.PublicDir, env.Config.ImgURLPrefix) poloShow := &polochon.Show{ImdbID: wishedShow.ImdbID}
show := NewWithClient(poloShow, client, pShow, wishedShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -9,6 +9,7 @@ import (
"git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/models"
"git.quimbo.fr/odwrtw/canape/backend/web" "git.quimbo.fr/odwrtw/canape/backend/web"
"github.com/odwrtw/errors"
"github.com/odwrtw/papi" "github.com/odwrtw/papi"
polochon "github.com/odwrtw/polochon/lib" polochon "github.com/odwrtw/polochon/lib"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -65,11 +66,9 @@ func New(imdbID string, publicDir, imgURLPrefix string) *Show {
} }
// NewWithClient returns a new Show with a polochon ShowConfig // NewWithClient returns a new Show with a polochon ShowConfig
func NewWithClient(imdbID string, client *papi.Client, pShow *papi.Show, wShow *models.WishedShow, publicDir, imgURLPrefix string) *Show { func NewWithClient(show *polochon.Show, client *papi.Client, pShow *papi.Show, wShow *models.WishedShow, publicDir, imgURLPrefix string) *Show {
s := &Show{ s := &Show{
Show: &polochon.Show{ Show: show,
ImdbID: imdbID,
},
client: client, client: client,
pShow: pShow, pShow: pShow,
publicDir: publicDir, publicDir: publicDir,
@ -97,9 +96,11 @@ func (s *Show) GetDetails(env *web.Env, detailers []polochon.Detailer) error {
s.Detailers = detailers s.Detailers = detailers
// Get the details // Get the details
err := polochon.GetDetails(s.Show, env.Log) err := polochon.GetDetails(s.Show, log)
if err != nil { if err != nil {
return err if errors.IsFatal(err) {
return err
}
} }
log.Debugf("got details from detailers") log.Debugf("got details from detailers")
@ -219,7 +220,7 @@ func getPolochonShows(env *web.Env, user *models.User) ([]*Show, error) {
// Create Shows objects from the shows retrieved // Create Shows objects from the shows retrieved
for _, pShow := range pshows.List() { for _, pShow := range pshows.List() {
wShow, _ := wShows.IsShowInWishlist(pShow.ImdbID) wShow, _ := wShows.IsShowInWishlist(pShow.ImdbID)
show := NewWithClient(pShow.ImdbID, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) show := NewWithClient(&polochon.Show{ImdbID: pShow.ImdbID}, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix)
shows = append(shows, show) shows = append(shows, show)
} }
return shows, nil return shows, nil

3
go.mod
View File

@ -14,8 +14,9 @@ require (
github.com/lib/pq v1.1.1 github.com/lib/pq v1.1.1
github.com/mattn/go-sqlite3 v1.10.0 // indirect github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/odwrtw/errors v0.0.0-20170604160533-c747b9d17833
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a
github.com/odwrtw/polochon v0.0.0-20200131104911-522892bdd053 github.com/odwrtw/polochon v0.0.0-20200403121328-985a643dc6aa
github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029 github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029
github.com/pioz/tvdb v0.0.0-20190503215423-f45c687faba9 // indirect github.com/pioz/tvdb v0.0.0-20190503215423-f45c687faba9 // indirect
github.com/robfig/cron v1.1.0 github.com/robfig/cron v1.1.0

4
go.sum
View File

@ -137,8 +137,8 @@ github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6 h1:bF8XKFfYNY4quRdqJ5E
github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6/go.mod h1:CXotdtODLpW0/yuFV5XH8Rmrj0eAfPLvdMKykPM2WCk= github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6/go.mod h1:CXotdtODLpW0/yuFV5XH8Rmrj0eAfPLvdMKykPM2WCk=
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a h1:9mdPet/ianrckPWR2jSekoafz6BaqbF7kPXLnDEIKu8= github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a h1:9mdPet/ianrckPWR2jSekoafz6BaqbF7kPXLnDEIKu8=
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo= github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo=
github.com/odwrtw/polochon v0.0.0-20200131104911-522892bdd053 h1:3Apbf8rWjgKswZuO5VWVoaFMtit4COdNP/ebRz6mi4Q= github.com/odwrtw/polochon v0.0.0-20200403121328-985a643dc6aa h1:Jh5cSZCcBwzULN9po+0mzydbPqiMRZAXkScON7BNvVw=
github.com/odwrtw/polochon v0.0.0-20200131104911-522892bdd053/go.mod h1:vb6PuVZ0ToGnfgVxijvUdYsayoItmdOYSVM8yMnEtJo= github.com/odwrtw/polochon v0.0.0-20200403121328-985a643dc6aa/go.mod h1:vb6PuVZ0ToGnfgVxijvUdYsayoItmdOYSVM8yMnEtJo=
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f h1:fwEIGT+o3e8+XkBqrwsE3/+9ketTQXflPhCkv3/w990= github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f h1:fwEIGT+o3e8+XkBqrwsE3/+9ketTQXflPhCkv3/w990=
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f/go.mod h1:updLvMbQo2xHoz94MX9+GqmSoKhf6E8fs/J+wLvvu6A= github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f/go.mod h1:updLvMbQo2xHoz94MX9+GqmSoKhf6E8fs/J+wLvvu6A=
github.com/odwrtw/trakttv v0.0.0-20170418094324-76889e438555 h1:5JfY2cKMq0g+IpgAaY+6EPRZZK8eV2lgRIUsqPB+hBY= github.com/odwrtw/trakttv v0.0.0-20170418094324-76889e438555 h1:5JfY2cKMq0g+IpgAaY+6EPRZZK8eV2lgRIUsqPB+hBY=