2019-02-09 12:30:49 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2019-12-01 16:18:44 +00:00
|
|
|
"path/filepath"
|
2021-10-28 03:25:17 +00:00
|
|
|
"strconv"
|
2021-10-14 23:39:48 +00:00
|
|
|
"time"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// Scene stores the metadata for a single video scene.
|
2019-02-09 12:30:49 +00:00
|
|
|
type Scene struct {
|
2021-12-13 02:41:07 +00:00
|
|
|
ID int `db:"id" json:"id"`
|
|
|
|
Checksum sql.NullString `db:"checksum" json:"checksum"`
|
|
|
|
OSHash sql.NullString `db:"oshash" json:"oshash"`
|
|
|
|
Path string `db:"path" json:"path"`
|
|
|
|
Title sql.NullString `db:"title" json:"title"`
|
|
|
|
Details sql.NullString `db:"details" json:"details"`
|
|
|
|
URL sql.NullString `db:"url" json:"url"`
|
|
|
|
Date SQLiteDate `db:"date" json:"date"`
|
|
|
|
Rating sql.NullInt64 `db:"rating" json:"rating"`
|
|
|
|
Organized bool `db:"organized" json:"organized"`
|
|
|
|
OCounter int `db:"o_counter" json:"o_counter"`
|
|
|
|
Size sql.NullString `db:"size" json:"size"`
|
|
|
|
Duration sql.NullFloat64 `db:"duration" json:"duration"`
|
|
|
|
VideoCodec sql.NullString `db:"video_codec" json:"video_codec"`
|
|
|
|
Format sql.NullString `db:"format" json:"format_name"`
|
|
|
|
AudioCodec sql.NullString `db:"audio_codec" json:"audio_codec"`
|
|
|
|
Width sql.NullInt64 `db:"width" json:"width"`
|
|
|
|
Height sql.NullInt64 `db:"height" json:"height"`
|
|
|
|
Framerate sql.NullFloat64 `db:"framerate" json:"framerate"`
|
|
|
|
Bitrate sql.NullInt64 `db:"bitrate" json:"bitrate"`
|
|
|
|
StudioID sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
|
|
|
FileModTime NullSQLiteTimestamp `db:"file_mod_time" json:"file_mod_time"`
|
|
|
|
Phash sql.NullInt64 `db:"phash,omitempty" json:"phash"`
|
|
|
|
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
|
|
|
Interactive bool `db:"interactive" json:"interactive"`
|
|
|
|
InteractiveSpeed sql.NullInt64 `db:"interactive_speed" json:"interactive_speed"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
2019-10-14 21:57:53 +00:00
|
|
|
|
2021-10-14 23:39:48 +00:00
|
|
|
func (s *Scene) File() File {
|
|
|
|
ret := File{
|
|
|
|
Path: s.Path,
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.Checksum.Valid {
|
|
|
|
ret.Checksum = s.Checksum.String
|
|
|
|
}
|
|
|
|
if s.OSHash.Valid {
|
|
|
|
ret.OSHash = s.OSHash.String
|
|
|
|
}
|
|
|
|
if s.FileModTime.Valid {
|
|
|
|
ret.FileModTime = s.FileModTime.Timestamp
|
|
|
|
}
|
|
|
|
if s.Size.Valid {
|
|
|
|
ret.Size = s.Size.String
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scene) SetFile(f File) {
|
|
|
|
path := f.Path
|
|
|
|
s.Path = path
|
|
|
|
|
|
|
|
if f.Checksum != "" {
|
|
|
|
s.Checksum = sql.NullString{
|
|
|
|
String: f.Checksum,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.OSHash != "" {
|
|
|
|
s.OSHash = sql.NullString{
|
|
|
|
String: f.OSHash,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zeroTime := time.Time{}
|
|
|
|
if f.FileModTime != zeroTime {
|
|
|
|
s.FileModTime = NullSQLiteTimestamp{
|
|
|
|
Timestamp: f.FileModTime,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.Size != "" {
|
|
|
|
s.Size = sql.NullString{
|
|
|
|
String: f.Size,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// ScenePartial represents part of a Scene object. It is used to update
|
|
|
|
// the database entry. Only non-nil fields will be updated.
|
2019-10-14 21:57:53 +00:00
|
|
|
type ScenePartial struct {
|
2021-12-13 02:41:07 +00:00
|
|
|
ID int `db:"id" json:"id"`
|
|
|
|
Checksum *sql.NullString `db:"checksum" json:"checksum"`
|
|
|
|
OSHash *sql.NullString `db:"oshash" json:"oshash"`
|
|
|
|
Path *string `db:"path" json:"path"`
|
|
|
|
Title *sql.NullString `db:"title" json:"title"`
|
|
|
|
Details *sql.NullString `db:"details" json:"details"`
|
|
|
|
URL *sql.NullString `db:"url" json:"url"`
|
|
|
|
Date *SQLiteDate `db:"date" json:"date"`
|
|
|
|
Rating *sql.NullInt64 `db:"rating" json:"rating"`
|
|
|
|
Organized *bool `db:"organized" json:"organized"`
|
|
|
|
Size *sql.NullString `db:"size" json:"size"`
|
|
|
|
Duration *sql.NullFloat64 `db:"duration" json:"duration"`
|
|
|
|
VideoCodec *sql.NullString `db:"video_codec" json:"video_codec"`
|
|
|
|
Format *sql.NullString `db:"format" json:"format_name"`
|
|
|
|
AudioCodec *sql.NullString `db:"audio_codec" json:"audio_codec"`
|
|
|
|
Width *sql.NullInt64 `db:"width" json:"width"`
|
|
|
|
Height *sql.NullInt64 `db:"height" json:"height"`
|
|
|
|
Framerate *sql.NullFloat64 `db:"framerate" json:"framerate"`
|
|
|
|
Bitrate *sql.NullInt64 `db:"bitrate" json:"bitrate"`
|
|
|
|
StudioID *sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
|
|
|
MovieID *sql.NullInt64 `db:"movie_id,omitempty" json:"movie_id"`
|
|
|
|
FileModTime *NullSQLiteTimestamp `db:"file_mod_time" json:"file_mod_time"`
|
|
|
|
Phash *sql.NullInt64 `db:"phash,omitempty" json:"phash"`
|
|
|
|
CreatedAt *SQLiteTimestamp `db:"created_at" json:"created_at"`
|
|
|
|
UpdatedAt *SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
|
|
|
Interactive *bool `db:"interactive" json:"interactive"`
|
|
|
|
InteractiveSpeed *sql.NullInt64 `db:"interactive_speed" json:"interactive_speed"`
|
2019-10-14 21:57:53 +00:00
|
|
|
}
|
2019-12-01 16:18:44 +00:00
|
|
|
|
2022-04-25 05:55:05 +00:00
|
|
|
type SceneMovieInput struct {
|
|
|
|
MovieID string `json:"movie_id"`
|
|
|
|
SceneIndex *int `json:"scene_index"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SceneUpdateInput struct {
|
|
|
|
ClientMutationID *string `json:"clientMutationId"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
Title *string `json:"title"`
|
|
|
|
Details *string `json:"details"`
|
|
|
|
URL *string `json:"url"`
|
|
|
|
Date *string `json:"date"`
|
|
|
|
Rating *int `json:"rating"`
|
|
|
|
Organized *bool `json:"organized"`
|
|
|
|
StudioID *string `json:"studio_id"`
|
|
|
|
GalleryIds []string `json:"gallery_ids"`
|
|
|
|
PerformerIds []string `json:"performer_ids"`
|
|
|
|
Movies []*SceneMovieInput `json:"movies"`
|
|
|
|
TagIds []string `json:"tag_ids"`
|
|
|
|
// This should be a URL or a base64 encoded data URL
|
|
|
|
CoverImage *string `json:"cover_image"`
|
|
|
|
StashIds []*StashIDInput `json:"stash_ids"`
|
|
|
|
}
|
|
|
|
|
2021-10-28 03:25:17 +00:00
|
|
|
// UpdateInput constructs a SceneUpdateInput using the populated fields in the ScenePartial object.
|
|
|
|
func (s ScenePartial) UpdateInput() SceneUpdateInput {
|
|
|
|
boolPtrCopy := func(v *bool) *bool {
|
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
vv := *v
|
|
|
|
return &vv
|
|
|
|
}
|
|
|
|
|
|
|
|
return SceneUpdateInput{
|
|
|
|
ID: strconv.Itoa(s.ID),
|
|
|
|
Title: nullStringPtrToStringPtr(s.Title),
|
|
|
|
Details: nullStringPtrToStringPtr(s.Details),
|
|
|
|
URL: nullStringPtrToStringPtr(s.URL),
|
|
|
|
Date: s.Date.StringPtr(),
|
|
|
|
Rating: nullInt64PtrToIntPtr(s.Rating),
|
|
|
|
Organized: boolPtrCopy(s.Organized),
|
|
|
|
StudioID: nullInt64PtrToStringPtr(s.StudioID),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 23:39:48 +00:00
|
|
|
func (s *ScenePartial) SetFile(f File) {
|
|
|
|
path := f.Path
|
|
|
|
s.Path = &path
|
|
|
|
|
|
|
|
if f.Checksum != "" {
|
|
|
|
s.Checksum = &sql.NullString{
|
|
|
|
String: f.Checksum,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.OSHash != "" {
|
|
|
|
s.OSHash = &sql.NullString{
|
|
|
|
String: f.OSHash,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zeroTime := time.Time{}
|
|
|
|
if f.FileModTime != zeroTime {
|
|
|
|
s.FileModTime = &NullSQLiteTimestamp{
|
|
|
|
Timestamp: f.FileModTime,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.Size != "" {
|
|
|
|
s.Size = &sql.NullString{
|
|
|
|
String: f.Size,
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// GetTitle returns the title of the scene. If the Title field is empty,
|
|
|
|
// then the base filename is returned.
|
2019-12-01 16:18:44 +00:00
|
|
|
func (s Scene) GetTitle() string {
|
|
|
|
if s.Title.String != "" {
|
|
|
|
return s.Title.String
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Base(s.Path)
|
|
|
|
}
|
2019-12-21 00:13:23 +00:00
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// GetHash returns the hash of the scene, based on the hash algorithm provided. If
|
|
|
|
// hash algorithm is MD5, then Checksum is returned. Otherwise, OSHash is returned.
|
|
|
|
func (s Scene) GetHash(hashAlgorithm HashAlgorithm) string {
|
2021-10-14 23:39:48 +00:00
|
|
|
return s.File().GetHash(hashAlgorithm)
|
2020-08-06 01:21:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 01:51:42 +00:00
|
|
|
func (s Scene) GetMinResolution() int64 {
|
|
|
|
if s.Width.Int64 < s.Height.Int64 {
|
|
|
|
return s.Width.Int64
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.Height.Int64
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// SceneFileType represents the file metadata for a scene.
|
2019-12-21 00:13:23 +00:00
|
|
|
type SceneFileType struct {
|
|
|
|
Size *string `graphql:"size" json:"size"`
|
|
|
|
Duration *float64 `graphql:"duration" json:"duration"`
|
|
|
|
VideoCodec *string `graphql:"video_codec" json:"video_codec"`
|
|
|
|
AudioCodec *string `graphql:"audio_codec" json:"audio_codec"`
|
|
|
|
Width *int `graphql:"width" json:"width"`
|
|
|
|
Height *int `graphql:"height" json:"height"`
|
|
|
|
Framerate *float64 `graphql:"framerate" json:"framerate"`
|
|
|
|
Bitrate *int `graphql:"bitrate" json:"bitrate"`
|
|
|
|
}
|
2021-01-18 01:23:20 +00:00
|
|
|
|
|
|
|
type Scenes []*Scene
|
|
|
|
|
|
|
|
func (s *Scenes) Append(o interface{}) {
|
|
|
|
*s = append(*s, o.(*Scene))
|
|
|
|
}
|
|
|
|
|
2021-01-21 11:02:09 +00:00
|
|
|
func (s *Scenes) New() interface{} {
|
2021-01-18 01:23:20 +00:00
|
|
|
return &Scene{}
|
|
|
|
}
|
2022-05-06 01:59:28 +00:00
|
|
|
|
|
|
|
type SceneCaption struct {
|
|
|
|
LanguageCode string `json:"language_code"`
|
|
|
|
Filename string `json:"filename"`
|
|
|
|
CaptionType string `json:"caption_type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c SceneCaption) Path(scenePath string) string {
|
|
|
|
return filepath.Join(filepath.Dir(scenePath), c.Filename)
|
|
|
|
}
|