mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
* Refactor transcode generation * Move phash generation into separate package * Refactor image thumbnail generation * Move JSONTime to separate package * Ffmpeg refactoring * Refactor live transcoding * Refactor scene marker preview generation * Refactor preview generation * Refactor screenshot generation * Refactor sprite generation * Change ffmpeg.IsStreamable to return error * Move frame rate calculation into ffmpeg * Refactor file locking * Refactor title set during scan * Add missing lockmanager instance * Return error instead of logging in MatchContainer
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package movie
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
"github.com/stashapp/stash/pkg/models/json"
|
|
"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: json.JSONTime{Time: movie.CreatedAt.Timestamp},
|
|
UpdatedAt: json.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
|
|
}
|