2020-03-10 03:28:15 +00:00
|
|
|
package jsonschema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2020-06-22 23:19:19 +00:00
|
|
|
jsoniter "github.com/json-iterator/go"
|
2020-03-10 03:28:15 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Movie struct {
|
2020-04-22 01:22:14 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Aliases string `json:"aliases,omitempty"`
|
|
|
|
Duration int `json:"duration,omitempty"`
|
|
|
|
Date string `json:"date,omitempty"`
|
|
|
|
Rating int `json:"rating,omitempty"`
|
|
|
|
Director string `json:"director,omitempty"`
|
|
|
|
Synopsis string `json:"sypnopsis,omitempty"`
|
|
|
|
FrontImage string `json:"front_image,omitempty"`
|
|
|
|
BackImage string `json:"back_image,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
2020-06-22 23:19:19 +00:00
|
|
|
Studio string `json:"studio,omitempty"`
|
2020-04-22 01:22:14 +00:00
|
|
|
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
2020-03-10 03:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadMovieFile(filePath string) (*Movie, error) {
|
|
|
|
var movie Movie
|
|
|
|
file, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-24 21:52:55 +00:00
|
|
|
defer file.Close()
|
2020-04-24 02:52:21 +00:00
|
|
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
2020-03-10 03:28:15 +00:00
|
|
|
jsonParser := json.NewDecoder(file)
|
|
|
|
err = jsonParser.Decode(&movie)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &movie, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveMovieFile(filePath string, movie *Movie) error {
|
|
|
|
if movie == nil {
|
|
|
|
return fmt.Errorf("movie must not be nil")
|
|
|
|
}
|
|
|
|
return marshalToFile(filePath, movie)
|
|
|
|
}
|