Add the polochon URL in every movie
This commit is contained in:
parent
f34813f3a5
commit
e1a11e5ff9
@ -5,8 +5,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/auth"
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/movies"
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/shows"
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/users"
|
||||
|
||||
"gitlab.quimbo.fr/odwrtw/canape-sql/src/internal/web"
|
||||
|
||||
@ -89,12 +91,19 @@ func GetMediaIDs(env *web.Env, mediaType string, source string, category string,
|
||||
}
|
||||
|
||||
// GetMovies get some movies
|
||||
func GetMovies(env *web.Env, source string, category string, force bool) ([]*movies.Movie, error) {
|
||||
func GetMovies(env *web.Env, user *users.User, source string, category string, force bool) ([]*movies.Movie, error) {
|
||||
movieIds, err := GetMediaIDs(env, "movie", source, category, force)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get the URLs from polochon, we don't really care if it fails for now
|
||||
var urls map[string]string
|
||||
urls, err = movies.GetPolochonMoviesURLs(user)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting polochon movies url: %s", err)
|
||||
}
|
||||
|
||||
movieList := []*movies.Movie{}
|
||||
for _, id := range movieIds {
|
||||
movie := movies.New(id)
|
||||
@ -108,6 +117,13 @@ func GetMovies(env *web.Env, source string, category string, force bool) ([]*mov
|
||||
env.Log.Errorf("error while getting movie torrents : %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if urls != nil {
|
||||
if url, ok := urls[id]; ok {
|
||||
movie.PolochonURL = url
|
||||
}
|
||||
}
|
||||
|
||||
movieList = append(movieList, movie)
|
||||
}
|
||||
return movieList, nil
|
||||
@ -157,8 +173,14 @@ func Explore(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
category = "popular"
|
||||
}
|
||||
|
||||
v := auth.GetCurrentUser(r, env.Log)
|
||||
user, ok := v.(*users.User)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid user type")
|
||||
}
|
||||
|
||||
// Get the medias without trying to refresh them
|
||||
movies, err := GetMovies(env, source, category, false)
|
||||
movies, err := GetMovies(env, user, source, category, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -218,11 +240,17 @@ func Refresh(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
category = "popular"
|
||||
}
|
||||
|
||||
v := auth.GetCurrentUser(r, env.Log)
|
||||
user, ok := v.(*users.User)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid user type")
|
||||
}
|
||||
|
||||
// We'll refresh the medias for each sources
|
||||
for _, source := range MediaSources {
|
||||
env.Log.Debugf("refreshing %s", source)
|
||||
// GetMedias and refresh them
|
||||
_, err := GetMovies(env, source, category, true)
|
||||
_, err := GetMovies(env, user, source, category, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -64,6 +64,21 @@ func getPolochonMovies(user *users.User) ([]*Movie, error) {
|
||||
return movies, nil
|
||||
}
|
||||
|
||||
// GetPolochonMoviesURLs returns the polochon urls associated with an imdb id
|
||||
func GetPolochonMoviesURLs(user *users.User) (map[string]string, error) {
|
||||
movies, err := getPolochonMovies(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
urls := make(map[string]string, len(movies))
|
||||
for _, movie := range movies {
|
||||
urls[movie.ImdbID] = movie.PolochonURL
|
||||
}
|
||||
|
||||
return urls, nil
|
||||
}
|
||||
|
||||
// FromPolochon will returns movies from Polochon
|
||||
func FromPolochon(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
v := auth.GetCurrentUser(r, env.Log)
|
||||
@ -117,7 +132,8 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
var data struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
err := json.NewDecoder(r.Body).Decode(&data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -125,6 +141,12 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
return env.RenderError(w, errors.New("no given key"))
|
||||
}
|
||||
|
||||
v := auth.GetCurrentUser(r, env.Log)
|
||||
user, ok := v.(*users.User)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid user type")
|
||||
}
|
||||
|
||||
var movies []*polochon.Movie
|
||||
searchers := env.Config.MovieSearchers
|
||||
for _, searcher := range searchers {
|
||||
@ -136,6 +158,13 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
movies = append(movies, result...)
|
||||
}
|
||||
|
||||
// Get the URLs from polochon, we don't really care if it fails for now
|
||||
var urls map[string]string
|
||||
urls, err = GetPolochonMoviesURLs(user)
|
||||
if err != nil {
|
||||
env.Log.Errorf("error while getting polochon movies url: %s", err)
|
||||
}
|
||||
|
||||
env.Log.Debugf("got %d movies doing search %q", len(movies), data.Key)
|
||||
movieList := []*Movie{}
|
||||
for _, m := range movies {
|
||||
@ -150,6 +179,13 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
env.Log.Errorf("error while getting movie torrents : %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if urls != nil {
|
||||
if url, ok := urls[m.ImdbID]; ok {
|
||||
movie.PolochonURL = url
|
||||
}
|
||||
}
|
||||
|
||||
movieList = append(movieList, movie)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user