Improved gallery cover lookup (#3391)

* Gallery cover lookup by regex in config.yml
* Added regex validation and an in-app manual entry
* Improved settings description + some translations
* Add changelog entry
This commit is contained in:
Ksrx01
2023-02-22 07:50:12 +00:00
committed by GitHub
parent 8b6f7db4ef
commit 2d528733ff
13 changed files with 60 additions and 13 deletions

View File

@@ -7,11 +7,6 @@ import (
"github.com/stashapp/stash/pkg/models"
)
const (
coverFilename = "cover.jpg"
coverFilenameSearchString = "%" + coverFilename
)
type Queryer interface {
Query(ctx context.Context, options models.ImageQueryOptions) (*models.ImageQueryResult, error)
}
@@ -102,9 +97,9 @@ func FindByGalleryID(ctx context.Context, r Queryer, galleryID int, sortBy strin
}, &findFilter)
}
func FindGalleryCover(ctx context.Context, r Queryer, galleryID int) (*models.Image, error) {
func FindGalleryCover(ctx context.Context, r Queryer, galleryID int, galleryCoverRegex string) (*models.Image, error) {
const useCoverJpg = true
img, err := findGalleryCover(ctx, r, galleryID, useCoverJpg)
img, err := findGalleryCover(ctx, r, galleryID, useCoverJpg, galleryCoverRegex)
if err != nil {
return nil, err
}
@@ -114,10 +109,10 @@ func FindGalleryCover(ctx context.Context, r Queryer, galleryID int) (*models.Im
}
// return the first image in the gallery
return findGalleryCover(ctx, r, galleryID, !useCoverJpg)
return findGalleryCover(ctx, r, galleryID, !useCoverJpg, galleryCoverRegex)
}
func findGalleryCover(ctx context.Context, r Queryer, galleryID int, useCoverJpg bool) (*models.Image, error) {
func findGalleryCover(ctx context.Context, r Queryer, galleryID int, useCoverJpg bool, galleryCoverRegex string) (*models.Image, error) {
// try to find cover.jpg in the gallery
perPage := 1
sortBy := "path"
@@ -138,8 +133,8 @@ func findGalleryCover(ctx context.Context, r Queryer, galleryID int, useCoverJpg
if useCoverJpg {
imageFilter.Path = &models.StringCriterionInput{
Value: coverFilenameSearchString,
Modifier: models.CriterionModifierEquals,
Value: "(?i)" + galleryCoverRegex,
Modifier: models.CriterionModifierMatchesRegex,
}
}