Get the movie poster with a get details
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5b68ddb098
commit
2f0497ebc6
@ -49,7 +49,11 @@ func run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
backend := &models.Backend{Database: db}
|
||||
backend := &models.Backend{
|
||||
Database: db,
|
||||
PublicDir: cf.PublicDir,
|
||||
ImgURLPrefix: cf.ImgURLPrefix,
|
||||
}
|
||||
|
||||
// Generate auth params
|
||||
authParams := auth.Params{
|
||||
|
@ -7,8 +7,10 @@ import (
|
||||
|
||||
// Backend represents the data backend
|
||||
type Backend struct {
|
||||
Database *sqlx.DB
|
||||
configured bool
|
||||
Database *sqlx.DB
|
||||
PublicDir string
|
||||
ImgURLPrefix string
|
||||
configured bool
|
||||
}
|
||||
|
||||
// Name implements the Module interface
|
||||
|
@ -2,6 +2,9 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
polochon "github.com/odwrtw/polochon/lib"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -28,6 +31,15 @@ func (b *Backend) GetMovieDetails(pMovie *polochon.Movie, log *logrus.Entry) err
|
||||
return err
|
||||
}
|
||||
|
||||
// Add the movie images
|
||||
imgURL := fmt.Sprintf("movies/%s.jpg", pMovie.ImdbID)
|
||||
imgFile := filepath.Join(b.PublicDir, "img", imgURL)
|
||||
posterURL := ""
|
||||
if _, err := os.Stat(imgFile); !os.IsNotExist(err) {
|
||||
posterURL = b.ImgURLPrefix + imgURL
|
||||
}
|
||||
pMovie.Thumb = posterURL
|
||||
|
||||
log.Debugf("got movie %s from backend", pMovie.ImdbID)
|
||||
|
||||
return nil
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@ -43,8 +42,9 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
|
||||
VideoCodec string `json:"video_codec"`
|
||||
Container string `json:"container"`
|
||||
}{
|
||||
Alias: (*Alias)(m),
|
||||
PosterURL: m.PosterURL(),
|
||||
Alias: (*Alias)(m),
|
||||
// TODO: remove this field to use m.Thumb
|
||||
PosterURL: m.Thumb,
|
||||
Subtitles: []subtitles.Subtitle{},
|
||||
}
|
||||
|
||||
@ -244,15 +244,6 @@ func (m *Movie) imgFile() string {
|
||||
return filepath.Join(m.publicDir, "img", m.imgURL())
|
||||
}
|
||||
|
||||
// PosterURL returns the image URL or the default image if the poster is not yet downloaded
|
||||
func (m *Movie) PosterURL() string {
|
||||
// Check if the movie image exists
|
||||
if _, err := os.Stat(m.imgFile()); os.IsNotExist(err) {
|
||||
return ""
|
||||
}
|
||||
return m.imgURLPrefix + m.imgURL()
|
||||
}
|
||||
|
||||
// getPolochonMovies returns an array of the user's polochon movies
|
||||
func getPolochonMovies(user *models.User, env *web.Env) ([]*Movie, error) {
|
||||
movies := []*Movie{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user