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 // Iterate over the map of movies to refresh them
for id := range movieMap { 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 // Refresh the movie
err := movie.Refresh(env, env.Config.Movie.Detailers) err := movie.Refresh(env, env.Config.Movie.Detailers)
if err != nil { 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 // Fill all the movies infos from the list of IDs
for _, id := range media.IDs { for _, id := range media.IDs {
pMovie, _ := pMovies.Has(id) 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 // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} before := []polochon.Detailer{env.Backend.Detailer}
// Then with the default detailers // 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 // 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 // Refresh the movie's infos
if err := m.Refresh(env, env.Config.Movie.Detailers); err != nil { 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 { for _, m := range movies {
pMovie, _ := pMovies.Has(m.ImdbID) pMovie, _ := pMovies.Has(m.ImdbID)
movie := New( movie := New(
env,
m.ImdbID, m.ImdbID,
client, client,
pMovie, pMovie,
moviesWishlist.IsMovieInWishlist(m.ImdbID), moviesWishlist.IsMovieInWishlist(m.ImdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
// First check in the DB // 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() { for _, imdbID := range moviesWishlist.List() {
pMovie, _ := pMovies.Has(imdbID) pMovie, _ := pMovies.Has(imdbID)
movie := New( movie := New(
env,
imdbID, imdbID,
client, client,
pMovie, pMovie,
moviesWishlist.IsMovieInWishlist(imdbID), moviesWishlist.IsMovieInWishlist(imdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
// First check in the DB // First check in the DB
before := []polochon.Detailer{env.Backend.Detailer} 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 // 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{ return &Movie{
client: client, client: client,
pMovie: pMovie, pMovie: pMovie,
publicDir: publicDir, publicDir: env.Config.PublicDir,
imgURLPrefix: imgURLPrefix, imgURLPrefix: env.Config.ImgURLPrefix,
Wishlisted: isWishlisted, Wishlisted: isWishlisted,
Movie: &polochon.Movie{ Movie: &polochon.Movie{
ImdbID: imdbID, ImdbID: imdbID,
@ -115,7 +115,7 @@ func (m *Movie) GetDetails(env *web.Env, detailers []polochon.Detailer) error {
// If found, return // If found, return
// If not, retrives details with the detailers 'after' and update them in // If not, retrives details with the detailers 'after' and update them in
// database // 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{ log := env.Log.WithFields(logrus.Fields{
"imdb_id": m.ImdbID, "imdb_id": m.ImdbID,
"function": "movies.GetAndFetch", "function": "movies.GetAndFetch",
@ -182,7 +182,7 @@ func (m *Movie) GetTorrents(env *web.Env, torrenters []polochon.Torrenter) error
// If found, return // If found, return
// If not, retrives torrents with the torrenters 'after' and update them in // If not, retrives torrents with the torrenters 'after' and update them in
// database // 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{ log := env.Log.WithFields(logrus.Fields{
"imdb_id": m.ImdbID, "imdb_id": m.ImdbID,
"function": "movies.GetAndFetchTorrents", "function": "movies.GetAndFetchTorrents",
@ -278,12 +278,11 @@ func getPolochonMovies(user *models.User, env *web.Env) ([]*Movie, error) {
// Create Movies objects from the movies retrieved // Create Movies objects from the movies retrieved
for _, pmovie := range pmovies.List() { for _, pmovie := range pmovies.List() {
movie := New( movie := New(
env,
pmovie.ImdbID, pmovie.ImdbID,
client, client,
pmovie, pmovie,
moviesWishlist.IsMovieInWishlist(pmovie.ImdbID), moviesWishlist.IsMovieInWishlist(pmovie.ImdbID),
env.Config.PublicDir,
env.Config.ImgURLPrefix,
) )
movies = append(movies, movie) movies = append(movies, movie)
} }