mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
added support for image orientation filter (#4404)
* added support for image orientation filter * Add orientation filtering to scenes --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -169,3 +169,7 @@ type PhashDistanceCriterionInput struct {
|
||||
Modifier CriterionModifier `json:"modifier"`
|
||||
Distance *int `json:"distance"`
|
||||
}
|
||||
|
||||
type OrientationCriterionInput struct {
|
||||
Value []OrientationEnum `json:"value"`
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ type ImageFilterType struct {
|
||||
OCounter *IntCriterionInput `json:"o_counter"`
|
||||
// Filter by resolution
|
||||
Resolution *ResolutionCriterionInput `json:"resolution"`
|
||||
// Filter by landscape/portrait
|
||||
Orientation *OrientationCriterionInput `json:"orientation"`
|
||||
// Filter to only include images missing this property
|
||||
IsMissing *string `json:"is_missing"`
|
||||
// Filter to only include images with this studio
|
||||
|
||||
17
pkg/models/orientation.go
Normal file
17
pkg/models/orientation.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
type OrientationEnum string
|
||||
|
||||
const (
|
||||
OrientationLandscape OrientationEnum = "LANDSCAPE"
|
||||
OrientationPortrait OrientationEnum = "PORTRAIT"
|
||||
OrientationSquare OrientationEnum = "SQUARE"
|
||||
)
|
||||
|
||||
func (e OrientationEnum) IsValid() bool {
|
||||
switch e {
|
||||
case OrientationLandscape, OrientationPortrait, OrientationSquare:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -39,6 +39,8 @@ type SceneFilterType struct {
|
||||
Duplicated *PHashDuplicationCriterionInput `json:"duplicated"`
|
||||
// Filter by resolution
|
||||
Resolution *ResolutionCriterionInput `json:"resolution"`
|
||||
// Filter by orientation
|
||||
Orientation *OrientationCriterionInput `json:"orientation"`
|
||||
// Filter by framerate
|
||||
Framerate *IntCriterionInput `json:"framerate"`
|
||||
// Filter by video codec
|
||||
|
||||
43
pkg/sqlite/criterion_handlers.go
Normal file
43
pkg/sqlite/criterion_handlers.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
// shared criterion handlers go here
|
||||
|
||||
func orientationCriterionHandler(orientation *models.OrientationCriterionInput, heightColumn string, widthColumn string, addJoinFn func(f *filterBuilder)) criterionHandlerFunc {
|
||||
return func(ctx context.Context, f *filterBuilder) {
|
||||
if orientation != nil {
|
||||
if addJoinFn != nil {
|
||||
addJoinFn(f)
|
||||
}
|
||||
|
||||
var clauses []sqlClause
|
||||
|
||||
for _, v := range orientation.Value {
|
||||
// width mod height
|
||||
mod := ""
|
||||
switch v {
|
||||
case models.OrientationPortrait:
|
||||
mod = "<"
|
||||
case models.OrientationLandscape:
|
||||
mod = ">"
|
||||
case models.OrientationSquare:
|
||||
mod = "="
|
||||
}
|
||||
|
||||
if mod != "" {
|
||||
clauses = append(clauses, makeClause(fmt.Sprintf("%s %s %s", widthColumn, mod, heightColumn)))
|
||||
}
|
||||
}
|
||||
|
||||
if len(clauses) > 0 {
|
||||
f.whereClauses = append(f.whereClauses, orClauses(clauses...))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,6 +709,7 @@ func (qb *ImageStore) makeFilter(ctx context.Context, imageFilter *models.ImageF
|
||||
query.handleCriterion(ctx, imageURLsCriterionHandler(imageFilter.URL))
|
||||
|
||||
query.handleCriterion(ctx, resolutionCriterionHandler(imageFilter.Resolution, "image_files.height", "image_files.width", qb.addImageFilesTable))
|
||||
query.handleCriterion(ctx, orientationCriterionHandler(imageFilter.Orientation, "image_files.height", "image_files.width", qb.addImageFilesTable))
|
||||
query.handleCriterion(ctx, imageIsMissingCriterionHandler(qb, imageFilter.IsMissing))
|
||||
|
||||
query.handleCriterion(ctx, imageTagsCriterionHandler(qb, imageFilter.Tags))
|
||||
|
||||
@@ -982,6 +982,7 @@ func (qb *SceneStore) makeFilter(ctx context.Context, sceneFilter *models.SceneF
|
||||
|
||||
query.handleCriterion(ctx, floatIntCriterionHandler(sceneFilter.Duration, "video_files.duration", qb.addVideoFilesTable))
|
||||
query.handleCriterion(ctx, resolutionCriterionHandler(sceneFilter.Resolution, "video_files.height", "video_files.width", qb.addVideoFilesTable))
|
||||
query.handleCriterion(ctx, orientationCriterionHandler(sceneFilter.Orientation, "video_files.height", "video_files.width", qb.addVideoFilesTable))
|
||||
query.handleCriterion(ctx, floatIntCriterionHandler(sceneFilter.Framerate, "ROUND(video_files.frame_rate)", qb.addVideoFilesTable))
|
||||
query.handleCriterion(ctx, codecCriterionHandler(sceneFilter.VideoCodec, "video_files.video_codec", qb.addVideoFilesTable))
|
||||
query.handleCriterion(ctx, codecCriterionHandler(sceneFilter.AudioCodec, "video_files.audio_codec", qb.addVideoFilesTable))
|
||||
|
||||
Reference in New Issue
Block a user