Skip to content

Commit ab0dba1

Browse files
Configurable title format for DeoVR
1 parent c067a49 commit ab0dba1

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
@@ -346,7 +346,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
346346
Height: height,
347347
Width: width,
348348
Size: file.Size,
349-
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(), dnt),
349+
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
350350
},
351351
},
352352
}
@@ -443,11 +443,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
443443
}
444444
}
445445

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

449449
if scene.IsScripted {
450-
title = scene.GetFunscriptTitle()
450+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
451451
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
452452
thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
453453
}
@@ -554,9 +554,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem
554554
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
555555
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
556556
}
557-
558557
item := DeoListItem{
559-
Title: scenes[i].Title,
558+
Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat),
560559
VideoLength: scenes[i].Duration * 60,
561560
ThumbnailURL: thumbnailURL,
562561
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
@@ -326,7 +326,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
326326
Height: height,
327327
Width: width,
328328
Size: file.Size,
329-
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(), dnt),
329+
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
330330
},
331331
},
332332
}
@@ -616,7 +616,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
616616
thumbnailURL := "http://" + req.Request.Host + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
617617

618618
if scene.IsScripted {
619-
title = scene.GetFunscriptTitle()
619+
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
620620
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
621621
thumbnailURL = "http://" + req.Request.Host + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
622622
}

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"`
@@ -309,6 +310,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
309310
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
310311
config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime
311312
config.Config.Interfaces.DeoVR.Username = r.Username
313+
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
312314
config.Config.Interfaces.Heresphere.AllowFileDeletes = r.AllowFileDeletes
313315
config.Config.Interfaces.Heresphere.AllowRatingUpdates = r.AllowRatingUpdates
314316
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"
@@ -183,12 +185,32 @@ func (o *Scene) GetIfExistURL(u string) error {
183185
Where(&Scene{SceneURL: u}).First(o).Error
184186
}
185187

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

188210
// first make the title filename safe
189211
var re = regexp.MustCompile(`[?/\<>|]`)
190212

191-
title := o.Title
213+
title := o.GetDeoFormattedTitle(titleFormat)
192214
// Colons are pretty common in titles, so we use a unicode alternative
193215
title = strings.ReplaceAll(title, ":", "꞉")
194216
// 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: {
@@ -45,6 +46,7 @@ const actions = {
4546
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
4647
state.deovr.username = data.config.interfaces.deovr.username
4748
state.deovr.password = data.config.interfaces.deovr.password
49+
state.deovr.title_format = data.config.interfaces.deovr.title_format
4850
state.deovr.boundIp = data.currentState.server.bound_ip
4951
state.heresphere.allow_file_deletes = data.config.interfaces.heresphere.allow_file_deletes
5052
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
@@ -111,6 +111,19 @@
111111
</b-field>
112112
</b-tooltip>
113113
</div>
114+
<hr/>
115+
<div class="block">
116+
<b-field label="Title Format">
117+
<b-input v-model="titleFormat"></b-input>
118+
</b-field>
119+
<p>
120+
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>.
121+
Examples:
122+
</p>
123+
<ul>
124+
<pre v-pre><li>{{.Studio}} - {{.Title}}</li><li>{{.Title}} ({{.ReleaseDate.Format "2006"}})</li></pre>
125+
</ul>
126+
</div>
114127
</div>
115128
</section>
116129
</div>
@@ -375,6 +388,14 @@ export default {
375388
this.$store.state.optionsDeoVR.deovr.password = value
376389
}
377390
},
391+
titleFormat: {
392+
get () {
393+
return this.$store.state.optionsDeoVR.deovr.title_format
394+
},
395+
set (value) {
396+
this.$store.state.optionsDeoVR.deovr.title_format = value
397+
}
398+
},
378399
boundIp: {
379400
get () {
380401
return this.$store.state.optionsDeoVR.deovr.boundIp

0 commit comments

Comments
 (0)