Skip to content

Commit f4bf739

Browse files
Configurable title format for DeoVR
1 parent 6e97f8e commit f4bf739

File tree

8 files changed

+59
-11
lines changed

8 files changed

+59
-11
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
@@ -318,7 +318,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
318318
Height: height,
319319
Width: width,
320320
Size: file.Size,
321-
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(), dnt),
321+
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
322322
},
323323
},
324324
}
@@ -540,7 +540,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
540540
thumbnailURL := "http://" + req.Request.Host + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
541541

542542
if scene.IsScripted {
543-
title = scene.GetFunscriptTitle()
543+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
544544
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
545545
thumbnailURL = "http://" + req.Request.Host + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
546546
}

pkg/api/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type RequestSaveOptionsDeoVR struct {
6666
RemoteEnabled bool `json:"remote_enabled"`
6767
TrackWatchTime bool `json:"track_watch_time"`
6868
RenderHeatmaps bool `json:"render_heatmaps"`
69+
TitleFormat string `json:"title_format"`
6970
AllowFileDeletes bool `json:"allow_file_deletes"`
7071
AllowRatingUpdates bool `json:"allow_rating_updates"`
7172
AllowFavoriteUpdates bool `json:"allow_favorite_updates"`
@@ -305,6 +306,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
305306
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
306307
config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime
307308
config.Config.Interfaces.DeoVR.Username = r.Username
309+
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
308310
config.Config.Interfaces.Heresphere.AllowFileDeletes = r.AllowFileDeletes
309311
config.Config.Interfaces.Heresphere.AllowRatingUpdates = r.AllowRatingUpdates
310312
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
@@ -58,6 +58,7 @@ type ObjectConfig struct {
5858
RemoteEnabled bool `default:"false" json:"remote_enabled"`
5959
Username string `default:"" json:"username"`
6060
Password string `default:"" json:"password"`
61+
TitleFormat string `default:"{{.Title}}" json:"title_format"`
6162
} `json:"deovr"`
6263
Heresphere struct {
6364
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,13 +1,15 @@
11
package models
22

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

1315
"github.com/araddon/dateparse"
@@ -177,12 +179,32 @@ func (o *Scene) GetIfExistURL(u string) error {
177179
Where(&Scene{SceneURL: u}).First(o).Error
178180
}
179181

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

182204
// first make the title filename safe
183205
var re = regexp.MustCompile(`[?/\<>|]`)
184206

185-
title := o.Title
207+
title := o.GetDeoFormattedTitle(titleFormat)
186208
// Colons are pretty common in titles, so we use a unicode alternative
187209
title = strings.ReplaceAll(title, ":", "꞉")
188210
// 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: {
@@ -39,6 +40,7 @@ const actions = {
3940
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
4041
state.deovr.username = data.config.interfaces.deovr.username
4142
state.deovr.password = data.config.interfaces.deovr.password
43+
state.deovr.title_format = data.config.interfaces.deovr.title_format
4244
state.deovr.boundIp = data.currentState.server.bound_ip
4345
state.heresphere.allow_file_deletes = data.config.interfaces.heresphere.allow_file_deletes
4446
state.heresphere.allow_rating_updates = data.config.interfaces.heresphere.allow_rating_updates

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@
5353
</b-switch>
5454
</b-field>
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>
@@ -236,11 +249,19 @@ export default {
236249
this.$store.state.optionsDeoVR.deovr.password = value
237250
}
238251
},
252+
titleFormat: {
253+
get () {
254+
return this.$store.state.optionsDeoVR.deovr.title_format
255+
},
256+
set (value) {
257+
this.$store.state.optionsDeoVR.deovr.title_format = value
258+
}
259+
},
239260
boundIp: {
240261
get () {
241262
return this.$store.state.optionsDeoVR.deovr.boundIp
242263
}
243-
},
264+
},
244265
allowFileDeletions: {
245266
get () {
246267
return this.$store.state.optionsDeoVR.heresphere.allow_file_deletes

0 commit comments

Comments
 (0)