From 385e8e514b84d94ec53a88ea55042e46af24e36d Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Fri, 7 Apr 2017 21:34:51 +0000 Subject: [PATCH] Use polochon config to initialize modules --- config.yml.exemple | 30 +++++++- src/internal/config/canape.go | 124 ++++++++-------------------------- src/main.go | 2 +- src/modules.go | 21 ++++++ 4 files changed, 78 insertions(+), 99 deletions(-) create mode 100644 src/modules.go diff --git a/config.yml.exemple b/config.yml.exemple index ae281e5..5d00b47 100644 --- a/config.yml.exemple +++ b/config.yml.exemple @@ -3,7 +3,33 @@ authorizer: pepper: pepper cost: 10 pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable -trakttv_client_id: my_trakttv_client_id -tmdb_api_key: my_tmdb_key listen_port: 3000 public_dir: build/public + +movie: + detailers: + - tmdb + - trakttv + torrenters: + - yts + searchers: + - yts + explorers: + - yts + - trakttv +show: + torrenters: + - eztv + detailers: + - tvdb + - trakttv + searchers: + - eztv + explorers: + - trakttv + - eztv +modules_params: + - name: trakttv + client_id: my_trakttv_client_id + - name: tmdb + apikey: my_tmdb_key diff --git a/src/internal/config/canape.go b/src/internal/config/canape.go index cc141c7..1687997 100644 --- a/src/internal/config/canape.go +++ b/src/internal/config/canape.go @@ -4,34 +4,29 @@ import ( "io/ioutil" "os" + "github.com/Sirupsen/logrus" polochon "github.com/odwrtw/polochon/lib" - "github.com/odwrtw/polochon/modules/eztv" - "github.com/odwrtw/polochon/modules/tmdb" - "github.com/odwrtw/polochon/modules/trakttv" - "github.com/odwrtw/polochon/modules/tvdb" - "github.com/odwrtw/polochon/modules/yts" + polochonConfig "github.com/odwrtw/polochon/lib/configuration" "gopkg.in/yaml.v2" ) // Config represents the Config of the canape app type Config struct { - Authorizer AuthorizerConfig `yaml:"authorizer"` - PGDSN string `yaml:"pgdsn"` - Port string `yaml:"listen_port"` - TraktTVClientID string `yaml:"trakttv_client_id"` - PublicDir string `yaml:"public_dir"` + Authorizer AuthorizerConfig `yaml:"authorizer"` + PGDSN string `yaml:"pgdsn"` + Port string `yaml:"listen_port"` + PublicDir string `yaml:"public_dir"` - // TODO improve the detailers and torrenters configurations - TmdbAPIKey string `yaml:"tmdb_api_key"` MovieExplorers []polochon.Explorer MovieDetailers []polochon.Detailer MovieTorrenters []polochon.Torrenter MovieSearchers []polochon.Searcher - ShowExplorers []polochon.Explorer - ShowDetailers []polochon.Detailer - ShowTorrenters []polochon.Torrenter - ShowSearchers []polochon.Searcher + + ShowExplorers []polochon.Explorer + ShowDetailers []polochon.Detailer + ShowTorrenters []polochon.Torrenter + ShowSearchers []polochon.Searcher } // AuthorizerConfig is the config for the authentication @@ -42,7 +37,7 @@ type AuthorizerConfig struct { } // Load loads a config file from a path and return a Config object -func Load(path string) (*Config, error) { +func Load(path string, log *logrus.Entry) (*Config, error) { // Open the file file, err := os.Open(path) if err != nil { @@ -51,6 +46,7 @@ func Load(path string) (*Config, error) { defer file.Close() cf := &Config{} + polochonCf := &polochonConfig.ConfigFileRoot{} // Read it b, err := ioutil.ReadAll(file) @@ -58,101 +54,37 @@ func Load(path string) (*Config, error) { return nil, err } - // Unmarshal its content + // Unmarshal its content into the Config obj err = yaml.Unmarshal(b, cf) if err != nil { return nil, err } - // Initialize the default values - - // Default movie detailers - cf.MovieDetailers = []polochon.Detailer{} - if cf.TmdbAPIKey != "" { - d, err := tmdb.New( - &tmdb.Params{ - ApiKey: cf.TmdbAPIKey, - }, - ) - if err != nil { - return nil, err - } - cf.MovieDetailers = append(cf.MovieDetailers, d) - } - - // Default movie explorers - cf.MovieExplorers = []polochon.Explorer{} - ytsExp, err := yts.NewExplorer() + // Unmarshal its content into the polochon.ConfigFileRoot obj + err = yaml.Unmarshal(b, polochonCf) if err != nil { return nil, err } - cf.MovieExplorers = append(cf.MovieExplorers, ytsExp) - if cf.TraktTVClientID != "" { - traktExp, err := trakttv.NewExplorer(&trakttv.Params{ - ClientID: cf.TraktTVClientID, - }) - if err != nil { - return nil, err - } - cf.MovieExplorers = append(cf.MovieExplorers, traktExp) - } - // Default movie torrenters - cf.MovieTorrenters = []polochon.Torrenter{} - d, err := yts.New() + // Init all the show torrenters / detailers / searchers / explorers + showConf, err := polochonCf.InitShow(log) if err != nil { return nil, err } - cf.MovieTorrenters = append(cf.MovieTorrenters, d) + cf.ShowTorrenters = showConf.Torrenters + cf.ShowDetailers = showConf.Detailers + cf.ShowSearchers = showConf.Searchers + cf.ShowExplorers = showConf.Explorers - // Default movie searchers - cf.MovieSearchers = []polochon.Searcher{} - movieSearcher, err := yts.NewSearcher() + // Init all the movie torrenters / detailers / searchers / explorers + movieConf, err := polochonCf.InitMovie(log) if err != nil { return nil, err } - cf.MovieSearchers = append(cf.MovieSearchers, movieSearcher) - - // Default show searchers - cf.ShowSearchers = []polochon.Searcher{} - showSearcher, err := eztv.NewSearcher() - if err != nil { - return nil, err - } - cf.ShowSearchers = append(cf.ShowSearchers, showSearcher) - - // Default show explorers - cf.ShowExplorers = []polochon.Explorer{} - eztvExp, err := eztv.NewExplorer() - if err != nil { - return nil, err - } - cf.ShowExplorers = append(cf.ShowExplorers, eztvExp) - if cf.TraktTVClientID != "" { - traktExp, err := trakttv.NewExplorer(&trakttv.Params{ - ClientID: cf.TraktTVClientID, - }) - if err != nil { - return nil, err - } - cf.ShowExplorers = append(cf.ShowExplorers, traktExp) - } - - // Default show detailers - cf.ShowDetailers = []polochon.Detailer{} - showDetailer, err := tvdb.NewDetailer() - if err != nil { - return nil, err - } - cf.ShowDetailers = append(cf.ShowDetailers, showDetailer) - - // Default show torrenters - cf.ShowTorrenters = []polochon.Torrenter{} - showTorrenter, err := eztv.New() - if err != nil { - return nil, err - } - cf.ShowTorrenters = append(cf.ShowTorrenters, showTorrenter) + cf.MovieTorrenters = movieConf.Torrenters + cf.MovieDetailers = movieConf.Detailers + cf.MovieSearchers = movieConf.Searchers + cf.MovieExplorers = movieConf.Explorers return cf, nil } diff --git a/src/main.go b/src/main.go index d59621e..a99a33c 100644 --- a/src/main.go +++ b/src/main.go @@ -31,7 +31,7 @@ func main() { logger.Level = logrus.DebugLevel log := logrus.NewEntry(logger) - cf, err := config.Load(cfgPath) + cf, err := config.Load(cfgPath, log) if err != nil { log.Panic(err) } diff --git a/src/modules.go b/src/modules.go new file mode 100644 index 0000000..ea0ae5a --- /dev/null +++ b/src/modules.go @@ -0,0 +1,21 @@ +package main + +import ( + // Modules + _ "github.com/odwrtw/polochon/modules/addicted" + _ "github.com/odwrtw/polochon/modules/canape" + _ "github.com/odwrtw/polochon/modules/eztv" + _ "github.com/odwrtw/polochon/modules/fsnotify" + _ "github.com/odwrtw/polochon/modules/imdb" + _ "github.com/odwrtw/polochon/modules/mock" + _ "github.com/odwrtw/polochon/modules/openguessit" + _ "github.com/odwrtw/polochon/modules/opensubtitles" + _ "github.com/odwrtw/polochon/modules/pam" + _ "github.com/odwrtw/polochon/modules/pushover" + _ "github.com/odwrtw/polochon/modules/tmdb" + _ "github.com/odwrtw/polochon/modules/trakttv" + _ "github.com/odwrtw/polochon/modules/transmission" + _ "github.com/odwrtw/polochon/modules/tvdb" + _ "github.com/odwrtw/polochon/modules/yifysubs" + _ "github.com/odwrtw/polochon/modules/yts" +)