Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable title format for DeoVR #546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,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 @@ -443,11 +443,11 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
}
}

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 @@ -554,9 +554,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
4 changes: 2 additions & 2 deletions pkg/api/heresphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
Height: height,
Width: width,
Size: file.Size,
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(), dnt),
URL: fmt.Sprintf("http://%v/api/dms/file/%v/%v/%v", req.Request.Host, file.ID, scene.GetFunscriptTitle(config.Config.Interfaces.DeoVR.TitleFormat), dnt),
},
},
}
Expand Down Expand Up @@ -616,7 +616,7 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
thumbnailURL := "http://" + req.Request.Host + "/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 = "http://" + req.Request.Host + "/imghm/" + fmt.Sprint(scene.ID) + "/" + strings.Replace(scene.CoverURL, "://", ":/", -1)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type RequestSaveOptionsDeoVR struct {
RemoteEnabled bool `json:"remote_enabled"`
TrackWatchTime bool `json:"track_watch_time"`
RenderHeatmaps bool `json:"render_heatmaps"`
TitleFormat string `json:"title_format"`
AllowFileDeletes bool `json:"allow_file_deletes"`
AllowRatingUpdates bool `json:"allow_rating_updates"`
AllowFavoriteUpdates bool `json:"allow_favorite_updates"`
Expand Down Expand Up @@ -309,6 +310,7 @@ func (i ConfigResource) saveOptionsDeoVR(req *restful.Request, resp *restful.Res
config.Config.Interfaces.DeoVR.RemoteEnabled = r.RemoteEnabled
config.Config.Interfaces.DeoVR.TrackWatchTime = r.TrackWatchTime
config.Config.Interfaces.DeoVR.Username = r.Username
config.Config.Interfaces.DeoVR.TitleFormat = r.TitleFormat
config.Config.Interfaces.Heresphere.AllowFileDeletes = r.AllowFileDeletes
config.Config.Interfaces.Heresphere.AllowRatingUpdates = r.AllowRatingUpdates
config.Config.Interfaces.Heresphere.AllowFavoriteUpdates = r.AllowFavoriteUpdates
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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"`
Heresphere struct {
AllowFileDeletes bool `default:"false" json:"allow_file_deletes"`
Expand Down
26 changes: 24 additions & 2 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package models

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

"github.com/araddon/dateparse"
Expand Down Expand Up @@ -183,12 +185,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 @@ -10,6 +10,7 @@ const state = {
remote_enabled: false,
username: '',
password: '',
title_format: '',
boundIp: []
},
heresphere: {
Expand Down Expand Up @@ -45,6 +46,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.heresphere.allow_file_deletes = data.config.interfaces.heresphere.allow_file_deletes
state.heresphere.allow_rating_updates = data.config.interfaces.heresphere.allow_rating_updates
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 @@ -111,6 +111,19 @@
</b-field>
</b-tooltip>
</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 @@ -375,6 +388,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