Skip to content

Commit

Permalink
fix: don’t render heatmaps for script tokens (xbapps#1798)
Browse files Browse the repository at this point in the history
Co-authored-by: crwxaj <crwxaj>
  • Loading branch information
crwxaj authored Jul 19, 2024
1 parent 5e84f98 commit a4274db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
10 changes: 6 additions & 4 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion pkg/tasks/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion pkg/tasks/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/files/SceneMatch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down

0 comments on commit a4274db

Please sign in to comment.