From a4274db9585851d8038c5972a6072b9499e6e3df Mon Sep 17 00:00:00 2001 From: crwxaj <52156245+crwxaj@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:08:17 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20don=E2=80=99t=20render=20heatmaps=20for?= =?UTF-8?q?=20script=20tokens=20(#1798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: crwxaj --- pkg/api/deovr.go | 10 ++++++---- pkg/tasks/heatmap.go | 31 ++++++++++++++++++++++++++++++- pkg/tasks/volume.go | 2 +- ui/src/views/files/SceneMatch.vue | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/pkg/api/deovr.go b/pkg/api/deovr.go index 207e210ad..4a1a2cb5f 100644 --- a/pkg/api/deovr.go +++ b/pkg/api/deovr.go @@ -426,10 +426,12 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response) } for _, file := range scriptFiles { - deoScriptFiles = append(deoScriptFiles, DeoSceneScriptFile{ - Title: file.Filename, - URL: fmt.Sprintf("%v/api/dms/file/%v", session.DeoRequestHost, file.ID), - }) + if strings.HasSuffix(file.Filename, ".funscript") { + deoScriptFiles = append(deoScriptFiles, DeoSceneScriptFile{ + Title: file.Filename, + URL: fmt.Sprintf("%v/api/dms/file/%v", session.DeoRequestHost, file.ID), + }) + } } var deoHSPFiles []DeoSceneHSPFile diff --git a/pkg/tasks/heatmap.go b/pkg/tasks/heatmap.go index 2ee89cbf3..52150cb61 100644 --- a/pkg/tasks/heatmap.go +++ b/pkg/tasks/heatmap.go @@ -131,6 +131,9 @@ func RenderHeatmap(inputFile string, destFile string, width, height, numSegments if err != nil { return err } + if funscript.IsFunscriptToken() { + return fmt.Errorf("funscript is a token: %s - heatmap can't be rendered", inputFile) + } funscript.UpdateIntensity() gradient := funscript.getGradientTable(numSegments) @@ -260,6 +263,29 @@ func (funscript Script) getGradientTable(numSegments int) GradientTable { return gradient } +func (funscript *Script) IsFunscriptToken() bool { + if len(funscript.Actions) > 100 { + return false + } + actions := make([]Action, len(funscript.Actions)) + copy(actions, funscript.Actions) + sort.SliceStable(actions, func(i, j int) bool { return funscript.Actions[i].Pos < funscript.Actions[j].Pos }) + + if actions[0].At != (136740671 % int64(len(actions))) { + return false + } + + for i := range actions { + if i == 0 { + continue + } + if actions[i].Pos != actions[i-1].Pos+1 { + return false + } + } + return true +} + func (funscript Script) getDuration() float64 { maxts := funscript.Actions[len(funscript.Actions)-1].At duration := float64(maxts) / 1000.0 @@ -280,13 +306,16 @@ func (funscript Script) getDuration() float64 { func getFunscriptDuration(path string) (float64, error) { if !strings.HasSuffix(path, ".funscript") { - return 0.0, fmt.Errorf("Not a funscript: %s", path) + return 0.0, fmt.Errorf("not a funscript: %s", path) } funscript, err := LoadFunscriptData(path) if err != nil { return 0.0, err } + if funscript.IsFunscriptToken() { + return 0.0, fmt.Errorf("funscript is a token: %s", path) + } return funscript.getDuration(), nil } diff --git a/pkg/tasks/volume.go b/pkg/tasks/volume.go index 085a7ded5..484c570bf 100644 --- a/pkg/tasks/volume.go +++ b/pkg/tasks/volume.go @@ -227,7 +227,7 @@ func scanLocalVolume(vol models.Volume, db *gorm.DB, tlog *logrus.Entry) { } } - if !strings.HasPrefix(filepath.Base(path), ".") && (filepath.Ext(path) == ".funscript" || filepath.Ext(path) == ".cmscript") { + if !strings.HasPrefix(filepath.Base(path), ".") && (filepath.Ext(path) == ".funscript" || strings.ToLower(filepath.Ext(path)) == ".cmscript") { scriptProcList = append(scriptProcList, path) } if !strings.HasPrefix(filepath.Base(path), ".") && filepath.Ext(path) == ".hsp" { diff --git a/ui/src/views/files/SceneMatch.vue b/ui/src/views/files/SceneMatch.vue index 5a09755c8..26139118e 100644 --- a/ui/src/views/files/SceneMatch.vue +++ b/ui/src/views/files/SceneMatch.vue @@ -142,7 +142,7 @@ export default { const commonWords = [ '180', '180x180', '2880x1440', '3d', '3dh', '3dv', '30fps', '30m', '360', '3840x1920', '4k', '5k', '5400x2700', '60fps', '6k', '7k', '7680x3840', - '8k', 'fb360', 'fisheye190', 'funscript', 'h264', 'h265', 'hevc', 'hq', 'hsp', 'lq', 'lr', + '8k', 'fb360', 'fisheye190', 'funscript', 'cmscript', 'h264', 'h265', 'hevc', 'hq', 'hsp', 'lq', 'lr', 'mkv', 'mkx200', 'mkx220', 'mono', 'mp4', 'oculus', 'oculus5k', 'oculusrift', 'original', 'rf52', 'smartphone', 'srt', 'ssa', 'tb', 'uhq', 'vrca220', 'vp9' ]