From ab0dba151e21d333db817a1d37d6f66c13cb0015 Mon Sep 17 00:00:00 2001 From: CoolMintChocolate <70276626+CoolMintChocolate@users.noreply.github.com> Date: Sun, 13 Jun 2021 17:58:56 -0400 Subject: [PATCH] Configurable title format for DeoVR --- pkg/api/deovr.go | 9 +++---- pkg/api/heresphere.go | 4 +-- pkg/api/options.go | 2 ++ pkg/config/config.go | 1 + pkg/models/model_scene.go | 26 +++++++++++++++++-- pkg/tasks/funscripts.go | 3 ++- ui/src/store/optionsDeoVR.js | 2 ++ .../views/options/sections/InterfaceDeoVR.vue | 21 +++++++++++++++ 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/pkg/api/deovr.go b/pkg/api/deovr.go index 6e49016ad..ffaa2a752 100644 --- a/pkg/api/deovr.go +++ b/pkg/api/deovr.go @@ -346,7 +346,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response) Height: height, Width: width, Size: file.Size, - URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(), dnt), + URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt), }, }, } @@ -443,11 +443,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response) } } - title := scene.Title + title := scene.GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat) thumbnailURL := session.DeoRequestHost + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1) if scene.IsScripted { - title = scene.GetFunscriptTitle() + title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat) if config.Config.Interfaces.DeoVR.RenderHeatmaps { thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1) } @@ -554,9 +554,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted { thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1)) } - item := DeoListItem{ - Title: scenes[i].Title, + Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat), VideoLength: scenes[i].Duration * 60, ThumbnailURL: thumbnailURL, VideoURL: fmt.Sprintf("%v/deovr/%v", session.DeoRequestHost, scenes[i].ID), diff --git a/pkg/api/heresphere.go b/pkg/api/heresphere.go index aecfebaba..84f161d59 100644 --- a/pkg/api/heresphere.go +++ b/pkg/api/heresphere.go @@ -326,7 +326,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf Height: height, Width: width, Size: file.Size, - URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(), dnt), + URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt), }, }, } @@ -616,7 +616,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf thumbnailURL := "http://" + req.Request.Host + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1) if scene.IsScripted { - title = scene.GetFunscriptTitle() + title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat) if config.Config.Interfaces.DeoVR.RenderHeatmaps { thumbnailURL = "http://" + req.Request.Host + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1) } diff --git a/pkg/api/options.go b/pkg/api/options.go index 82bfe8f6b..be303103f 100644 --- a/pkg/api/options.go +++ b/pkg/api/options.go @@ -66,6 +66,7 @@ type RequestSaveOptionsDeoVR struct { RemoteEnabled bool `json:"remote_enabled"` TrackWatchTime bool `json:"track_watch_time"` RenderHeatmaps bool `json:"render_heatmaps"` + TitleFormat string `json:"title_format"` AllowFileDeletes bool `json:"allow_file_deletes"` AllowRatingUpdates bool `json:"allow_rating_updates"` AllowFavoriteUpdates bool `json:"allow_favorite_updates"` @@ -309,6 +310,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime config.Config.Interfaces.DeoVR.Username = r.Username + config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat config.Config.Interfaces.Heresphere.AllowFileDeletes = r.AllowFileDeletes config.Config.Interfaces.Heresphere.AllowRatingUpdates = r.AllowRatingUpdates config.Config.Interfaces.Heresphere.AllowFavoriteUpdates = r.AllowFavoriteUpdates diff --git a/pkg/config/config.go b/pkg/config/config.go index f0926f773..f1212b569 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -58,6 +58,7 @@ type ObjectConfig struct { RemoteEnabled bool `default:"false" json:"remote_enabled"` Username string `default:"" json:"username"` Password string `default:"" json:"password"` + TitleFormat string `default:"{{.Title}}" json:"title_format"` } `json:"deovr"` Heresphere struct { AllowFileDeletes bool `default:"false" json:"allow_file_deletes"` diff --git a/pkg/models/model_scene.go b/pkg/models/model_scene.go index b70c20fde..8a316f37c 100644 --- a/pkg/models/model_scene.go +++ b/pkg/models/model_scene.go @@ -1,6 +1,7 @@ package models import ( + "bytes" "encoding/json" "fmt" "os" @@ -8,6 +9,7 @@ import ( "regexp" "strconv" "strings" + "text/template" "time" "github.com/araddon/dateparse" @@ -183,12 +185,32 @@ func (o *Scene) GetIfExistURL(u string) error { Where(&Scene{SceneURL: u}).First(o).Error } -func (o *Scene) GetFunscriptTitle() string { +func (scene *Scene) GetDeoFormattedTitle(titleFormat string) string { + customTitleTemplate, err := template.New("customTitleTemplate").Parse(titleFormat) + if err != nil { + common.Log.Warn(err) + customTitleTemplate, err = template.New("customTitleTemplate").Parse("{{.Title}}") + if err != nil { + return scene.Title + } + } + var tpl bytes.Buffer + title := scene.Title + err = customTitleTemplate.Execute(&tpl, scene) + if err == nil { + title = tpl.String() + } else { + common.Log.Warn(err) + } + return title +} + +func (o *Scene) GetFunscriptTitle(titleFormat string) string { // first make the title filename safe var re = regexp.MustCompile(`[?/\<>|]`) - title := o.Title + title := o.GetDeoFormattedTitle(titleFormat) // Colons are pretty common in titles, so we use a unicode alternative title = strings.ReplaceAll(title, ":", "꞉") // all other unsafe characters get removed diff --git a/pkg/tasks/funscripts.go b/pkg/tasks/funscripts.go index a3fd4dca4..393f901dd 100644 --- a/pkg/tasks/funscripts.go +++ b/pkg/tasks/funscripts.go @@ -7,6 +7,7 @@ import ( "net/http" "os" + "github.com/xbapps/xbvr/pkg/config" "github.com/xbapps/xbvr/pkg/models" ) @@ -39,7 +40,7 @@ func ExportFunscripts(w http.ResponseWriter, updatedOnly bool) { if i == 0 { if file.Exists() { if !file.IsExported || !updatedOnly { - funscriptName := fmt.Sprintf("%s.funscript", scene.GetFunscriptTitle()) + funscriptName := fmt.Sprintf("%s.funscript", scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)) if err = AddFileToZip(zipWriter, file.GetPath(), funscriptName); err != nil { log.Infof("Error when adding file to zip: %v (%s)", err, funscriptName) diff --git a/ui/src/store/optionsDeoVR.js b/ui/src/store/optionsDeoVR.js index dfa3f8c92..37b87b674 100644 --- a/ui/src/store/optionsDeoVR.js +++ b/ui/src/store/optionsDeoVR.js @@ -10,6 +10,7 @@ const state = { remote_enabled: false, username: '', password: '', + title_format: '', boundIp: [] }, heresphere: { @@ -45,6 +46,7 @@ const actions = { state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled state.deovr.username = data.config.interfaces.deovr.username state.deovr.password = data.config.interfaces.deovr.password + state.deovr.title_format = data.config.interfaces.deovr.title_format state.deovr.boundIp = data.currentState.server.bound_ip state.heresphere.allow_file_deletes = data.config.interfaces.heresphere.allow_file_deletes state.heresphere.allow_rating_updates = data.config.interfaces.heresphere.allow_rating_updates diff --git a/ui/src/views/options/sections/InterfaceDeoVR.vue b/ui/src/views/options/sections/InterfaceDeoVR.vue index a9615fcf7..14a1ca258 100644 --- a/ui/src/views/options/sections/InterfaceDeoVR.vue +++ b/ui/src/views/options/sections/InterfaceDeoVR.vue @@ -111,6 +111,19 @@ +
+
+ + + +

+ Custom Title format to use in DeoVR, following Golang's template format. + Examples: +

+ +
@@ -375,6 +388,14 @@ export default { this.$store.state.optionsDeoVR.deovr.password = value } }, + titleFormat: { + get () { + return this.$store.state.optionsDeoVR.deovr.title_format + }, + set (value) { + this.$store.state.optionsDeoVR.deovr.title_format = value + } + }, boundIp: { get () { return this.$store.state.optionsDeoVR.deovr.boundIp