Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vtt sprite generation ( issue #1033 ) #1035

Merged
merged 7 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require (
github.com/99designs/gqlgen v0.12.2
github.com/Yamashou/gqlgenc v0.0.0-20200902035953-4dbef3551953
github.com/antchfx/htmlquery v1.2.3
github.com/bmatcuk/doublestar/v2 v2.0.1
github.com/chromedp/cdproto v0.0.0-20200608134039-8a80cdaf865c
github.com/chromedp/chromedp v0.5.3
github.com/disintegration/imaging v1.6.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/bmatcuk/doublestar/v2 v2.0.1 h1:EFT91DmIMRcrUEcYUW7AqSAwKvNzP5+CoDmNVBbcQOU=
github.com/bmatcuk/doublestar/v2 v2.0.1/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down
9 changes: 6 additions & 3 deletions pkg/manager/generator_sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"sort"
"strings"

"github.com/bmatcuk/doublestar/v2"
"github.com/disintegration/imaging"
"github.com/fvbommel/sortorder"

"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/utils"
Expand Down Expand Up @@ -89,8 +89,11 @@ func (g *SpriteGenerator) generateSpriteImage(encoder *ffmpeg.Encoder) error {
}

// Combine all of the thumbnails into a sprite image
globPath := filepath.Join(instance.Paths.Generated.Tmp, fmt.Sprintf("thumbnail_%s_*.jpg", g.VideoChecksum))
imagePaths, _ := doublestar.Glob(globPath)
pattern := fmt.Sprintf("thumbnail_%s_.+\\.jpg$", g.VideoChecksum)
imagePaths, err := utils.MatchEntries(instance.Paths.Generated.Tmp, pattern)
if err != nil {
return err
}
sort.Sort(sortorder.Natural(imagePaths))
var images []image.Image
for _, imagePath := range imagePaths {
Expand Down
37 changes: 35 additions & 2 deletions pkg/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/user"
"path/filepath"
"regexp"

"github.com/h2non/filetype"
"github.com/h2non/filetype/types"
Expand Down Expand Up @@ -198,8 +199,8 @@ func WriteFile(path string, file []byte) error {
}

// GetIntraDir returns a string that can be added to filepath.Join to implement directory depth, "" on error
//eg given a pattern of 0af63ce3c99162e9df23a997f62621c5 and a depth of 2 length of 3
//returns 0af/63c or 0af\63c ( dependin on os) that can be later used like this filepath.Join(directory, intradir, basename)
// eg given a pattern of 0af63ce3c99162e9df23a997f62621c5 and a depth of 2 length of 3
// returns 0af/63c or 0af\63c ( dependin on os) that can be later used like this filepath.Join(directory, intradir, basename)
func GetIntraDir(pattern string, depth, length int) string {
if depth < 1 || length < 1 || (depth*length > len(pattern)) {
return ""
Expand Down Expand Up @@ -236,3 +237,35 @@ func ServeFileNoCache(w http.ResponseWriter, r *http.Request, filepath string) {

http.ServeFile(w, r, filepath)
}

// MatchEntries returns a string slice of the entries in directory dir which
// match the regexp pattern. On error an empty slice is returned
// MatchEntries isn't recursive, only the specific 'dir' is searched
// without being expanded.
func MatchEntries(dir, pattern string) ([]string, error) {
var res []string
var err error

re, err := regexp.Compile(pattern)
if err != nil {
return nil, err
}

f, err := os.Open(dir)
if err != nil {
return nil, err
}
defer f.Close()

files, err := f.Readdirnames(-1)
if err != nil {
return nil, err
}

for _, file := range files {
if re.Match([]byte(file)) {
res = append(res, filepath.Join(dir, file))
}
}
return res, err
}
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Changelog/versions/v050.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Support configurable number of threads for scanning and generation.

### 🐛 Bug fixes
* Fix sprite generation when generated path has special characters.
* Prevent studio from being set as its own parent
* Fixed performer scraper select overlapping search results
* Fix tag/studio images not being changed after update.
Expand Down
32 changes: 0 additions & 32 deletions vendor/github.com/bmatcuk/doublestar/v2/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/github.com/bmatcuk/doublestar/v2/.travis.yml

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/bmatcuk/doublestar/v2/LICENSE

This file was deleted.

142 changes: 0 additions & 142 deletions vendor/github.com/bmatcuk/doublestar/v2/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions vendor/github.com/bmatcuk/doublestar/v2/UPGRADING.md

This file was deleted.

Loading