Support file-less scenes. Add scene split, merge and reassign file (#3006)

* Reassign scene file functionality
* Implement scene create
* Add scene create UI
* Add sceneMerge backend support
* Add merge scene to UI
* Populate split create with scene details
* Add merge button to duplicate checker
* Handle file-less scenes in marker preview generate
* Make unique file name for file-less scene exports
* Add o-counter to scene update input
* Hide rescan for file-less scenes
* Generate heatmap if no speed set on file
* Fix count in scene/image queries
This commit is contained in:
WithoutPants
2022-11-14 16:35:09 +11:00
committed by GitHub
parent d0b0be4dd4
commit 4a054ab081
60 changed files with 2550 additions and 412 deletions
+5 -1
View File
@@ -3,6 +3,7 @@ package jsonschema
import (
"fmt"
"os"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/stashapp/stash/pkg/fsutil"
@@ -60,7 +61,7 @@ type Scene struct {
StashIDs []models.StashID `json:"stash_ids,omitempty"`
}
func (s Scene) Filename(basename string, hash string) string {
func (s Scene) Filename(id int, basename string, hash string) string {
ret := fsutil.SanitiseBasename(s.Title)
if ret == "" {
ret = basename
@@ -68,6 +69,9 @@ func (s Scene) Filename(basename string, hash string) string {
if hash != "" {
ret += "." + hash
} else {
// scenes may have no file and therefore no hash
ret += "." + strconv.Itoa(id)
}
return ret + ".json"
+25 -3
View File
@@ -41,21 +41,43 @@ func (u *UpdateMovieIDs) SceneMovieInputs() []*SceneMovieInput {
return ret
}
func (u *UpdateMovieIDs) AddUnique(v MoviesScenes) {
for _, vv := range u.Movies {
if vv.MovieID == v.MovieID {
return
}
}
u.Movies = append(u.Movies, v)
}
func UpdateMovieIDsFromInput(i []*SceneMovieInput) (*UpdateMovieIDs, error) {
ret := &UpdateMovieIDs{
Mode: RelationshipUpdateModeSet,
}
for _, v := range i {
var err error
ret.Movies, err = MoviesScenesFromInput(i)
if err != nil {
return nil, err
}
return ret, nil
}
func MoviesScenesFromInput(input []*SceneMovieInput) ([]MoviesScenes, error) {
ret := make([]MoviesScenes, len(input))
for i, v := range input {
mID, err := strconv.Atoi(v.MovieID)
if err != nil {
return nil, fmt.Errorf("invalid movie ID: %s", v.MovieID)
}
ret.Movies = append(ret.Movies, MoviesScenes{
ret[i] = MoviesScenes{
MovieID: mID,
SceneIndex: v.SceneIndex,
})
}
}
return ret, nil
+1
View File
@@ -177,6 +177,7 @@ type SceneUpdateInput struct {
URL *string `json:"url"`
Date *string `json:"date"`
Rating *int `json:"rating"`
OCounter *int `json:"o_counter"`
Organized *bool `json:"organized"`
StudioID *string `json:"studio_id"`
GalleryIds []string `json:"gallery_ids"`
+2 -2
View File
@@ -13,13 +13,13 @@ type Paths struct {
SceneMarkers *sceneMarkerPaths
}
func NewPaths(generatedPath string) *Paths {
func NewPaths(generatedPath string) Paths {
p := Paths{}
p.Generated = newGeneratedPaths(generatedPath)
p.Scene = newScenePaths(p)
p.SceneMarkers = newSceneMarkerPaths(p)
return &p
return p
}
func GetStashHomeDirectory() string {
+13
View File
@@ -138,6 +138,19 @@ func (r *RelatedMovies) Add(movies ...MoviesScenes) {
r.list = append(r.list, movies...)
}
// ForID returns the MoviesScenes object for the given movie ID. Returns nil if not found.
func (r *RelatedMovies) ForID(id int) *MoviesScenes {
r.mustLoaded()
for _, v := range r.list {
if v.MovieID == id {
return &v
}
}
return nil
}
func (r *RelatedMovies) load(fn func() ([]MoviesScenes, error)) error {
if r.Loaded() {
return nil
+11
View File
@@ -9,3 +9,14 @@ type UpdateStashIDs struct {
StashIDs []StashID `json:"stash_ids"`
Mode RelationshipUpdateMode `json:"mode"`
}
// AddUnique adds the stash id to the list, only if the endpoint/stashid pair does not already exist in the list.
func (u *UpdateStashIDs) AddUnique(v StashID) {
for _, vv := range u.StashIDs {
if vv.StashID == v.StashID && vv.Endpoint == v.Endpoint {
return
}
}
u.StashIDs = append(u.StashIDs, v)
}
+28
View File
@@ -23,6 +23,13 @@ func (o *OptionalString) Ptr() *string {
return &v
}
// Merge sets the OptionalString if it is not already set, the destination value is empty and the source value is not empty.
func (o *OptionalString) Merge(destVal string, srcVal string) {
if destVal == "" && srcVal != "" && !o.Set {
*o = NewOptionalString(srcVal)
}
}
// NewOptionalString returns a new OptionalString with the given value.
func NewOptionalString(v string) OptionalString {
return OptionalString{v, false, true}
@@ -58,6 +65,13 @@ func (o *OptionalInt) Ptr() *int {
return &v
}
// MergePtr sets the OptionalInt if it is not already set, the destination value is nil and the source value is not nil.
func (o *OptionalInt) MergePtr(destVal *int, srcVal *int) {
if destVal == nil && srcVal != nil && !o.Set {
*o = NewOptionalInt(*srcVal)
}
}
// NewOptionalInt returns a new OptionalInt with the given value.
func NewOptionalInt(v int) OptionalInt {
return OptionalInt{v, false, true}
@@ -138,6 +152,13 @@ func (o *OptionalBool) Ptr() *bool {
return &v
}
// Merge sets the OptionalBool to true if it is not already set, the destination value is false and the source value is true.
func (o *OptionalBool) Merge(destVal bool, srcVal bool) {
if !destVal && srcVal && !o.Set {
*o = NewOptionalBool(true)
}
}
// NewOptionalBool returns a new OptionalBool with the given value.
func NewOptionalBool(v bool) OptionalBool {
return OptionalBool{v, false, true}
@@ -200,6 +221,13 @@ func NewOptionalDate(v Date) OptionalDate {
return OptionalDate{v, false, true}
}
// Merge sets the OptionalDate if it is not already set, the destination value is nil and the source value is nil.
func (o *OptionalDate) MergePtr(destVal *Date, srcVal *Date) {
if destVal == nil && srcVal != nil && !o.Set {
*o = NewOptionalDate(*srcVal)
}
}
// NewOptionalBoolPtr returns a new OptionalDate with the given value.
// If the value is nil, the returned OptionalDate will be set and null.
func NewOptionalDatePtr(v *Date) OptionalDate {