Skip to content

Commit

Permalink
Configurable title format for DeoVR
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMintChocolate committed Jul 26, 2021
1 parent a642907 commit e588277
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
9 changes: 4 additions & 5 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
Height: height,
Width: width,
Size: file.Size,
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(), dnt),
URL: fmt.Sprintf("%v/api/dms/file/%v/%v%v", session.DeoRequestHost, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
},
},
})
Expand Down Expand Up @@ -358,11 +358,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
screenType = "sphere"
}

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

if scene.IsScripted {
title = scene.GetFunscriptTitle()
title = scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat)
if config.Config.Interfaces.DeoVR.RenderHeatmaps {
thumbnailURL = session.DeoRequestHost + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
}
Expand Down Expand Up @@ -457,9 +457,8 @@ func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
}

item := DeoListItem{
Title: scenes[i].Title,
Title: scenes[i].GetDeoFormattedTitle(config.Config.Interfaces.DeoVR.TitleFormat),
VideoLength: scenes[i].Duration * 60,
ThumbnailURL: thumbnailURL,
VideoURL: fmt.Sprintf("%v/deovr/%v", session.DeoRequestHost, scenes[i].ID),
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type RequestSaveOptionsDeoVR struct {
Password string `json:"password"`
RemoteEnabled bool `json:"remote_enabled"`
RenderHeatmaps bool `json:"render_heatmaps"`
TitleFormat string `json:"title_format"`
}

type RequestSaveOptionsPreviews struct {
Expand Down Expand Up @@ -233,6 +234,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
config.Config.Interfaces.DeoVR.RenderHeatmaps = r.RenderHeatmaps
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
config.Config.Interfaces.DeoVR.Username = r.Username
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
if r.Password != config.Config.Interfaces.DeoVR.Password && r.Password != "" {
hash, _ := bcrypt.GenerateFromPassword([]byte(r.Password), bcrypt.DefaultCost)
config.Config.Interfaces.DeoVR.Password = string(hash)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ObjectConfig struct {
RemoteEnabled bool `default:"false" json:"remote_enabled"`
Username string `default:"" json:"username"`
Password string `default:"" json:"password"`
TitleFormat string `default:"{{.Title}}" json:"title_format"`
} `json:"deovr"`
} `json:"interfaces"`
Library struct {
Expand Down
26 changes: 24 additions & 2 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package models

import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"
"time"

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

func (o *Scene) GetFunscriptTitle() string {
func (scene *Scene) GetDeoFormattedTitle(titleFormat string) string {
customTitleTemplate, err := template.New("customTitleTemplate").Parse(titleFormat)
if err != nil {
common.Log.Warn(err)
customTitleTemplate, err = template.New("customTitleTemplate").Parse("{{.Title}}")
if err != nil {
return scene.Title
}
}
var tpl bytes.Buffer
title := scene.Title
err = customTitleTemplate.Execute(&tpl, scene)
if err == nil {
title = tpl.String()
} else {
common.Log.Warn(err)
}
return title
}

func (o *Scene) GetFunscriptTitle(titleFormat string) string {

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

title := o.Title
title := o.GetDeoFormattedTitle(titleFormat)
// Colons are pretty common in titles, so we use a unicode alternative
title = strings.ReplaceAll(title, ":", "꞉")
// all other unsafe characters get removed
Expand Down
3 changes: 2 additions & 1 deletion pkg/tasks/funscripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"

"github.com/xbapps/xbvr/pkg/config"
"github.com/xbapps/xbvr/pkg/models"
)

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

if err = AddFileToZip(zipWriter, file.GetPath(), funscriptName); err != nil {
log.Infof("Error when adding file to zip: %v (%s)", err, funscriptName)
Expand Down
2 changes: 2 additions & 0 deletions ui/src/store/optionsDeoVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const state = {
remote_enabled: false,
username: '',
password: '',
title_format: '',
boundIp: []
}
}
Expand All @@ -27,6 +28,7 @@ const actions = {
state.deovr.remote_enabled = data.config.interfaces.deovr.remote_enabled
state.deovr.username = data.config.interfaces.deovr.username
state.deovr.password = data.config.interfaces.deovr.password
state.deovr.title_format = data.config.interfaces.deovr.title_format
state.deovr.boundIp = data.currentState.server.bound_ip
state.loading = false
})
Expand Down
21 changes: 21 additions & 0 deletions ui/src/views/options/sections/InterfaceDeoVR.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
instructions in DeoVR documentation</a>.
</p>
</div>
<hr/>
<div class="block">
<b-field label="Title Format">
<b-input v-model="titleFormat"></b-input>
</b-field>
<p>
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>.
Examples:
</p>
<ul>
<pre v-pre><li>{{.Studio}} - {{.Title}}</li><li>{{.Title}} ({{.ReleaseDate.Format "2006"}})</li></pre>
</ul>
</div>
</div>
</section>
</div>
Expand Down Expand Up @@ -149,6 +162,14 @@ export default {
this.$store.state.optionsDeoVR.deovr.password = value
}
},
titleFormat: {
get () {
return this.$store.state.optionsDeoVR.deovr.title_format
},
set (value) {
this.$store.state.optionsDeoVR.deovr.title_format = value
}
},
boundIp: {
get () {
return this.$store.state.optionsDeoVR.deovr.boundIp
Expand Down

0 comments on commit e588277

Please sign in to comment.