mirror of
https://github.com/stashapp/stash.git
synced 2026-04-26 00:41:40 +02:00
* Move main to cmd * Move api to internal * Move logger and manager to internal * Move shell hiding code to separate package * Decouple job from desktop and utils * Decouple session from config * Move static into internal * Decouple config from dlna * Move desktop to internal * Move dlna to internal * Decouple remaining packages from config * Move config into internal * Move jsonschema and paths to models * Make ffmpeg functions private * Move file utility methods into fsutil package * Move symwalk into fsutil * Move single-use util functions into client package * Move slice functions to separate packages * Add env var to suppress windowsgui arg * Move hash functions into separate package * Move identify to internal * Move autotag to internal * Touch UI when generating backend
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package movie
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
"github.com/stashapp/stash/pkg/models/jsonschema"
|
|
"github.com/stashapp/stash/pkg/utils"
|
|
)
|
|
|
|
// ToJSON converts a Movie into its JSON equivalent.
|
|
func ToJSON(reader models.MovieReader, studioReader models.StudioReader, movie *models.Movie) (*jsonschema.Movie, error) {
|
|
newMovieJSON := jsonschema.Movie{
|
|
CreatedAt: models.JSONTime{Time: movie.CreatedAt.Timestamp},
|
|
UpdatedAt: models.JSONTime{Time: movie.UpdatedAt.Timestamp},
|
|
}
|
|
|
|
if movie.Name.Valid {
|
|
newMovieJSON.Name = movie.Name.String
|
|
}
|
|
if movie.Aliases.Valid {
|
|
newMovieJSON.Aliases = movie.Aliases.String
|
|
}
|
|
if movie.Date.Valid {
|
|
newMovieJSON.Date = utils.GetYMDFromDatabaseDate(movie.Date.String)
|
|
}
|
|
if movie.Rating.Valid {
|
|
newMovieJSON.Rating = int(movie.Rating.Int64)
|
|
}
|
|
if movie.Duration.Valid {
|
|
newMovieJSON.Duration = int(movie.Duration.Int64)
|
|
}
|
|
|
|
if movie.Director.Valid {
|
|
newMovieJSON.Director = movie.Director.String
|
|
}
|
|
|
|
if movie.Synopsis.Valid {
|
|
newMovieJSON.Synopsis = movie.Synopsis.String
|
|
}
|
|
|
|
if movie.URL.Valid {
|
|
newMovieJSON.URL = movie.URL.String
|
|
}
|
|
|
|
if movie.StudioID.Valid {
|
|
studio, err := studioReader.Find(int(movie.StudioID.Int64))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error getting movie studio: %v", err)
|
|
}
|
|
|
|
if studio != nil {
|
|
newMovieJSON.Studio = studio.Name.String
|
|
}
|
|
}
|
|
|
|
frontImage, err := reader.GetFrontImage(movie.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error getting movie front image: %v", err)
|
|
}
|
|
|
|
if len(frontImage) > 0 {
|
|
newMovieJSON.FrontImage = utils.GetBase64StringFromData(frontImage)
|
|
}
|
|
|
|
backImage, err := reader.GetBackImage(movie.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error getting movie back image: %v", err)
|
|
}
|
|
|
|
if len(backImage) > 0 {
|
|
newMovieJSON.BackImage = utils.GetBase64StringFromData(backImage)
|
|
}
|
|
|
|
return &newMovieJSON, nil
|
|
}
|