Skip to content

Commit e588277

Browse files
Configurable title format for DeoVR
1 parent a642907 commit e588277

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
@@ -307,7 +307,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
307307
Height: height,
308308
Width: width,
309309
Size: file.Size,
310-
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(), dnt),
310+
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
311311
},
312312
},
313313
})
@@ -358,11 +358,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
358358
screenType = "sphere"
359359
}
360360

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

364364
if scene.IsScripted {
365-
title = scene.GetFunscriptTitle()
365+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
366366
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
367367
thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
368368
}
@@ -457,9 +457,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem
457457
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
458458
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
459459
}
460-
461460
item := DeoListItem{
462-
Title: scenes[i].Title,
461+
Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat),
463462
VideoLength: scenes[i].Duration * 60,
464463
ThumbnailURL: thumbnailURL,
465464
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
@@ -56,6 +56,7 @@ type RequestSaveOptionsDeoVR struct {
5656
Password string `json:"password"`
5757
RemoteEnabled bool `json:"remote_enabled"`
5858
RenderHeatmaps bool `json:"render_heatmaps"`
59+
TitleFormat string `json:"title_format"`
5960
}
6061

6162
type RequestSaveOptionsPreviews struct {
@@ -233,6 +234,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
233234
config.Config.Interfaces.DeoVR.RenderHeatmaps = r.RenderHeatmaps
234235
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
235236
config.Config.Interfaces.DeoVR.Username = r.Username
237+
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
236238
if r.Password != config.Config.Interfaces.DeoVR.Password && r.Password != "" {
237239
hash, _ := bcrypt.GenerateFromPassword([]byte(r.Password), bcrypt.DefaultCost)
238240
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
@@ -35,6 +35,7 @@ type ObjectConfig struct {
3535
RemoteEnabled bool `default:"false" json:"remote_enabled"`
3636
Username string `default:"" json:"username"`
3737
Password string `default:"" json:"password"`
38+
TitleFormat string `default:"{{.Title}}" json:"title_format"`
3839
} `json:"deovr"`
3940
} `json:"interfaces"`
4041
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
@@ -9,6 +9,7 @@ const state = {
99
remote_enabled: false,
1010
username: '',
1111
password: '',
12+
title_format: '',
1213
boundIp: []
1314
}
1415
}
@@ -27,6 +28,7 @@ const actions = {
2728
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
2829
state.deovr.username = data.config.interfaces.deovr.username
2930
state.deovr.password = data.config.interfaces.deovr.password
31+
state.deovr.title_format = data.config.interfaces.deovr.title_format
3032
state.deovr.boundIp = data.currentState.server.bound_ip
3133
state.loading = false
3234
})

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@
5353
instructions in DeoVR documentation</a>.
5454
</p>
5555
</div>
56+
<hr/>
57+
<div class="block">
58+
<b-field label="Title Format">
59+
<b-input v-model="titleFormat"></b-input>
60+
</b-field>
61+
<p>
62+
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>.
63+
Examples:
64+
</p>
65+
<ul>
66+
<pre v-pre><li>{{.Studio}} - {{.Title}}</li><li>{{.Title}} ({{.ReleaseDate.Format "2006"}})</li></pre>
67+
</ul>
68+
</div>
5669
</div>
5770
</section>
5871
</div>
@@ -149,6 +162,14 @@ export default {
149162
this.$store.state.optionsDeoVR.deovr.password = value
150163
}
151164
},
165+
titleFormat: {
166+
get () {
167+
return this.$store.state.optionsDeoVR.deovr.title_format
168+
},
169+
set (value) {
170+
this.$store.state.optionsDeoVR.deovr.title_format = value
171+
}
172+
},
152173
boundIp: {
153174
get () {
154175
return this.$store.state.optionsDeoVR.deovr.boundIp

0 commit comments

Comments
 (0)