Skip to content

Commit

Permalink
Initial support for funscript files
Browse files Browse the repository at this point in the history
  • Loading branch information
cld9x committed Feb 28, 2021
1 parent 1a2f8c8 commit d9aeff2
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 111 deletions.
64 changes: 38 additions & 26 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func setDeoPlayerHost(req *restful.Request) {
if deoIP != session.DeoPlayerHost {
common.Log.Infof("DeoVR Player connecting from %v", deoIP)
session.DeoPlayerHost = deoIP
session.DeoRequestHost = "http://" + req.Request.Host
}
}

Expand Down Expand Up @@ -198,8 +199,6 @@ func (i DeoVRResource) getDeoFile(req *restful.Request, resp *restful.Response)
return
}

baseURL := "http://" + req.Request.Host

var file models.File
db.Where(&models.File{ID: uint(fileId)}).First(&file)

Expand All @@ -214,7 +213,7 @@ func (i DeoVRResource) getDeoFile(req *restful.Request, resp *restful.Response)
Height: height,
Width: width,
Size: file.Size,
URL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", baseURL, file.ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
URL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", session.DeoRequestHost, file.ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
},
},
})
Expand All @@ -225,7 +224,7 @@ func (i DeoVRResource) getDeoFile(req *restful.Request, resp *restful.Response)
Description: file.Filename,
Title: file.Filename,
IsFavorite: false,
ThumbnailURL: baseURL + "/ui/images/blank.png",
ThumbnailURL: session.DeoRequestHost + "/ui/images/blank.png",
Is3D: true,
Encodings: sources,
VideoLength: int(file.VideoDuration),
Expand All @@ -239,19 +238,25 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
return
}

sceneID := req.PathParameter("scene-id")
if sceneID == "" {
return
}

setDeoPlayerHost(req)

db, _ := models.GetDB()
defer db.Close()

var scene models.Scene
db.Preload("Cast").
err := db.Preload("Cast").
Preload("Tags").
Preload("Files").
Preload("Cuepoints").
Where(&models.Scene{SceneID: req.PathParameter("scene-id")}).First(&scene)

baseURL := "http://" + req.Request.Host
Where("id = ?", sceneID).First(&scene).Error
if err != nil {
log.Error(err)
return
}

var stereoMode string
var screenType string
Expand All @@ -275,24 +280,31 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
var videoLength float64

var sources []DeoSceneEncoding
for i := range scene.Files {
var height = scene.Files[i].VideoHeight
var width = scene.Files[i].VideoWidth
var videoFiles []models.File
videoFiles, err = scene.GetVideoFiles()
if err != nil {
log.Error(err)
return
}

for i, file := range videoFiles {
var height = file.VideoHeight
var width = file.VideoWidth

sources = append(sources, DeoSceneEncoding{
Name: fmt.Sprintf("File %v/%v %vp - %v", i+1, len(scene.Files), scene.Files[i].VideoHeight, humanize.Bytes(uint64(scene.Files[i].Size))),
Name: fmt.Sprintf("File %v/%v %vp - %v", i+1, len(videoFiles), file.VideoHeight, humanize.Bytes(uint64(file.Size))),
VideoSources: []DeoSceneVideoSource{
{
Resolution: height,
Height: height,
Width: width,
Size: scene.Files[i].Size,
URL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", baseURL, scene.Files[i].ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
Size: file.Size,
URL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", session.DeoRequestHost, file.ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
},
},
})

videoLength = scene.Files[i].VideoDuration
videoLength = file.VideoDuration
}

var cuepoints []DeoSceneTimestamp
Expand All @@ -303,12 +315,12 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
})
}

