Skip to content

Commit fdac321

Browse files
Configurable title format for DeoVR
1 parent e8bb049 commit fdac321

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

pkg/api/deovr.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
339339
Height: height,
340340
Width: width,
341341
Size: file.Size,
342-
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(), dnt),
342+
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
343343
},
344344
},
345345
}
@@ -425,11 +425,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
425425
}
426426
}
427427

428-
title := scene.Title
428+
title := scene.GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat)
429429
thumbnailURL := session.DeoRequestHost + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
430430

431431
if scene.IsScripted {
432-
title = scene.GetFunscriptTitle()
432+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
433433
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
434434
thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
435435
}
@@ -530,9 +530,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem
530530
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
531531
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
532532
}
533-
534533
item := DeoListItem{
535-
Title: scenes[i].Title,
534+
Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat),
536535
VideoLength: scenes[i].Duration * 60,
537536
ThumbnailURL: thumbnailURL,
538537
VideoURL: fmt.Sprintf("%v/deovr/%v", session.DeoRequestHost, scenes[i].ID),

pkg/api/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type RequestSaveOptionsDeoVR struct {
6262
RemoteEnabled bool `json:"remote_enabled"`
6363
TrackWatchTime bool `json:"track_watch_time"`
6464
RenderHeatmaps bool `json:"render_heatmaps"`
65+
TitleFormat string `json:"title_format"`
6566
}
6667

6768
type RequestSaveOptionsPreviews struct {
@@ -256,6 +257,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
256257
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
257258
config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime
258259
config.Config.Interfaces.DeoVR.Username = r.Username
260+
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
259261
if r.Password != config.Config.Interfaces.DeoVR.Password && r.Password != "" {
260262
hash, _ := bcrypt.GenerateFromPassword([]byte(r.Password), bcrypt.DefaultCost)
261263
config.Config.Interfaces.DeoVR.Password = string(hash)

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type ObjectConfig struct {
4545
RemoteEnabled bool `default:"false" json:"remote_enabled"`
4646
Username string `default:"" json:"username"`
4747
Password string `default:"" json:"password"`
48+
TitleFormat string `default:"{{.Title}}" json:"title_format"`
4849
} `json:"deovr"`
4950
} `json:"interfaces"`
5051
Library struct {

pkg/models/model_scene.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package models
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"os"
78
"path/filepath"
89
"regexp"
910
"strings"
11+
"text/template"
1012
"time"
1113

1214
"github.com/araddon/dateparse"
@@ -172,12 +174,32 @@ func (o *Scene) GetIfExistURL(u string) error {
172174
Where(&Scene{SceneURL: u}).First(o).Error
173175
}
174176

175-
func (o *Scene) GetFunscriptTitle() string {
177+
func (scene *Scene) GetDeoFormattedTitle(titleFormat string) string {
178+
customTitleTemplate, err := template.New("customTitleTemplate").Parse(titleFormat)
179+
if err != nil {
180+
common.Log.Warn(err)
181+
customTitleTemplate, err = template.New("customTitleTemplate").Parse("{{.Title}}")
182+
if err != nil {
183+
return scene.Title
184+
}
185+
}
186+
var tpl bytes.Buffer
187+
title := scene.Title
188+
err = customTitleTemplate.Execute(&tpl, scene)
189+
if err == nil {
190+
title = tpl.String()
191+
} else {
192+
common.Log.Warn(err)
193+
}
194+
return title
195+
}
196+
197+
func (o *Scene) GetFunscriptTitle(titleFormat string) string {
176198

177199
// first make the title filename safe
178200
var re = regexp.MustCompile(`[?/\<>|]`)
179201

180-
title := o.Title
202+
title := o.GetDeoFormattedTitle(titleFormat)
181203
// Colons are pretty common in titles, so we use a unicode alternative
182204
title = strings.ReplaceAll(title, ":", "꞉")
183205
// all other unsafe characters get removed

pkg/tasks/funscripts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99

10+
"github.com/xbapps/xbvr/pkg/config"
1011
"github.com/xbapps/xbvr/pkg/models"
1112
)
1213

@@ -39,7 +40,7 @@ func ExportFunscripts(w http.ResponseWriter, updatedOnly bool) {
3940
if i == 0 {
4041
if file.Exists() {
4142
if !file.IsExported || !updatedOnly {
42-
funscriptName := fmt.Sprintf("%s.funscript", scene.GetFunscriptTitle())
43+
funscriptName := fmt.Sprintf("%s.funscript", scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat))
4344

4445
if err = AddFileToZip(zipWriter, file.GetPath(), funscriptName); err != nil {
4546
log.Infof("Error when adding file to zip: %v (%s)", err, funscriptName)

ui/src/store/optionsDeoVR.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const state = {
1010
remote_enabled: false,
1111
username: '',
1212
password: '',
13+
title_format: '',
1314
boundIp: []
1415
}
1516
}
@@ -29,6 +30,7 @@ const actions = {
2930
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
3031
state.deovr.username = data.config.interfaces.deovr.username
3132
state.deovr.password = data.config.interfaces.deovr.password
33+
state.deovr.title_format = data.config.interfaces.deovr.title_format
3234
state.deovr.boundIp = data.currentState.server.bound_ip
3335
state.loading = false
3436
})

ui/src/views/options/sections/InterfaceDeoVR.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@
5858
instructions in DeoVR documentation</a>.
5959
</p>
6060
</div>
61+
<hr/>
62+
<div class="block">
63+
<b-field label="Title Format">
64+
<b-input v-model="titleFormat"></b-input>
65+
</b-field>
66+
<p>
67+
Custom Title format to use in DeoVR, following Golang's template <a href="https://golang.org/pkg/text/template/" target="_blank" rel="noreferrer">format</a>.
68+
Examples:
69+
</p>
70+
<ul>
71+
<pre v-pre><li>{{.Studio}} - {{.Title}}</li><li>{{.Title}} ({{.ReleaseDate.Format "2006"}})</li></pre>
72+
</ul>
73+
</div>
6174
</div>
6275
</section>
6376
</div>
@@ -162,6 +175,14 @@ export default {
162175
this.$store.state.optionsDeoVR.deovr.password = value
163176
}
164177
},
178+
titleFormat: {
179+
get () {
180+
return this.$store.state.optionsDeoVR.deovr.title_format
181+
},
182+
set (value) {
183+
this.$store.state.optionsDeoVR.deovr.title_format = value
184+
}
185+
},
165186
boundIp: {
166187
get () {
167188
return this.$store.state.optionsDeoVR.deovr.boundIp

0 commit comments

Comments
 (0)