mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Remove streaming resolutions over max configured (#1187)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
||||||
"github.com/stashapp/stash/pkg/manager"
|
"github.com/stashapp/stash/pkg/manager"
|
||||||
|
"github.com/stashapp/stash/pkg/manager/config"
|
||||||
"github.com/stashapp/stash/pkg/models"
|
"github.com/stashapp/stash/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,5 +30,5 @@ func (r *queryResolver) SceneStreams(ctx context.Context, id *string) ([]*models
|
|||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
builder := urlbuilders.NewSceneURLBuilder(baseURL, scene.ID)
|
builder := urlbuilders.NewSceneURLBuilder(baseURL, scene.ID)
|
||||||
|
|
||||||
return manager.GetSceneStreamPaths(scene, builder.GetStreamURL())
|
return manager.GetSceneStreamPaths(scene, builder.GetStreamURL(), config.GetMaxStreamingTranscodeSize())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,7 +194,38 @@ func GetSceneFileContainer(scene *models.Scene) (ffmpeg.Container, error) {
|
|||||||
return container, nil
|
return container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSceneStreamPaths(scene *models.Scene, directStreamURL string) ([]*models.SceneStreamEndpoint, error) {
|
func includeSceneStreamPath(scene *models.Scene, streamingResolution models.StreamingResolutionEnum, maxStreamingTranscodeSize models.StreamingResolutionEnum) bool {
|
||||||
|
// convert StreamingResolutionEnum to ResolutionEnum so we can get the min
|
||||||
|
// resolution
|
||||||
|
convertedRes := models.ResolutionEnum(streamingResolution)
|
||||||
|
|
||||||
|
minResolution := int64(convertedRes.GetMinResolution())
|
||||||
|
sceneResolution := scene.GetMinResolution()
|
||||||
|
|
||||||
|
// don't include if scene resolution is smaller than the streamingResolution
|
||||||
|
if sceneResolution != 0 && sceneResolution < minResolution {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we always allow everything, then return true
|
||||||
|
if maxStreamingTranscodeSize == models.StreamingResolutionEnumOriginal {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert StreamingResolutionEnum to ResolutionEnum
|
||||||
|
maxStreamingResolution := models.ResolutionEnum(maxStreamingTranscodeSize)
|
||||||
|
return int64(maxStreamingResolution.GetMinResolution()) >= minResolution
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeStreamEndpoint(streamURL string, streamingResolution models.StreamingResolutionEnum, mimeType, label string) *models.SceneStreamEndpoint {
|
||||||
|
return &models.SceneStreamEndpoint{
|
||||||
|
URL: fmt.Sprintf("%s?resolution=%s", streamURL, streamingResolution.String()),
|
||||||
|
MimeType: &mimeType,
|
||||||
|
Label: &label,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSceneStreamPaths(scene *models.Scene, directStreamURL string, maxStreamingTranscodeSize models.StreamingResolutionEnum) ([]*models.SceneStreamEndpoint, error) {
|
||||||
if scene == nil {
|
if scene == nil {
|
||||||
return nil, fmt.Errorf("nil scene")
|
return nil, fmt.Errorf("nil scene")
|
||||||
}
|
}
|
||||||
@@ -248,107 +279,51 @@ func GetSceneStreamPaths(scene *models.Scene, directStreamURL string) ([]*models
|
|||||||
// Note: These have the wrong mime type intentionally to allow jwplayer to selection between mp4/webm
|
// Note: These have the wrong mime type intentionally to allow jwplayer to selection between mp4/webm
|
||||||
webmLabelFourK := "WEBM 4K (2160p)" // "FOUR_K"
|
webmLabelFourK := "WEBM 4K (2160p)" // "FOUR_K"
|
||||||
webmLabelFullHD := "WEBM Full HD (1080p)" // "FULL_HD"
|
webmLabelFullHD := "WEBM Full HD (1080p)" // "FULL_HD"
|
||||||
webmLabelStardardHD := "WEBM HD (720p)" // "STANDARD_HD"
|
webmLabelStandardHD := "WEBM HD (720p)" // "STANDARD_HD"
|
||||||
webmLabelStandard := "WEBM Standard (480p)" // "STANDARD"
|
webmLabelStandard := "WEBM Standard (480p)" // "STANDARD"
|
||||||
webmLabelLow := "WEBM Low (240p)" // "LOW"
|
webmLabelLow := "WEBM Low (240p)" // "LOW"
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 2160 {
|
|
||||||
new := models.SceneStreamEndpoint{
|
|
||||||
URL: directStreamURL + ".webm?resolution=FOUR_K",
|
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &webmLabelFourK,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 1080 {
|
|
||||||
new := models.SceneStreamEndpoint{
|
|
||||||
URL: directStreamURL + ".webm?resolution=FULL_HD",
|
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &webmLabelFullHD,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 720 {
|
|
||||||
new := models.SceneStreamEndpoint{
|
|
||||||
URL: directStreamURL + ".webm?resolution=STANDARD_HD",
|
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &webmLabelStardardHD,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 480 {
|
|
||||||
new := models.SceneStreamEndpoint{
|
|
||||||
URL: directStreamURL + ".webm?resolution=STANDARD",
|
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &webmLabelStandard,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 240 {
|
|
||||||
new := models.SceneStreamEndpoint{
|
|
||||||
URL: directStreamURL + ".webm?resolution=LOW",
|
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &webmLabelLow,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup up lower quality transcoding options (MP4)
|
// Setup up lower quality transcoding options (MP4)
|
||||||
mp4LabelFourK := "MP4 4K (2160p)" // "FOUR_K"
|
mp4LabelFourK := "MP4 4K (2160p)" // "FOUR_K"
|
||||||
mp4LabelFullHD := "MP4 Full HD (1080p)" // "FULL_HD"
|
mp4LabelFullHD := "MP4 Full HD (1080p)" // "FULL_HD"
|
||||||
mp4LabelStardardHD := "MP4 HD (720p)" // "STANDARD_HD"
|
mp4LabelStandardHD := "MP4 HD (720p)" // "STANDARD_HD"
|
||||||
mp4LabelStandard := "MP4 Standard (480p)" // "STANDARD"
|
mp4LabelStandard := "MP4 Standard (480p)" // "STANDARD"
|
||||||
mp4LabelLow := "MP4 Low (240p)" // "LOW"
|
mp4LabelLow := "MP4 Low (240p)" // "LOW"
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 2160 {
|
var webmStreams []*models.SceneStreamEndpoint
|
||||||
new := models.SceneStreamEndpoint{
|
var mp4Streams []*models.SceneStreamEndpoint
|
||||||
URL: directStreamURL + ".mp4?resolution=FOUR_K",
|
|
||||||
MimeType: &mimeMp4,
|
webmURL := directStreamURL + ".webm"
|
||||||
Label: &mp4LabelFourK,
|
mp4URL := directStreamURL + ".mp4"
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
if includeSceneStreamPath(scene, models.StreamingResolutionEnumFourK, maxStreamingTranscodeSize) {
|
||||||
|
webmStreams = append(webmStreams, makeStreamEndpoint(webmURL, models.StreamingResolutionEnumFourK, mimeMp4, webmLabelFourK))
|
||||||
|
mp4Streams = append(mp4Streams, makeStreamEndpoint(mp4URL, models.StreamingResolutionEnumFourK, mimeMp4, mp4LabelFourK))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 1080 {
|
if includeSceneStreamPath(scene, models.StreamingResolutionEnumFullHd, maxStreamingTranscodeSize) {
|
||||||
new := models.SceneStreamEndpoint{
|
webmStreams = append(webmStreams, makeStreamEndpoint(webmURL, models.StreamingResolutionEnumFullHd, mimeMp4, webmLabelFullHD))
|
||||||
URL: directStreamURL + ".mp4?resolution=FULL_HD",
|
mp4Streams = append(mp4Streams, makeStreamEndpoint(mp4URL, models.StreamingResolutionEnumFullHd, mimeMp4, mp4LabelFullHD))
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &mp4LabelFullHD,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 720 {
|
if includeSceneStreamPath(scene, models.StreamingResolutionEnumStandardHd, maxStreamingTranscodeSize) {
|
||||||
new := models.SceneStreamEndpoint{
|
webmStreams = append(webmStreams, makeStreamEndpoint(webmURL, models.StreamingResolutionEnumStandardHd, mimeMp4, webmLabelStandardHD))
|
||||||
URL: directStreamURL + ".mp4?resolution=STANDARD_HD",
|
mp4Streams = append(mp4Streams, makeStreamEndpoint(mp4URL, models.StreamingResolutionEnumStandardHd, mimeMp4, mp4LabelStandardHD))
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &mp4LabelStardardHD,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 480 {
|
if includeSceneStreamPath(scene, models.StreamingResolutionEnumStandard, maxStreamingTranscodeSize) {
|
||||||
new := models.SceneStreamEndpoint{
|
webmStreams = append(webmStreams, makeStreamEndpoint(webmURL, models.StreamingResolutionEnumStandard, mimeMp4, webmLabelStandard))
|
||||||
URL: directStreamURL + ".mp4?resolution=STANDARD",
|
mp4Streams = append(mp4Streams, makeStreamEndpoint(mp4URL, models.StreamingResolutionEnumStandard, mimeMp4, mp4LabelStandard))
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &mp4LabelStandard,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scene.Height.Valid || scene.Height.Int64 >= 240 {
|
if includeSceneStreamPath(scene, models.StreamingResolutionEnumLow, maxStreamingTranscodeSize) {
|
||||||
new := models.SceneStreamEndpoint{
|
webmStreams = append(webmStreams, makeStreamEndpoint(webmURL, models.StreamingResolutionEnumLow, mimeMp4, webmLabelLow))
|
||||||
URL: directStreamURL + ".mp4?resolution=LOW",
|
mp4Streams = append(mp4Streams, makeStreamEndpoint(mp4URL, models.StreamingResolutionEnumLow, mimeMp4, mp4LabelLow))
|
||||||
MimeType: &mimeMp4,
|
|
||||||
Label: &mp4LabelLow,
|
|
||||||
}
|
|
||||||
ret = append(ret, &new)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = append(ret, webmStreams...)
|
||||||
|
ret = append(ret, mp4Streams...)
|
||||||
|
|
||||||
defaultStreams := []*models.SceneStreamEndpoint{
|
defaultStreams := []*models.SceneStreamEndpoint{
|
||||||
{
|
{
|
||||||
URL: directStreamURL + ".webm",
|
URL: directStreamURL + ".webm",
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ func (s Scene) GetHash(hashAlgorithm HashAlgorithm) string {
|
|||||||
panic("unknown hash algorithm")
|
panic("unknown hash algorithm")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Scene) GetMinResolution() int64 {
|
||||||
|
if s.Width.Int64 < s.Height.Int64 {
|
||||||
|
return s.Width.Int64
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.Height.Int64
|
||||||
|
}
|
||||||
|
|
||||||
// SceneFileType represents the file metadata for a scene.
|
// SceneFileType represents the file metadata for a scene.
|
||||||
type SceneFileType struct {
|
type SceneFileType struct {
|
||||||
Size *string `graphql:"size" json:"size"`
|
Size *string `graphql:"size" json:"size"`
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
* Added Rescan button to scene, image, gallery details overflow button.
|
* Added Rescan button to scene, image, gallery details overflow button.
|
||||||
|
|
||||||
### 🐛 Bug fixes
|
### 🐛 Bug fixes
|
||||||
|
* Filter out streaming resolution options that are over the maximum streaming resolution.
|
||||||
* Fix `cover.jpg` not being detected as cover image when in sub-directory.
|
* Fix `cover.jpg` not being detected as cover image when in sub-directory.
|
||||||
* Fix scan re-associating galleries to the same scene.
|
* Fix scan re-associating galleries to the same scene.
|
||||||
* Fix SQL error when filtering galleries excluding performers or tags.
|
* Fix SQL error when filtering galleries excluding performers or tags.
|
||||||
|
|||||||
Reference in New Issue
Block a user