if scene.Files[0].VideoProjection == "180_sbs" {
if videoFiles[0].VideoProjection == "180_sbs" {
stereoMode = "sbs"
screenType = "dome"
}

if scene.Files[0].VideoProjection == "360_tb" {
if videoFiles[0].VideoProjection == "360_tb" {
stereoMode = "tb"
screenType = "sphere"
}
Expand All @@ -325,7 +337,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
RatingAvg: scene.StarRating,
FullVideoReady: true,
FullAccess: true,
ThumbnailURL: baseURL + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1),
ThumbnailURL: session.DeoRequestHost + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1),
StereoMode: stereoMode,
Is3D: true,
ScreenType: screenType,
Expand All @@ -335,7 +347,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
}

if scene.HasVideoPreview {
deoScene.VideoPreview = fmt.Sprintf("%v/api/dms/preview/%v", baseURL, scene.SceneID)
deoScene.VideoPreview = fmt.Sprintf("%v/api/dms/preview/%v", session.DeoRequestHost, scene.SceneID)
}

resp.WriteHeaderAndEntity(http.StatusOK, deoScene)
Expand Down Expand Up @@ -392,23 +404,23 @@ func (i DeoVRResource) getDeoLibrary(req *restful.Request, resp *restful.Respons
}

func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem {
baseURL := "http://" + req.Request.Host
setDeoPlayerHost(req)

list := make([]DeoListItem, 0)
for i := range scenes {
item := DeoListItem{
Title: scenes[i].Title,
VideoLength: scenes[i].Duration * 60,
ThumbnailURL: baseURL + "/img/700x/" + strings.Replace(scenes[i].CoverURL, "://", ":/", -1),
VideoURL: baseURL + "/deovr/" + scenes[i].SceneID,
ThumbnailURL: fmt.Sprintf("%v/img/700x/%v", session.DeoRequestHost, strings.Replace(scenes[i].CoverURL, "://", ":/", -1)),
VideoURL: fmt.Sprintf("%v/deovr/%v", session.DeoRequestHost, scenes[i].ID),
}
list = append(list, item)
}
return list
}

func filesToDeoList(req *restful.Request, files []models.File) []DeoListItem {
baseURL := "http://" + req.Request.Host
setDeoPlayerHost(req)

list := make([]DeoListItem, 0)
for i := range files {
Expand All @@ -420,8 +432,8 @@ func filesToDeoList(req *restful.Request, files []models.File) []DeoListItem {
item := DeoListItem{
Title: files[i].Filename,
VideoLength: int(files[i].VideoDuration),
ThumbnailURL: baseURL + "/ui/images/blank.png",
VideoURL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", baseURL, files[i].ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
ThumbnailURL: session.DeoRequestHost + "/ui/images/blank.png",
VideoURL: fmt.Sprintf("%v/api/dms/file/%v?dnt=%v", session.DeoRequestHost, files[i].ID, strconv.FormatBool(config.Config.Interfaces.DeoVR.RemoteEnabled)),
}
list = append(list, item)
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ func (i FilesResource) matchFile(req *restful.Request, resp *restful.Response) {
models.AddAction(scene.SceneID, "match", "filenames_arr", scene.FilenamesArr)

// Finally, update scene available/accessible status
scene.IsAvailable = true
scene.AddedDate = f.CreatedTime
if f.Exists() {
scene.IsAccessible = true
}
scene.Save()
scene.UpdateStatus()

resp.WriteHeaderAndEntity(http.StatusOK, nil)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ func Migrate() {
return tx.AutoMigrate(&models.Scene{}).Error
},
},
{
ID: "0018-added-file-type",
Migrate: func(tx *gorm.DB) error {
err := tx.AutoMigrate(&models.File{}).Error

var files []models.File
db.Find(&files)
for _, file := range files {
file.Type = "video"
file.Save()
}
return err
},
},
{
ID: "0019-scene-is-scripted",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&models.Scene{}).Error
},
},
})

