Merge branch 'configPolochon' into 'master'

Use polochon config to initialize modules

See merge request !52
This commit is contained in:
Grégoire Delattre 2017-04-07 21:28:03 +00:00
commit 6db5b15ea5
4 changed files with 78 additions and 99 deletions

View File

@ -3,7 +3,33 @@ authorizer:
pepper: pepper pepper: pepper
cost: 10 cost: 10
pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable 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 listen_port: 3000
public_dir: build/public 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

View File

@ -4,12 +4,9 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/Sirupsen/logrus"
polochon "github.com/odwrtw/polochon/lib" polochon "github.com/odwrtw/polochon/lib"
"github.com/odwrtw/polochon/modules/eztv" polochonConfig "github.com/odwrtw/polochon/lib/configuration"
"github.com/odwrtw/polochon/modules/tmdb"
"github.com/odwrtw/polochon/modules/trakttv"
"github.com/odwrtw/polochon/modules/tvdb"
"github.com/odwrtw/polochon/modules/yts"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -19,15 +16,13 @@ type Config struct {
Authorizer AuthorizerConfig `yaml:"authorizer"` Authorizer AuthorizerConfig `yaml:"authorizer"`
PGDSN string `yaml:"pgdsn"` PGDSN string `yaml:"pgdsn"`
Port string `yaml:"listen_port"` Port string `yaml:"listen_port"`
TraktTVClientID string `yaml:"trakttv_client_id"`
PublicDir string `yaml:"public_dir"` PublicDir string `yaml:"public_dir"`
// TODO improve the detailers and torrenters configurations
TmdbAPIKey string `yaml:"tmdb_api_key"`
MovieExplorers []polochon.Explorer MovieExplorers []polochon.Explorer
MovieDetailers []polochon.Detailer MovieDetailers []polochon.Detailer
MovieTorrenters []polochon.Torrenter MovieTorrenters []polochon.Torrenter
MovieSearchers []polochon.Searcher MovieSearchers []polochon.Searcher
ShowExplorers []polochon.Explorer ShowExplorers []polochon.Explorer
ShowDetailers []polochon.Detailer ShowDetailers []polochon.Detailer
ShowTorrenters []polochon.Torrenter ShowTorrenters []polochon.Torrenter
@ -42,7 +37,7 @@ type AuthorizerConfig struct {
} }
// Load loads a config file from a path and return a Config object // 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 // Open the file
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
@ -51,6 +46,7 @@ func Load(path string) (*Config, error) {
defer file.Close() defer file.Close()
cf := &Config{} cf := &Config{}
polochonCf := &polochonConfig.ConfigFileRoot{}
// Read it // Read it
b, err := ioutil.ReadAll(file) b, err := ioutil.ReadAll(file)
@ -58,101 +54,37 @@ func Load(path string) (*Config, error) {
return nil, err return nil, err
} }
// Unmarshal its content // Unmarshal its content into the Config obj
err = yaml.Unmarshal(b, cf) err = yaml.Unmarshal(b, cf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Initialize the default values // Unmarshal its content into the polochon.ConfigFileRoot obj
err = yaml.Unmarshal(b, polochonCf)
// Default movie detailers
cf.MovieDetailers = []polochon.Detailer{}
if cf.TmdbAPIKey != "" {
d, err := tmdb.New(
&tmdb.Params{
ApiKey: cf.TmdbAPIKey,
},
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
cf.MovieDetailers = append(cf.MovieDetailers, d)
}
// Default movie explorers // Init all the show torrenters / detailers / searchers / explorers
cf.MovieExplorers = []polochon.Explorer{} showConf, err := polochonCf.InitShow(log)
ytsExp, err := yts.NewExplorer()
if err != nil { if err != nil {
return nil, err return nil, err
} }
cf.MovieExplorers = append(cf.MovieExplorers, ytsExp) cf.ShowTorrenters = showConf.Torrenters
if cf.TraktTVClientID != "" { cf.ShowDetailers = showConf.Detailers
traktExp, err := trakttv.NewExplorer(&trakttv.Params{ cf.ShowSearchers = showConf.Searchers
ClientID: cf.TraktTVClientID, cf.ShowExplorers = showConf.Explorers
})
if err != nil {
return nil, err
}
cf.MovieExplorers = append(cf.MovieExplorers, traktExp)
}
// Default movie torrenters // Init all the movie torrenters / detailers / searchers / explorers
cf.MovieTorrenters = []polochon.Torrenter{} movieConf, err := polochonCf.InitMovie(log)
d, err := yts.New()
if err != nil { if err != nil {
return nil, err return nil, err
} }
cf.MovieTorrenters = append(cf.MovieTorrenters, d) cf.MovieTorrenters = movieConf.Torrenters
cf.MovieDetailers = movieConf.Detailers
// Default movie searchers cf.MovieSearchers = movieConf.Searchers
cf.MovieSearchers = []polochon.Searcher{} cf.MovieExplorers = movieConf.Explorers
movieSearcher, err := yts.NewSearcher()
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)
return cf, nil return cf, nil
} }

View File

@ -31,7 +31,7 @@ func main() {
logger.Level = logrus.DebugLevel logger.Level = logrus.DebugLevel
log := logrus.NewEntry(logger) log := logrus.NewEntry(logger)
cf, err := config.Load(cfgPath) cf, err := config.Load(cfgPath, log)
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }

21
src/modules.go Normal file
View File

@ -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"
)