2019-02-09 12:30:49 +00:00
|
|
|
package jsonschema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-03-10 03:28:15 +00:00
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
jsoniter "github.com/json-iterator/go"
|
2020-03-10 03:28:15 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SceneMarker struct {
|
2019-03-27 19:53:15 +00:00
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
Seconds string `json:"seconds,omitempty"`
|
|
|
|
PrimaryTag string `json:"primary_tag,omitempty"`
|
|
|
|
Tags []string `json:"tags,omitempty"`
|
|
|
|
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SceneFile struct {
|
2020-11-04 23:26:51 +00:00
|
|
|
ModTime models.JSONTime `json:"mod_time,omitempty"`
|
|
|
|
Size string `json:"size"`
|
|
|
|
Duration string `json:"duration"`
|
|
|
|
VideoCodec string `json:"video_codec"`
|
|
|
|
AudioCodec string `json:"audio_codec"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Framerate string `json:"framerate"`
|
|
|
|
Bitrate int `json:"bitrate"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 03:28:15 +00:00
|
|
|
type SceneMovie struct {
|
|
|
|
MovieName string `json:"movieName,omitempty"`
|
2020-04-22 01:22:14 +00:00
|
|
|
SceneIndex int `json:"scene_index,omitempty"`
|
2020-03-10 03:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 12:30:49 +00:00
|
|
|
type Scene struct {
|
2019-03-27 19:53:15 +00:00
|
|
|
Title string `json:"title,omitempty"`
|
2020-08-06 01:21:14 +00:00
|
|
|
Checksum string `json:"checksum,omitempty"`
|
|
|
|
OSHash string `json:"oshash,omitempty"`
|
2019-03-27 19:53:15 +00:00
|
|
|
Studio string `json:"studio,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Date string `json:"date,omitempty"`
|
|
|
|
Rating int `json:"rating,omitempty"`
|
2020-12-17 21:06:49 +00:00
|
|
|
Organized bool `json:"organized,omitempty"`
|
2020-04-22 23:14:58 +00:00
|
|
|
OCounter int `json:"o_counter,omitempty"`
|
2019-03-27 19:53:15 +00:00
|
|
|
Details string `json:"details,omitempty"`
|
2021-02-01 20:56:54 +00:00
|
|
|
Galleries []string `json:"galleries,omitempty"`
|
2019-03-27 19:53:15 +00:00
|
|
|
Performers []string `json:"performers,omitempty"`
|
2020-03-10 03:28:15 +00:00
|
|
|
Movies []SceneMovie `json:"movies,omitempty"`
|
2019-03-27 19:53:15 +00:00
|
|
|
Tags []string `json:"tags,omitempty"`
|
|
|
|
Markers []SceneMarker `json:"markers,omitempty"`
|
|
|
|
File *SceneFile `json:"file,omitempty"`
|
2019-12-31 22:38:49 +00:00
|
|
|
Cover string `json:"cover,omitempty"`
|
2019-03-27 19:53:15 +00:00
|
|
|
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadSceneFile(filePath string) (*Scene, error) {
|
|
|
|
var scene Scene
|
|
|
|
file, err := os.Open(filePath)
|
|
|
|
defer file.Close()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-24 02:52:21 +00:00
|
|
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
2019-02-09 12:30:49 +00:00
|
|
|
jsonParser := json.NewDecoder(file)
|
|
|
|
err = jsonParser.Decode(&scene)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &scene, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveSceneFile(filePath string, scene *Scene) error {
|
|
|
|
if scene == nil {
|
|
|
|
return fmt.Errorf("scene must not be nil")
|
|
|
|
}
|
|
|
|
return marshalToFile(filePath, scene)
|
|
|
|
}
|