Merge branch 'showSearcher' into 'master'
Add showSearcher to the party See merge request !29
This commit is contained in:
commit
9d55743720
@ -27,6 +27,7 @@ type Config struct {
|
|||||||
MovieSearchers []polochon.Searcher
|
MovieSearchers []polochon.Searcher
|
||||||
ShowDetailers []polochon.Detailer
|
ShowDetailers []polochon.Detailer
|
||||||
ShowTorrenters []polochon.Torrenter
|
ShowTorrenters []polochon.Torrenter
|
||||||
|
ShowSearchers []polochon.Searcher
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthorizerConfig struct {
|
type AuthorizerConfig struct {
|
||||||
@ -54,7 +55,7 @@ func Load(path string) (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default detailers
|
// Default movie detailers
|
||||||
cf.MovieDetailers = []polochon.Detailer{}
|
cf.MovieDetailers = []polochon.Detailer{}
|
||||||
if cf.TmdbAPIKey != "" {
|
if cf.TmdbAPIKey != "" {
|
||||||
d, err := tmdb.New(&tmdb.Params{cf.TmdbAPIKey})
|
d, err := tmdb.New(&tmdb.Params{cf.TmdbAPIKey})
|
||||||
@ -64,7 +65,7 @@ func Load(path string) (*Config, error) {
|
|||||||
cf.MovieDetailers = append(cf.MovieDetailers, d)
|
cf.MovieDetailers = append(cf.MovieDetailers, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default torrenters
|
// Default movie torrenters
|
||||||
cf.MovieTorrenters = []polochon.Torrenter{}
|
cf.MovieTorrenters = []polochon.Torrenter{}
|
||||||
d, err := yts.New()
|
d, err := yts.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,15 +73,23 @@ func Load(path string) (*Config, error) {
|
|||||||
}
|
}
|
||||||
cf.MovieTorrenters = append(cf.MovieTorrenters, d)
|
cf.MovieTorrenters = append(cf.MovieTorrenters, d)
|
||||||
|
|
||||||
// Default searchers
|
// Default movie searchers
|
||||||
cf.MovieSearchers = []polochon.Searcher{}
|
cf.MovieSearchers = []polochon.Searcher{}
|
||||||
s, err := yts.NewSearcher()
|
movieSearcher, err := yts.NewSearcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cf.MovieSearchers = append(cf.MovieSearchers, s)
|
cf.MovieSearchers = append(cf.MovieSearchers, movieSearcher)
|
||||||
|
|
||||||
// Default detailers
|
// 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 detailers
|
||||||
cf.ShowDetailers = []polochon.Detailer{}
|
cf.ShowDetailers = []polochon.Detailer{}
|
||||||
showDetailer, err := tvdb.NewDetailer()
|
showDetailer, err := tvdb.NewDetailer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,7 +97,7 @@ func Load(path string) (*Config, error) {
|
|||||||
}
|
}
|
||||||
cf.ShowDetailers = append(cf.ShowDetailers, showDetailer)
|
cf.ShowDetailers = append(cf.ShowDetailers, showDetailer)
|
||||||
|
|
||||||
// Default torrenters
|
// Default show torrenters
|
||||||
cf.ShowTorrenters = []polochon.Torrenter{}
|
cf.ShowTorrenters = []polochon.Torrenter{}
|
||||||
showTorrenter, err := eztv.New()
|
showTorrenter, err := eztv.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package shows
|
package shows
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
polochon "github.com/odwrtw/polochon/lib"
|
||||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/web"
|
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,3 +24,36 @@ func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) err
|
|||||||
|
|
||||||
return env.RenderJSON(w, s)
|
return env.RenderJSON(w, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SearchShow will search a show
|
||||||
|
func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
key := r.FormValue("key")
|
||||||
|
if key == "" {
|
||||||
|
return env.RenderError(w, errors.New("no given key"))
|
||||||
|
}
|
||||||
|
|
||||||
|
var shows []*polochon.Show
|
||||||
|
searchers := env.Config.ShowSearchers
|
||||||
|
for _, searcher := range searchers {
|
||||||
|
result, err := searcher.SearchShow(key, env.Log)
|
||||||
|
if err != nil {
|
||||||
|
env.Log.Errorf("error while searching show : %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
shows = append(shows, result...)
|
||||||
|
}
|
||||||
|
|
||||||
|
env.Log.Debugf("got %d shows doing search %q", len(shows), key)
|
||||||
|
showList := []*Show{}
|
||||||
|
for _, s := range shows {
|
||||||
|
show := New(s.ImdbID)
|
||||||
|
err := show.GetDetails(env, false)
|
||||||
|
if err != nil {
|
||||||
|
env.Log.Errorf("error while getting show details : %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
showList = append(showList, show)
|
||||||
|
}
|
||||||
|
|
||||||
|
return env.RenderJSON(w, showList)
|
||||||
|
}
|
||||||
|
@ -86,6 +86,7 @@ func main() {
|
|||||||
env.Handle("/shows/{id:tt[0-9]+}", shows.GetDetailsHandler)
|
env.Handle("/shows/{id:tt[0-9]+}", shows.GetDetailsHandler)
|
||||||
env.Handle("/shows/refresh", extmedias.RefreshShows)
|
env.Handle("/shows/refresh", extmedias.RefreshShows)
|
||||||
env.Handle("/shows/explore", extmedias.ExploreShows)
|
env.Handle("/shows/explore", extmedias.ExploreShows)
|
||||||
|
env.Handle("/shows/search", shows.SearchShow)
|
||||||
|
|
||||||
n := negroni.Classic()
|
n := negroni.Classic()
|
||||||
n.Use(authMiddleware)
|
n.Use(authMiddleware)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user