Update the new movie function

This commit is contained in:
Grégoire Delattre 2020-04-11 10:59:45 +02:00
parent ed508bbf3b
commit 101e68372d
4 changed files with 11 additions and 14 deletions

View File

@ -196,7 +196,7 @@ func RefreshMovies(env *web.Env) {
// Iterate over the map of movies to refresh them
for id := range movieMap {
movie := movies.New(id, nil, nil, false, env.Config.PublicDir, env.Config.ImgURLPrefix)
movie := movies.New(env, id, nil, nil, false)
// Refresh the movie
err := movie.Refresh(env, env.Config.Movie.Detailers)
if err != nil {

View File

@ -80,7 +80,7 @@ func GetMovies(env *web.Env, user *models.User, source string, category string)
// Fill all the movies infos from the list of IDs
for _, id := range media.IDs {
pMovie, _ := pMovies.Has(id)
movie := movies.New(id, client, pMovie, moviesWishlist.IsMovieInWishlist(id), env.Config.PublicDir, env.Config.ImgURLPrefix)
movie := movies.New(env, id, client, pMovie, moviesWishlist.IsMovieInWishlist(id))
// First check in the DB
before := []polochon.Detailer{env.Backend.Detailer}
// Then with the default detailers

View File

@ -76,7 +76,7 @@ func RefreshMovieHandler(env *web.Env, w http.ResponseWriter, r *http.Request) e
}
// Create a new movie
m := New(id, client, pMovie, isWishlisted, env.Config.PublicDir, env.Config.ImgURLPrefix)
m := New(env, id, client, pMovie, isWishlisted)
// Refresh the movie's infos
if err := m.Refresh(env, env.Config.Movie.Detailers); err != nil {
@ -141,12 +141,11 @@ func SearchMovie(env *web.Env, w http.ResponseWriter, r *http.Request) error {
for _, m := range movies {
pMovie, _ := pMovies.Has(m.ImdbID)
movie := New(
env,
m.ImdbID,
client,
pMovie,
moviesWishlist.IsMovieInWishlist(m.ImdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
)
// First check in the DB
@ -252,12 +251,11 @@ func GetWishlistHandler(env *web.Env, w http.ResponseWriter, r *http.Request) er
for _, imdbID := range moviesWishlist.List() {
pMovie, _ := pMovies.Has(imdbID)
movie := New(
env,
imdbID,
client,
pMovie,
moviesWishlist.IsMovieInWishlist(imdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
)
// First check in the DB
before := []polochon.Detailer{env.Backend.Detailer}

View File

@ -74,12 +74,12 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
}
// New returns a new Movie with all the needed infos
func New(imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool, publicDir, imgURLPrefix string) *Movie {
func New(env *web.Env, imdbID string, client *papi.Client, pMovie *papi.Movie, isWishlisted bool) *Movie {
return &Movie{
client: client,
pMovie: pMovie,
publicDir: publicDir,
imgURLPrefix: imgURLPrefix,
publicDir: env.Config.PublicDir,
imgURLPrefix: env.Config.ImgURLPrefix,
Wishlisted: isWishlisted,
Movie: &polochon.Movie{
ImdbID: imdbID,
@ -115,7 +115,7 @@ func (m *Movie) GetDetails(env *web.Env, detailers []polochon.Detailer) error {
// If found, return
// If not, retrives details with the detailers 'after' and update them in
// database
func (m *Movie) GetAndFetch(env *web.Env, before []polochon.Detailer, after []polochon.Detailer) error {
func (m *Movie) GetAndFetch(env *web.Env, before, after []polochon.Detailer) error {
log := env.Log.WithFields(logrus.Fields{
"imdb_id": m.ImdbID,
"function": "movies.GetAndFetch",
@ -182,7 +182,7 @@ func (m *Movie) GetTorrents(env *web.Env, torrenters []polochon.Torrenter) error
// If found, return
// If not, retrives torrents with the torrenters 'after' and update them in
// database
func (m *Movie) GetAndFetchTorrents(env *web.Env, before []polochon.Torrenter, after []polochon.Torrenter) error {
func (m *Movie) GetAndFetchTorrents(env *web.Env, before, after []polochon.Torrenter) error {
log := env.Log.WithFields(logrus.Fields{
"imdb_id": m.ImdbID,
"function": "movies.GetAndFetchTorrents",
@ -278,12 +278,11 @@ func getPolochonMovies(user *models.User, env *web.Env) ([]*Movie, error) {
// Create Movies objects from the movies retrieved
for _, pmovie := range pmovies.List() {
movie := New(
env,
pmovie.ImdbID,
client,
pmovie,
moviesWishlist.IsMovieInWishlist(pmovie.ImdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
)
movies = append(movies, movie)
}