2019-02-09 12:30:49 +00:00
|
|
|
package urlbuilders
|
|
|
|
|
2019-12-17 17:28:44 +00:00
|
|
|
import (
|
2021-04-12 01:05:49 +00:00
|
|
|
"fmt"
|
2022-10-09 23:11:51 +00:00
|
|
|
"net/url"
|
2019-12-17 17:28:44 +00:00
|
|
|
"strconv"
|
2023-04-19 03:01:32 +00:00
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-12-17 17:28:44 +00:00
|
|
|
)
|
2019-02-09 12:30:49 +00:00
|
|
|
|
2019-02-14 22:53:32 +00:00
|
|
|
type SceneURLBuilder struct {
|
2023-04-19 03:01:32 +00:00
|
|
|
BaseURL string
|
|
|
|
SceneID string
|
|
|
|
UpdatedAt string
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 03:01:32 +00:00
|
|
|
func NewSceneURLBuilder(baseURL string, scene *models.Scene) SceneURLBuilder {
|
2019-02-14 22:53:32 +00:00
|
|
|
return SceneURLBuilder{
|
2023-04-19 03:01:32 +00:00
|
|
|
BaseURL: baseURL,
|
|
|
|
SceneID: strconv.Itoa(scene.ID),
|
|
|
|
UpdatedAt: strconv.FormatInt(scene.UpdatedAt.Unix(), 10),
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 00:54:18 +00:00
|
|
|
func (b SceneURLBuilder) GetStreamURL(apiKey string) *url.URL {
|
2022-10-09 23:11:51 +00:00
|
|
|
u, err := url.Parse(fmt.Sprintf("%s/scene/%s/stream", b.BaseURL, b.SceneID))
|
|
|
|
if err != nil {
|
|
|
|
// shouldn't happen
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-03-10 00:54:18 +00:00
|
|
|
if apiKey != "" {
|
2022-10-09 23:11:51 +00:00
|
|
|
v := u.Query()
|
2023-03-10 00:54:18 +00:00
|
|
|
v.Set("apikey", apiKey)
|
2022-10-09 23:11:51 +00:00
|
|
|
u.RawQuery = v.Encode()
|
2021-04-12 01:05:49 +00:00
|
|
|
}
|
2022-10-09 23:11:51 +00:00
|
|
|
return u
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 22:53:32 +00:00
|
|
|
func (b SceneURLBuilder) GetStreamPreviewURL() string {
|
2019-02-09 12:30:49 +00:00
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/preview"
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:53:32 +00:00
|
|
|
func (b SceneURLBuilder) GetStreamPreviewImageURL() string {
|
2019-02-09 12:30:49 +00:00
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/webp"
|
|
|
|
}
|
|
|
|
|
2023-03-10 00:54:18 +00:00
|
|
|
func (b SceneURLBuilder) GetSpriteVTTURL(checksum string) string {
|
|
|
|
return b.BaseURL + "/scene/" + checksum + "_thumbs.vtt"
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2023-03-10 00:54:18 +00:00
|
|
|
func (b SceneURLBuilder) GetSpriteURL(checksum string) string {
|
|
|
|
return b.BaseURL + "/scene/" + checksum + "_sprite.jpg"
|
2021-04-11 23:04:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 03:01:32 +00:00
|
|
|
func (b SceneURLBuilder) GetScreenshotURL() string {
|
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/screenshot?t=" + b.UpdatedAt
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 22:45:45 +00:00
|
|
|
func (b SceneURLBuilder) GetChaptersVTTURL() string {
|
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/vtt/chapter"
|
|
|
|
}
|
|
|
|
|
2021-05-24 03:34:28 +00:00
|
|
|
func (b SceneURLBuilder) GetFunscriptURL() string {
|
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/funscript"
|
|
|
|
}
|
2021-12-13 02:41:07 +00:00
|
|
|
|
2022-05-06 01:59:28 +00:00
|
|
|
func (b SceneURLBuilder) GetCaptionURL() string {
|
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/caption"
|
|
|
|
}
|
|
|
|
|
2021-12-13 02:41:07 +00:00
|
|
|
func (b SceneURLBuilder) GetInteractiveHeatmapURL() string {
|
|
|
|
return b.BaseURL + "/scene/" + b.SceneID + "/interactive_heatmap"
|
|
|
|
}
|