Skip to content

Commit

Permalink
Add codec filters (stashapp#3843)
Browse files Browse the repository at this point in the history
* Add video_codec and audio_codec filter criteria
* Add Audio Codec and Video Codec UI filters
  • Loading branch information
plato178 authored Jul 11, 2023
1 parent 93b41fb commit f0d901a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ input SceneFilterType {
duplicated: PHashDuplicationCriterionInput
"""Filter by resolution"""
resolution: ResolutionCriterionInput
"""Filter by video codec"""
video_codec: StringCriterionInput
"""Filter by audio codec"""
audio_codec: StringCriterionInput
"""Filter by duration (in seconds)"""
duration: IntCriterionInput
"""Filter to only include scenes which have markers. `true` or `false`"""
Expand Down
4 changes: 4 additions & 0 deletions pkg/models/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type SceneFilterType struct {
Duplicated *PHashDuplicationCriterionInput `json:"duplicated"`
// Filter by resolution
Resolution *ResolutionCriterionInput `json:"resolution"`
// Filter by video codec
VideoCodec *StringCriterionInput `json:"video_codec"`
// Filter by audio codec
AudioCodec *StringCriterionInput `json:"audio_codec"`
// Filter by duration (in seconds)
Duration *IntCriterionInput `json:"duration"`
// Filter to only include scenes which have markers. `true` or `false`
Expand Down
15 changes: 15 additions & 0 deletions pkg/sqlite/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ 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, codecCriterionHandler(sceneFilter.VideoCodec, "video_files.video_codec", qb.addVideoFilesTable))
query.handleCriterion(ctx, codecCriterionHandler(sceneFilter.AudioCodec, "video_files.audio_codec", qb.addVideoFilesTable))

query.handleCriterion(ctx, hasMarkersCriterionHandler(sceneFilter.HasMarkers))
query.handleCriterion(ctx, sceneIsMissingCriterionHandler(qb, sceneFilter.IsMissing))
query.handleCriterion(ctx, stringCriterionHandler(sceneFilter.URL, "scenes.url"))
Expand Down Expand Up @@ -1201,6 +1204,18 @@ func resolutionCriterionHandler(resolution *models.ResolutionCriterionInput, hei
}
}

func codecCriterionHandler(codec *models.StringCriterionInput, codecColumn string, addJoinFn func(f *filterBuilder)) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if codec != nil {
if addJoinFn != nil {
addJoinFn(f)
}

stringCriterionHandler(codec, codecColumn)(ctx, f)
}
}
}

func hasMarkersCriterionHandler(hasMarkers *string) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if hasMarkers != nil {
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"also_known_as": "Also known as",
"appears_with": "Appears With",
"ascending": "Ascending",
"audio_codec": "Audio Codec",
"average_resolution": "Average Resolution",
"between_and": "and",
"birth_year": "Birth Year",
Expand Down Expand Up @@ -1259,6 +1260,7 @@
"required": "${path} is a required field"
},
"videos": "Videos",
"video_codec": "Video Codec",
"view_all": "View All",
"weight": "Weight",
"weight_kg": "Weight (kg)",
Expand Down
4 changes: 4 additions & 0 deletions ui/v2.5/src/models/list-filter/criteria/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export function makeCriteria(
return new ResolutionCriterion();
case "average_resolution":
return new AverageResolutionCriterion();
case "video_codec":
return new StringCriterion(new StringCriterionOption(type, type));
case "audio_codec":
return new StringCriterion(new StringCriterionOption(type, type));
case "resume_time":
case "duration":
case "play_duration":
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/models/list-filter/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const criterionOptions = [
new NullNumberCriterionOption("rating", "rating100"),
createMandatoryNumberCriterionOption("o_counter"),
ResolutionCriterionOption,
createStringCriterionOption("video_codec"),
createStringCriterionOption("audio_codec"),
createMandatoryNumberCriterionOption("duration"),
createMandatoryNumberCriterionOption("resume_time"),
createMandatoryNumberCriterionOption("play_duration"),
Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/models/list-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export type CriterionType =
| "o_counter"
| "resolution"
| "average_resolution"
| "video_codec"
| "audio_codec"
| "duration"
| "favorite"
| "hasMarkers"
Expand Down

0 comments on commit f0d901a

Please sign in to comment.