mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Handle bad funscript at values (#3182)
This commit is contained in:
@@ -11,16 +11,18 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InteractiveHeatmapSpeedGenerator struct {
|
type InteractiveHeatmapSpeedGenerator struct {
|
||||||
InteractiveSpeed int
|
sceneDurationMilli int64
|
||||||
Funscript Script
|
InteractiveSpeed int
|
||||||
FunscriptPath string
|
Funscript Script
|
||||||
HeatmapPath string
|
FunscriptPath string
|
||||||
Width int
|
HeatmapPath string
|
||||||
Height int
|
Width int
|
||||||
NumSegments int
|
Height int
|
||||||
|
NumSegments int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Script struct {
|
type Script struct {
|
||||||
@@ -52,13 +54,14 @@ type GradientTable []struct {
|
|||||||
Pos float64
|
Pos float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInteractiveHeatmapSpeedGenerator(funscriptPath string, heatmapPath string) *InteractiveHeatmapSpeedGenerator {
|
func NewInteractiveHeatmapSpeedGenerator(funscriptPath string, heatmapPath string, sceneDuration float64) *InteractiveHeatmapSpeedGenerator {
|
||||||
return &InteractiveHeatmapSpeedGenerator{
|
return &InteractiveHeatmapSpeedGenerator{
|
||||||
FunscriptPath: funscriptPath,
|
sceneDurationMilli: int64(sceneDuration * 1000),
|
||||||
HeatmapPath: heatmapPath,
|
FunscriptPath: funscriptPath,
|
||||||
Width: 320,
|
HeatmapPath: heatmapPath,
|
||||||
Height: 15,
|
Width: 320,
|
||||||
NumSegments: 150,
|
Height: 15,
|
||||||
|
NumSegments: 150,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +72,10 @@ func (g *InteractiveHeatmapSpeedGenerator) Generate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(funscript.Actions) == 0 {
|
||||||
|
return fmt.Errorf("no valid actions in funscript")
|
||||||
|
}
|
||||||
|
|
||||||
g.Funscript = funscript
|
g.Funscript = funscript
|
||||||
g.Funscript.UpdateIntensityAndSpeed()
|
g.Funscript.UpdateIntensityAndSpeed()
|
||||||
|
|
||||||
@@ -102,14 +109,20 @@ func (g *InteractiveHeatmapSpeedGenerator) LoadFunscriptData(path string) (Scrip
|
|||||||
sort.SliceStable(funscript.Actions, func(i, j int) bool { return funscript.Actions[i].At < funscript.Actions[j].At })
|
sort.SliceStable(funscript.Actions, func(i, j int) bool { return funscript.Actions[i].At < funscript.Actions[j].At })
|
||||||
|
|
||||||
// trim actions with negative timestamps to avoid index range errors when generating heatmap
|
// trim actions with negative timestamps to avoid index range errors when generating heatmap
|
||||||
|
// #3181 - also trim actions that occur after the scene duration
|
||||||
isValid := func(x int64) bool { return x >= 0 }
|
loggedBadTimestamp := false
|
||||||
|
isValid := func(x int64) bool {
|
||||||
|
return x >= 0 && x < g.sceneDurationMilli
|
||||||
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for _, x := range funscript.Actions {
|
for _, x := range funscript.Actions {
|
||||||
if isValid(x.At) {
|
if isValid(x.At) {
|
||||||
funscript.Actions[i] = x
|
funscript.Actions[i] = x
|
||||||
i++
|
i++
|
||||||
|
} else if !loggedBadTimestamp {
|
||||||
|
loggedBadTimestamp = true
|
||||||
|
logger.Warnf("Invalid timestamp %d in %s: subsequent invalid timestamps will not be logged", x.At, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +228,10 @@ func (funscript Script) getGradientTable(numSegments int) GradientTable {
|
|||||||
|
|
||||||
for _, a := range funscript.Actions {
|
for _, a := range funscript.Actions {
|
||||||
segment := int(float64(a.At) / float64(maxts+1) * float64(numSegments))
|
segment := int(float64(a.At) / float64(maxts+1) * float64(numSegments))
|
||||||
|
// #3181 - sanity check. Clamp segment to numSegments-1
|
||||||
|
if segment >= numSegments {
|
||||||
|
segment = numSegments - 1
|
||||||
|
}
|
||||||
segments[segment].count++
|
segments[segment].count++
|
||||||
segments[segment].intensity += int(a.Intensity)
|
segments[segment].intensity += int(a.Intensity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (t *GenerateInteractiveHeatmapSpeedTask) Start(ctx context.Context) {
|
|||||||
funscriptPath := video.GetFunscriptPath(t.Scene.Path)
|
funscriptPath := video.GetFunscriptPath(t.Scene.Path)
|
||||||
heatmapPath := instance.Paths.Scene.GetInteractiveHeatmapPath(videoChecksum)
|
heatmapPath := instance.Paths.Scene.GetInteractiveHeatmapPath(videoChecksum)
|
||||||
|
|
||||||
generator := NewInteractiveHeatmapSpeedGenerator(funscriptPath, heatmapPath)
|
generator := NewInteractiveHeatmapSpeedGenerator(funscriptPath, heatmapPath, t.Scene.Files.Primary().Duration)
|
||||||
|
|
||||||
err := generator.Generate()
|
err := generator.Generate()
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
* Added tag description filter criterion. ([#3011](https://github.com/stashapp/stash/pull/3011))
|
* Added tag description filter criterion. ([#3011](https://github.com/stashapp/stash/pull/3011))
|
||||||
|
|
||||||
### 🎨 Improvements
|
### 🎨 Improvements
|
||||||
|
* Generated heatmaps now only show ranges within the duration of the scene. ([#3182](https://github.com/stashapp/stash/pull/3182))
|
||||||
* Added File Modification Time to File Info panels. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
* Added File Modification Time to File Info panels. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
||||||
* Added counter to File Info tabs for objects with multiple files. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
* Added counter to File Info tabs for objects with multiple files. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
||||||
* Added file count in Scene Duplicate Checker for scenes with multiple files. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
* Added file count in Scene Duplicate Checker for scenes with multiple files. ([#3054](https://github.com/stashapp/stash/pull/3054))
|
||||||
|
|||||||
Reference in New Issue
Block a user