Skip to content

Commit 82e5395

Browse files
Configurable title format for DeoVR
1 parent b7e6781 commit 82e5395

File tree

8 files changed

+58
-10
lines changed

8 files changed

+58
-10
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
}
@@ -436,11 +436,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
436436
}
437437
}
438438

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

442442
if scene.IsScripted {
443-
title = scene.GetFunscriptTitle()
443+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
444444
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
445445
thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
446446
}
@@ -541,9 +541,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem
541541
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
542542
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
543543
}
544-
545544
item := DeoListItem{
546-
Title: scenes[i].Title,
545+
Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat),
547546
VideoLength: scenes[i].Duration * 60,
548547
ThumbnailURL: thumbnailURL,
549548
VideoURL: fmt.Sprintf("%v/deovr/%v", session.DeoRequestHost, scenes[i].ID),

pkg/api/heresphere.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
302302
Height: height,
303303
Width: width,
304304
Size: file.Size,
305-
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle()),
305+
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)),
306306
},
307307
},
308308
}
@@ -469,7 +469,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
469469
thumbnailURL := "http://" + req.Request.Host + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
470470

471471
if scene.IsScripted {
472-
title = scene.GetFunscriptTitle()
472+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
473473
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
474474
thumbnailURL = "http://" + req.Request.Host + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
475475
}

pkg/api/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type RequestSaveOptionsDeoVR struct {
6565
RemoteEnabled bool `json:"remote_enabled"`
6666
TrackWatchTime bool `json:"track_watch_time"`
6767
RenderHeatmaps bool `json:"render_heatmaps"`
68+
TitleFormat string `json:"title_format"`
6869
AllowFileDeletes bool `json:"allow_file_deletes"`
6970
AllowRatingUpdates bool `json:"allow_rating_updates"`
7071
AllowFavoriteUpdates bool `json:"allow_favorite_updates"`
@@ -299,6 +300,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
299300
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
300301
config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime
301302
config.Config.Interfaces.DeoVR.Username = r.Username
303+
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
302304
config.Config.Interfaces.Heresphere.AllowFileDeletes = r.AllowFileDeletes
303305
config.Config.Interfaces.Heresphere.AllowRatingUpdates = r.AllowRatingUpdates
304306
config.Config.Interfaces.Heresphere.AllowFavoriteUpdates = r.AllowFavoriteUpdates

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ObjectConfig struct {
5656
RemoteEnabled bool `default:"false" json:"remote_enabled"`
5757
Username string `default:"" json:"username"`
5858
Password string `default:"" json:"password"`
59+
TitleFormat string `default:"{{.Title}}" json:"title_format"`
5960
} `json:"deovr"`
6061
Heresphere struct {
6162
AllowFileDeletes bool `default:"false" json:"allow_file_deletes"`

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"
@@ -173,12 +175,32 @@ func (o *Scene) GetIfExistURL(u string) error {
173175
Where(&Scene{SceneURL: u}).First(o).Error
174176
}
175177

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

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

181-
title := o.Title
203+
title := o.GetDeoFormattedTitle(titleFormat)
182204
// Colons are pretty common in titles, so we use a unicode alternative
183205
title = strings.ReplaceAll(title, ":", "꞉")
184206
// 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
heresphere: {
@@ -38,6 +39,7 @@ const actions = {
3839
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
3940
state.deovr.username = data.config.interfaces.deovr.username
4041
state.deovr.password = data.config.interfaces.deovr.password
42+
state.deovr.title_format = data.config.interfaces.deovr.title_format
4143
state.deovr.boundIp = data.currentState.server.bound_ip
4244
state.heresphere.allow_file_deletes = data.config.interfaces.heresphere.allow_file_deletes
4345
state.heresphere.allow_rating_updates = data.config.interfaces.heresphere.allow_rating_updates

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@
4545
If you are using funscripts, you can add a heatmap to the thumbnails of scripted scenes in the Player interface.
4646
</p>
4747
</div>
48+
<hr/>
49+
<div class="block">
50+
<b-field label="Title Format">
51+
<b-input v-model="titleFormat"></b-input>
52+
</b-field>
53+
<p>
54+
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>.
55+
Examples:
56+
</p>
57+
<ul>
58+
<pre v-pre><li>{{.Studio}} - {{.Title}}</li><li>{{.Title}} ({{.ReleaseDate.Format "2006"}})</li></pre>
59+
</ul>
60+
</div>
4861
</div>
4962
</section>
5063
</div>
@@ -222,6 +235,14 @@ export default {
222235
this.$store.state.optionsDeoVR.deovr.password = value
223236
}
224237
},
238+
titleFormat: {
239+
get () {
240+
return this.$store.state.optionsDeoVR.deovr.title_format
241+
},
242+
set (value) {
243+
this.$store.state.optionsDeoVR.deovr.title_format = value
244+
}
245+
},
225246
boundIp: {
226247
get () {
227248
return this.$store.state.optionsDeoVR.deovr.boundIp

0 commit comments

Comments
 (0)