diff --git a/backend/config/canape.go b/backend/config/canape.go index 5493631..3ebe941 100644 --- a/backend/config/canape.go +++ b/backend/config/canape.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "os" - polochon "github.com/odwrtw/polochon/lib" polochonConfig "github.com/odwrtw/polochon/lib/configuration" "github.com/sirupsen/logrus" @@ -20,15 +19,7 @@ type Config struct { ImgURLPrefix string `yaml:"img_url_prefix"` PeriodicRefresh PeriodicRefreshConfig `yaml:"periodic_refresh"` - MovieExplorers []polochon.Explorer - MovieDetailers []polochon.Detailer - MovieTorrenters []polochon.Torrenter - MovieSearchers []polochon.Searcher - - ShowExplorers []polochon.Explorer - ShowDetailers []polochon.Detailer - ShowTorrenters []polochon.Torrenter - ShowSearchers []polochon.Searcher + PolochonConfig *polochonConfig.Config } // AuthorizerConfig is the config for the authentication @@ -54,7 +45,8 @@ func Load(path string, log *logrus.Entry) (*Config, error) { defer file.Close() cf := &Config{} - polochonCf := &polochonConfig.ConfigFileRoot{} + polochonConfigFile := &polochonConfig.ConfigFileRoot{} + polochonConfig := &polochonConfig.Config{} // Read it b, err := ioutil.ReadAll(file) @@ -69,30 +61,24 @@ func Load(path string, log *logrus.Entry) (*Config, error) { } // Unmarshal its content into the polochon.ConfigFileRoot obj - err = yaml.Unmarshal(b, polochonCf) + err = yaml.Unmarshal(b, polochonConfigFile) if err != nil { return nil, err } // Init all the show torrenters / detailers / searchers / explorers - showConf, err := polochonCf.InitShow(log) + err = polochonConfig.InitShow(polochonConfigFile) if err != nil { return nil, err } - cf.ShowTorrenters = showConf.Torrenters - cf.ShowDetailers = showConf.Detailers - cf.ShowSearchers = showConf.Searchers - cf.ShowExplorers = showConf.Explorers // Init all the movie torrenters / detailers / searchers / explorers - movieConf, err := polochonCf.InitMovie(log) + err = polochonConfig.InitMovie(polochonConfigFile) if err != nil { return nil, err } - cf.MovieTorrenters = movieConf.Torrenters - cf.MovieDetailers = movieConf.Detailers - cf.MovieSearchers = movieConf.Searchers - cf.MovieExplorers = movieConf.Explorers + + cf.PolochonConfig = polochonConfig return cf, nil } diff --git a/backend/external_medias/external_medias.go b/backend/external_medias/external_medias.go index 72864de..5ee5077 100644 --- a/backend/external_medias/external_medias.go +++ b/backend/external_medias/external_medias.go @@ -3,21 +3,21 @@ package extmedias import ( "fmt" - polochon "github.com/odwrtw/polochon/lib" - "github.com/sirupsen/logrus" "git.quimbo.fr/odwrtw/canape/backend/backend" "git.quimbo.fr/odwrtw/canape/backend/movies" "git.quimbo.fr/odwrtw/canape/backend/shows" "git.quimbo.fr/odwrtw/canape/backend/web" + polochon "github.com/odwrtw/polochon/lib" + "github.com/sirupsen/logrus" ) // NewExplorer returns a polochon.Explorer from the list of Explorers in the config func NewExplorer(env *web.Env, mediaType, name string) (polochon.Explorer, error) { var explorers []polochon.Explorer if mediaType == "movie" { - explorers = env.Config.MovieExplorers + explorers = env.Config.PolochonConfig.Movie.Explorers } else { - explorers = env.Config.ShowExplorers + explorers = env.Config.PolochonConfig.Show.Explorers } for _, e := range explorers { @@ -96,7 +96,7 @@ func GetMediaIDs(env *web.Env, mediaType string, source string, category string) func RefreshShows(env *web.Env) { showMap := make(map[string]*shows.Show) // Iterate over all show explorers - for _, showExplorer := range env.Config.ShowExplorers { + for _, showExplorer := range env.Config.PolochonConfig.Show.Explorers { availableOptions := showExplorer.AvailableShowOptions() // Iterate over all show explorer options for _, option := range availableOptions { @@ -132,7 +132,7 @@ func RefreshShows(env *web.Env) { for id := range showMap { show := shows.New(id, env.Config.PublicDir, env.Config.ImgURLPrefix) // Refresh the shows - err := show.Refresh(env, env.Config.ShowDetailers) + err := show.Refresh(env, env.Config.PolochonConfig.Show.Detailers) if err != nil { env.Log.Warnf("error while refreshing show %s : %s", id, err) } @@ -146,7 +146,7 @@ func RefreshShows(env *web.Env) { // too many requests on our torrenters for _, e := range show.LastSeasonEpisodes() { // Refresh the torrents - err := shows.RefreshTorrents(env, e, env.Config.ShowTorrenters) + err := shows.RefreshTorrents(env, e, env.Config.PolochonConfig.Show.Torrenters) if err != nil { env.Log.Error(err) } @@ -162,7 +162,7 @@ func RefreshShows(env *web.Env) { func RefreshMovies(env *web.Env) { movieMap := make(map[string]struct{}) // Iterate over all movie explorers - for _, movieExplorer := range env.Config.MovieExplorers { + for _, movieExplorer := range env.Config.PolochonConfig.Movie.Explorers { availableOptions := movieExplorer.AvailableMovieOptions() // Iterate over all movie explorer options for _, option := range availableOptions { @@ -198,12 +198,12 @@ func RefreshMovies(env *web.Env) { for id := range movieMap { movie := movies.New(id, nil, nil, false, env.Config.PublicDir, env.Config.ImgURLPrefix) // Refresh the movie - err := movie.Refresh(env, env.Config.MovieDetailers) + err := movie.Refresh(env, env.Config.PolochonConfig.Movie.Detailers) if err != nil { env.Log.Warnf("error while refreshing movie %s : %s", id, err) } // Refresh its torrents - err = movie.RefreshTorrents(env, env.Config.MovieTorrenters) + err = movie.RefreshTorrents(env, env.Config.PolochonConfig.Movie.Torrenters) if err != nil { env.Log.Warnf("error while refreshing movie torrents %s : %s", id, err) } diff --git a/backend/external_medias/handlers.go b/backend/external_medias/handlers.go index 2e52b09..053404e 100644 --- a/backend/external_medias/handlers.go +++ b/backend/external_medias/handlers.go @@ -4,14 +4,14 @@ import ( "errors" "net/http" - polochon "github.com/odwrtw/polochon/lib" - "github.com/sirupsen/logrus" "git.quimbo.fr/odwrtw/canape/backend/auth" "git.quimbo.fr/odwrtw/canape/backend/backend" "git.quimbo.fr/odwrtw/canape/backend/movies" "git.quimbo.fr/odwrtw/canape/backend/shows" "git.quimbo.fr/odwrtw/canape/backend/users" "git.quimbo.fr/odwrtw/canape/backend/web" + polochon "github.com/odwrtw/polochon/lib" + "github.com/sirupsen/logrus" ) // RefreshHandler refresh the explored movies @@ -86,7 +86,7 @@ func GetMovies(env *web.Env, user *users.User, source string, category string) ( // First check in the DB before := []polochon.Detailer{env.Backend.Detailer} // Then with the default detailers - after := env.Config.MovieDetailers + after := env.Config.PolochonConfig.Movie.Detailers err := movie.GetAndFetch(env, before, after) if err != nil { env.Log.Errorf("error while getting movie details : %s", err) @@ -148,7 +148,7 @@ func GetShows(env *web.Env, user *users.User, source string, category string, fo // First check in the DB before := []polochon.Detailer{env.Backend.Detailer} // Then with the default detailers - after := env.Config.ShowDetailers + after := env.Config.PolochonConfig.Show.Detailers err := show.GetAndFetch(env, before, after) if err != nil { env.Log.Errorf("error while getting show details : %s", err) diff --git a/backend/movies/handlers.go b/backend/movies/handlers.go index 5ef3707..fb6b287 100644 --- a/backend/movies/handlers.go +++ b/backend/movies/handlers.go @@ -6,16 +6,16 @@ import ( "log" "net/http" - "github.com/gorilla/mux" - "github.com/odwrtw/papi" - polochon "github.com/odwrtw/polochon/lib" - "github.com/sirupsen/logrus" "git.quimbo.fr/odwrtw/canape/backend/auth" "git.quimbo.fr/odwrtw/canape/backend/backend" "git.quimbo.fr/odwrtw/canape/backend/config" "git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/users" "git.quimbo.fr/odwrtw/canape/backend/web" + "github.com/gorilla/mux" + "github.com/odwrtw/papi" + polochon "github.com/odwrtw/polochon/lib" + "github.com/sirupsen/logrus" ) // PolochonMoviesHandler will returns movies from Polochon @@ -45,7 +45,7 @@ func PolochonMoviesHandler(env *web.Env, w http.ResponseWriter, r *http.Request) // First try from the db first := []polochon.Detailer{env.Backend.Detailer} // Then try from the polochon detailer - detailers := env.Config.MovieDetailers + detailers := env.Config.PolochonConfig.Movie.Detailers err := m.GetAndFetch(env, first, detailers) if err != nil { env.Log.Error(err) @@ -97,12 +97,12 @@ func RefreshMovieHandler(env *web.Env, w http.ResponseWriter, r *http.Request) e m := New(id, client, pMovie, isWishlisted, env.Config.PublicDir, env.Config.ImgURLPrefix) // Refresh the movie's infos - if err := m.Refresh(env, env.Config.MovieDetailers); err != nil { + if err := m.Refresh(env, env.Config.PolochonConfig.Movie.Detailers); err != nil { env.Log.Error(err) } // Refresh the movie's torrents - if err := m.RefreshTorrents(env, env.Config.MovieTorrenters); err != nil { + if err := m.RefreshTorrents(env, env.Config.PolochonConfig.Movie.Torrenters); err != nil { env.Log.Error(err) } @@ -139,7 +139,7 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error { } var movies []*polochon.Movie - searchers := env.Config.MovieSearchers + searchers := env.Config.PolochonConfig.Movie.Searchers // Search for the movie with all the Searchers for _, searcher := range searchers { result, err := searcher.SearchMovie(search, env.Log) @@ -167,7 +167,7 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error { // First check in the DB before := []polochon.Detailer{env.Backend.Detailer} // Then with the default detailers - after := env.Config.MovieDetailers + after := env.Config.PolochonConfig.Movie.Detailers err := movie.GetAndFetch(env, before, after) if err != nil { env.Log.Errorf("error while getting movie details : %s", err) @@ -293,7 +293,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er // First check in the DB before := []polochon.Detailer{env.Backend.Detailer} // Then with the default detailers - after := env.Config.MovieDetailers + after := env.Config.PolochonConfig.Movie.Detailers err := movie.GetAndFetch(env, before, after) if err != nil { env.Log.Errorf("error while getting movie details : %s", err) diff --git a/backend/shows/handlers.go b/backend/shows/handlers.go index b78e965..f771bf5 100644 --- a/backend/shows/handlers.go +++ b/backend/shows/handlers.go @@ -9,14 +9,14 @@ import ( "net/http" - "github.com/gorilla/mux" - "github.com/odwrtw/papi" - polochon "github.com/odwrtw/polochon/lib" "git.quimbo.fr/odwrtw/canape/backend/auth" "git.quimbo.fr/odwrtw/canape/backend/backend" "git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/users" "git.quimbo.fr/odwrtw/canape/backend/web" + "github.com/gorilla/mux" + "github.com/odwrtw/papi" + polochon "github.com/odwrtw/polochon/lib" ) // ErrPolochonUnavailable is an error returned if the polochon server is not available @@ -52,7 +52,7 @@ func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) err // First try from the db first := []polochon.Detailer{env.Backend.Detailer} // Then try from the polochon detailers - detailers := env.Config.ShowDetailers + detailers := env.Config.PolochonConfig.Show.Detailers err = s.GetAndFetch(env, first, detailers) if err != nil { env.Log.Error(err) @@ -100,7 +100,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er s := NewWithClient(id, client, pShow, wShow, env.Config.PublicDir, env.Config.ImgURLPrefix) // Refresh the polochon detailers - detailers := env.Config.ShowDetailers + detailers := env.Config.PolochonConfig.Show.Detailers err = s.Refresh(env, detailers) if err != nil { env.Log.Error(err) @@ -110,7 +110,7 @@ func RefreshShowHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er env.Log.Debug("getting episodes torrents") for _, e := range s.Episodes { // Get torrents from the db - err := RefreshTorrents(env, e, env.Config.ShowTorrenters) + err := RefreshTorrents(env, e, env.Config.PolochonConfig.Show.Torrenters) if err != nil { env.Log.Error(err) } @@ -133,7 +133,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error { } var shows []*polochon.Show - searchers := env.Config.ShowSearchers + searchers := env.Config.PolochonConfig.Show.Searchers // Iterate on all the searchers to search for the show for _, searcher := range searchers { result, err := searcher.SearchShow(search, env.Log) @@ -174,7 +174,7 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error { // First try from the db first := []polochon.Detailer{env.Backend.Detailer} // Then try from the polochon detailers - detailers := env.Config.ShowDetailers + detailers := env.Config.PolochonConfig.Show.Detailers err := show.GetAndFetch(env, first, detailers) if err != nil { env.Log.Error(err) @@ -265,7 +265,7 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er // First check in the DB before := []polochon.Detailer{env.Backend.Detailer} // Then with the default detailers - after := env.Config.ShowDetailers + after := env.Config.PolochonConfig.Show.Detailers err := show.GetAndFetch(env, before, after) if err != nil { env.Log.Errorf("error while getting show details : %s", err) @@ -297,7 +297,7 @@ func PolochonShowsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) // First try from the db first := []polochon.Detailer{env.Backend.Detailer} // Then try from the polochon detailer - detailers := env.Config.ShowDetailers + detailers := env.Config.PolochonConfig.Show.Detailers err := s.GetAndFetch(env, first, detailers) if err != nil { env.Log.Error(err) @@ -330,19 +330,19 @@ func RefreshEpisodeHandler(env *web.Env, w http.ResponseWriter, r *http.Request) pShow, err := client.GetShow(id) if err != nil && err != papi.ErrResourceNotFound { - env.Log.Warnf("Error getting show ", err) + env.Log.Warnf("Error getting show %q", err) } e := NewEpisode(client, pShow, id, season, episode) // Refresh the episode - err = e.Refresh(env, env.Config.ShowDetailers) + err = e.Refresh(env, env.Config.PolochonConfig.Show.Detailers) if err != nil { env.Log.Error(err) return env.RenderError(w, err) } // Refresh the torrents - err = e.RefreshTorrents(env, env.Config.ShowTorrenters) + err = e.RefreshTorrents(env, env.Config.PolochonConfig.Show.Torrenters) if err != nil { env.Log.Error(err) } diff --git a/backend/torrents/handlers.go b/backend/torrents/handlers.go index 1f83b96..68a6015 100644 --- a/backend/torrents/handlers.go +++ b/backend/torrents/handlers.go @@ -107,9 +107,9 @@ func SearchHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error { var torrenters []polochon.Torrenter switch searchType { case "movies": - torrenters = env.Config.MovieTorrenters + torrenters = env.Config.PolochonConfig.Movie.Torrenters case "shows": - torrenters = env.Config.ShowTorrenters + torrenters = env.Config.PolochonConfig.Show.Torrenters default: return env.RenderError(w, errors.New("invalid search type")) }