Skip to content

Commit

Permalink
feat: add support for cmscript files (xbapps#1788)
Browse files Browse the repository at this point in the history
Co-authored-by: Alderamin <[email protected]>
  • Loading branch information
Alderamin49ly and Alderamin authored Jul 19, 2024
1 parent 3f428a9 commit 5e84f98
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
38 changes: 23 additions & 15 deletions pkg/tasks/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"

"github.com/lucasb-eyer/go-colorful"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -69,21 +70,24 @@ func GenerateHeatmaps(tlog *logrus.Entry) {
tlog.Infof("Generating heatmaps (%v/%v)", i+1, len(scriptfiles))
}
if file.Exists() {
log.Infof("Rendering %v", file.Filename)
destFile := filepath.Join(common.ScriptHeatmapDir, fmt.Sprintf("heatmap-%d.png", file.ID))
err := RenderHeatmap(
file.GetPath(),
destFile,
1000,
10,
250,
)
if err == nil {
file.HasHeatmap = true
file.RefreshHeatmapCache = true
file.Save()
} else {
log.Warn(err)
path := file.GetPath()
if strings.HasSuffix(path, ".funscript") {
log.Infof("Rendering %v", file.Filename)
destFile := filepath.Join(common.ScriptHeatmapDir, fmt.Sprintf("heatmap-%d.png", file.ID))
err := RenderHeatmap(
path,
destFile,
1000,
10,
250,
)
if err == nil {
file.HasHeatmap = true
file.RefreshHeatmapCache = true
file.Save()
} else {
log.Warn(err)
}
}
}
}
Expand Down Expand Up @@ -275,6 +279,10 @@ 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)
}

funscript, err := LoadFunscriptData(path)
if err != nil {
return 0.0, err
Expand Down
9 changes: 5 additions & 4 deletions pkg/tasks/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ func RescanVolumes(id int) {
filename := escape(unescapedFilename)
filename2 := strings.Replace(filename, ".funscript", ".mp4", -1)
filename3 := strings.Replace(filename, ".hsp", ".mp4", -1)
filename3 = strings.Replace(filename3, ".srt", ".mp4", -1)
err := db.Where("filenames_arr LIKE ? OR filenames_arr LIKE ? OR filenames_arr LIKE ?", `%"`+filename+`"%`, `%"`+filename2+`"%`, `%"`+filename3+`"%`).Find(&scenes).Error
filename4 := strings.Replace(filename, ".srt", ".mp4", -1)
filename5 := strings.Replace(filename, ".cmscript", ".mp4", -1)
err := db.Where("filenames_arr LIKE ? OR filenames_arr LIKE ? OR filenames_arr LIKE ? OR filenames_arr LIKE ? OR filenames_arr LIKE ?", `%"`+filename+`"%`, `%"`+filename2+`"%`, `%"`+filename3+`"%`, `%"`+filename4+`"%`, `%"`+filename5+`"%`).Find(&scenes).Error
if err != nil {
log.Error(err, " when matching "+unescapedFilename)
}
if len(scenes) == 0 && config.Config.Advanced.UseAltSrcInFileMatching {
// check if the filename matches in external_reference record

db.Preload("XbvrLinks").Where("external_source like 'alternate scene %' and external_data LIKE ? OR external_data LIKE ? OR external_data LIKE ?", `%"`+filename+`%`, `%"`+filename2+`%`, `%"`+filename3+`%`).Find(&extrefs)
db.Preload("XbvrLinks").Where("external_source like 'alternate scene %' and external_data LIKE ? OR external_data LIKE ? OR external_data LIKE ? OR external_data LIKE ? OR external_data LIKE ?", `%"`+filename+`%`, `%"`+filename2+`%`, `%"`+filename3+`%`, `%"`+filename4+`%`, `%"`+filename5+`%`).Find(&extrefs)
if len(extrefs) == 1 {
if len(extrefs[0].XbvrLinks) == 1 {
// the scene id will be the Internal DB Id from the associated link
Expand Down Expand Up @@ -226,7 +227,7 @@ func scanLocalVolume(vol models.Volume, db *gorm.DB, tlog *logrus.Entry) {
}
}

if !strings.HasPrefix(filepath.Base(path), ".") && filepath.Ext(path) == ".funscript" {
if !strings.HasPrefix(filepath.Base(path), ".") && (filepath.Ext(path) == ".funscript" || filepath.Ext(path) == ".cmscript") {
scriptProcList = append(scriptProcList, path)
}
if !strings.HasPrefix(filepath.Base(path), ".") && filepath.Ext(path) == ".hsp" {
Expand Down

0 comments on commit 5e84f98

Please sign in to comment.