if err := m.Migrate(); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/models/model_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type File struct {
CreatedTime time.Time `json:"created_time"`
UpdatedTime time.Time `json:"updated_time"`

SceneID uint `json:"scene_id"`
Scene Scene `json:"-"`
Type string `json:"type"`
SceneID uint `json:"scene_id"`
Scene Scene `json:"-"`

VideoWidth int `json:"video_width"`
VideoHeight int `json:"video_height"`
Expand Down
74 changes: 57 additions & 17 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Scene struct {
IsAvailable bool `json:"is_available" gorm:"default:false"`
IsAccessible bool `json:"is_accessible" gorm:"default:false"`
IsWatched bool `json:"is_watched" gorm:"default:false"`
IsScripted bool `json:"is_scripted" gorm:"default:false"`
Cuepoints []SceneCuepoint `json:"cuepoints"`
History []History `json:"history"`
AddedDate time.Time `json:"added_date"`
Expand Down Expand Up @@ -179,6 +180,16 @@ func (o *Scene) GetFiles() ([]File, error) {
return files, nil
}

func (o *Scene) GetVideoFiles() ([]File, error) {
db, _ := GetDB()
defer db.Close()

var files []File
db.Preload("Volume").Where("scene_id = ? AND type = ?", o.ID, "video").Find(&files)

return files, nil
}

func (o *Scene) PreviewExists() bool {
if _, err := os.Stat(filepath.Join(common.VideoPreviewDir, fmt.Sprintf("%v.mp4", o.SceneID))); os.IsNotExist(err) {
return false
Expand All @@ -194,29 +205,35 @@ func (o *Scene) UpdateStatus() {
}

changed := false
scripts := 0
videos := 0

if len(files) > 0 {
if !o.IsAvailable {
o.IsAvailable = true
changed = true
}

var newestFileDate time.Time
var totalFileSize int64
for j := range files {
totalFileSize = totalFileSize + files[j].Size
if files[j].Exists() {
if files[j].CreatedTime.After(newestFileDate) || newestFileDate.IsZero() {
newestFileDate = files[j].CreatedTime
}
if !o.IsAccessible {
o.IsAccessible = true
changed = true
}
} else {
if o.IsAccessible {
o.IsAccessible = false
changed = true

if files[j].Type == "script" {
scripts = scripts + 1
}

if files[j].Type == "video" {
videos = videos + 1

if files[j].Exists() {
if files[j].CreatedTime.After(newestFileDate) || newestFileDate.IsZero() {
newestFileDate = files[j].CreatedTime
}
if !o.IsAccessible {
o.IsAccessible = true
changed = true
}
} else {
if o.IsAccessible {
o.IsAccessible = false
changed = true
}
}
}
}
Expand All @@ -226,6 +243,26 @@ func (o *Scene) UpdateStatus() {
changed = true
}

if scripts > 0 && o.IsScripted == false {
o.IsScripted = true
changed = true
}

if scripts == 0 && o.IsScripted == true {
o.IsScripted = false
changed = true
}

if videos > 0 && o.IsAvailable == false {
o.IsAvailable = true
changed = true
}

if videos == 0 && o.IsAvailable == true {
o.IsAvailable = false
changed = true
}

if !newestFileDate.Equal(o.AddedDate) && !newestFileDate.IsZero() {
o.AddedDate = newestFileDate
changed = true
Expand Down Expand Up @@ -405,6 +442,9 @@ func QueryScenes(r RequestSceneList, enablePreload bool) ResponseSceneList {
if i.OrElse("") == "favourite" {
tx = tx.Where("favourite = ?", true)
}
if i.OrElse("") == "scripted" {
tx = tx.Where("is_scripted = ?", true)
}
}

var sites []string
Expand Down
4 changes: 3 additions & 1 deletion pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"
"strconv"
"strings"
"time"

"github.com/posthog/posthog-go"
Expand Down Expand Up @@ -63,7 +64,8 @@ func TrackSessionFromRemote(packet DeoPacket) {
if err != nil {
return
}
tmpCurrentFileID, err := strconv.Atoi(path.Base(tmpPath.Path))
tmp := strings.Split(tmpPath.Path, "/")
tmpCurrentFileID, err := strconv.Atoi(tmp[len(tmp)-2])
if err != nil {
return
}
Expand Down
Loading

0 comments on commit d9aeff2

Please sign in to comment.