diff --git a/Makefile b/Makefile index f99e435..81e1234 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +main: build + update: go get github.com/stashapp/stash@develop && \ go mod tidy @@ -6,35 +8,35 @@ update: windows-amd64: GOOS=windows GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-amd64.exe ./cmd/videohashes + go build -o dist/windows-amd64/videohashes.exe ./cmd/videohashes linux-amd64: GOOS=linux GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-amd64-linux ./cmd/videohashes + go build -o dist/linux-amd64/videohashes ./cmd/videohashes macos-amd64: GOOS=darwin GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-amd64-macos ./cmd/videohashes + go build -o dist/macos-amd64/videohashes ./cmd/videohashes windows-arm64: GOOS=windows GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-arm64.exe ./cmd/videohashes + go build -o dist/windows-arm64/videohashes.exe ./cmd/videohashes linux-arm64: GOOS=linux GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-arm64-linux ./cmd/videohashes + go build -o dist/linux-arm64/videohashes ./cmd/videohashes macos-arm64: GOOS=darwin GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-arm64-macos ./cmd/videohashes + go build -o dist/macos-arm64/videohashes ./cmd/videohashes windows-arm: GOOS=windows GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-arm.exe ./cmd/videohashes + go build -o dist/windows-arm/videohashes.exe ./cmd/videohashes linux-arm: GOOS=linux GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/videohashes-arm-linux ./cmd/videohashes + go build -o dist/linux-arm/videohashes ./cmd/videohashes build: windows-amd64 linux-amd64 macos-amd64 windows-arm64 linux-arm64 macos-arm64 windows-arm linux-arm @@ -43,35 +45,35 @@ build: windows-amd64 linux-amd64 macos-amd64 windows-arm64 linux-arm64 macos-arm duration-windows-amd64: GOOS=windows GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-amd64.exe ./cmd/duration + go build -o dist/windows-amd64/duration.exe ./cmd/duration duration-linux-amd64: GOOS=linux GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-amd64-linux ./cmd/duration + go build -o dist/linux-amd64/duration ./cmd/duration duration-macos-amd64: GOOS=darwin GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-amd64-macos ./cmd/duration + go build -o dist/macos-amd64/duration ./cmd/duration duration-windows-arm64: GOOS=windows GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-arm64.exe ./cmd/duration + go build -o dist/windows-arm64/duration.exe ./cmd/duration duration-linux-arm64: GOOS=linux GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-arm64-linux ./cmd/duration + go build -o dist/linux-arm64/duration ./cmd/duration duration-macos-arm64: GOOS=darwin GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-arm64-macos ./cmd/duration + go build -o dist/macos-arm64/duration ./cmd/duration duration-windows-arm: GOOS=windows GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-arm.exe ./cmd/duration + go build -o dist/windows-arm/duration.exe ./cmd/duration duration-linux-arm: GOOS=linux GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/duration-arm-linux ./cmd/duration + go build -o dist/linux-arm/duration ./cmd/duration duration-build: duration-windows-amd64 duration-linux-amd64 duration-macos-amd64 duration-windows-arm64 duration-linux-arm64 duration-macos-arm64 duration-windows-arm duration-linux-arm @@ -79,36 +81,36 @@ duration-build: duration-windows-amd64 duration-linux-amd64 duration-macos-amd64 phashcompare-windows-amd64: GOOS=windows GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-amd64.exe ./cmd/phashcompare + go build -o dist/windows-amd64/phashcompare.exe ./cmd/phashcompare phashcompare-linux-amd64: GOOS=linux GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-amd64-linux ./cmd/phashcompare + go build -o dist/linux-amd64/phashcompare ./cmd/phashcompare phashcompare-macos-amd64: GOOS=darwin GOARCH=amd64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-amd64-macos ./cmd/phashcompare + go build -o dist/macos-amd64/phashcompare ./cmd/phashcompare phashcompare-windows-arm64: GOOS=windows GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-arm64.exe ./cmd/phashcompare + go build -o dist/windows-arm64/phashcompare.exe ./cmd/phashcompare phashcompare-linux-arm64: GOOS=linux GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-arm64-linux ./cmd/phashcompare + go build -o dist/linux-arm64/phashcompare ./cmd/phashcompare phashcompare-macos-arm64: GOOS=darwin GOARCH=arm64 EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-arm64-macos ./cmd/phashcompare + go build -o dist/macos-arm64/phashcompare ./cmd/phashcompare phashcompare-windows-arm: GOOS=windows GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-arm.exe ./cmd/phashcompare + go build -o dist/windows-arm/phashcompare.exe ./cmd/phashcompare phashcompare-linux-arm: GOOS=linux GOARCH=arm EXTRA_LDFLAGS='-extldflags=-static -s -w' \ - go build -o dist/phashcompare-arm-linux ./cmd/phashcompare + go build -o dist/linux-arm/phashcompare ./cmd/phashcompare phashcompare-build: phashcompare-windows-amd64 phashcompare-linux-amd64 phashcompare-macos-amd64 phashcompare-windows-arm64 phashcompare-linux-arm64 phashcompare-macos-arm64 phashcompare-windows-arm phashcompare-linux-arm diff --git a/cmd/videohashes/result.go b/cmd/videohashes/result.go index 4d76e0a..4242e28 100644 --- a/cmd/videohashes/result.go +++ b/cmd/videohashes/result.go @@ -21,8 +21,8 @@ type Result struct { } func (r *Result) GeneratePHash(ffmpegPath string, ffprobePath string) error { - FFMPEG := ffmpeg.FFMpeg(ffmpegPath) - FFProbe := ffmpeg.FFProbe(ffprobePath) + FFMPEG := ffmpeg.NewEncoder(ffmpegPath) + FFProbe := ffmpeg.NewFFProbe(ffprobePath) videoProbe, err := FFProbe.NewVideoFile(r.videoPath) if err != nil { diff --git a/go.mod b/go.mod index a72f50d..3a4bb44 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,19 @@ module github.com/peolic/videohashes -go 1.18 +go 1.24.3 + +toolchain go1.24.5 require ( - github.com/corona10/goimagehash v1.0.3 - github.com/stashapp/stash v0.18.0 + github.com/corona10/goimagehash v1.1.0 + github.com/stashapp/stash v0.28.1 ) require ( - github.com/disintegration/imaging v1.6.0 // indirect + github.com/disintegration/imaging v1.6.2 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect - github.com/remeh/sizedwaitgroup v1.0.0 // indirect - github.com/sirupsen/logrus v1.8.1 // indirect - golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect - golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/zencoder/go-dash/v3 v3.0.2 // indirect + golang.org/x/image v0.18.0 // indirect + golang.org/x/sys v0.33.0 // indirect ) diff --git a/go.sum b/go.sum index 9b87c89..37be1ba 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,32 @@ -github.com/corona10/goimagehash v1.0.3 h1:NZM518aKLmoNluluhfHGxT3LGOnrojrxhGn63DR/CZA= -github.com/corona10/goimagehash v1.0.3/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI= +github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI= +github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/disintegration/imaging v1.6.0 h1:nVPXRUUQ36Z7MNf0O77UzgnOb1mkMMor7lmJMJXc/mA= -github.com/disintegration/imaging v1.6.0/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ= +github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= +github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/remeh/sizedwaitgroup v1.0.0 h1:VNGGFwNo/R5+MJBf6yrsr110p0m4/OX4S3DCy7Kyl5E= -github.com/remeh/sizedwaitgroup v1.0.0/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/stashapp/stash v0.18.0 h1:Na9yuiclrvHydkAuFMH2en59znSdCilndtXq0eYWgNI= -github.com/stashapp/stash v0.18.0/go.mod h1:/IBgG8WgU0Y96Tgb6RFn+RWLIxuEYjt53/hWPel72KM= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= -golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk= -golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs= -golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stashapp/stash v0.28.1 h1:X2lWxJirdjUeYPZNnDJOexhaB5dQ0gJ9PcbxYrQRdP4= +github.com/stashapp/stash v0.28.1/go.mod h1:XpKA7rTjhPFZuqdUJp56TWabBF60UcwBOAagHHmMl7c= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/zencoder/go-dash/v3 v3.0.2 h1:oP1+dOh+Gp57PkvdCyMfbHtrHaxfl3w4kR3KBBbuqQE= +github.com/zencoder/go-dash/v3 v3.0.2/go.mod h1:30R5bKy1aUYY45yesjtZ9l8trNc2TwNqbS17WVQmCzk= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/common.go b/internal/common.go index d11fec6..eccdbdd 100644 --- a/internal/common.go +++ b/internal/common.go @@ -3,9 +3,10 @@ package internal import ( "fmt" "os" + "path/filepath" "github.com/stashapp/stash/pkg/ffmpeg" - "github.com/stashapp/stash/pkg/file" + "github.com/stashapp/stash/pkg/models" ) func ValidFile(filePath string) error { @@ -19,18 +20,27 @@ func ValidFile(filePath string) error { } func GetFFPaths() (string, string) { - var paths []string + var ffmpegPath, ffprobePath string + + ex, err := os.Executable() + if err != nil { + panic(err) + } + exPath := filepath.Dir(ex) cwd, err := os.Getwd() - if err == nil { - paths = append(paths, cwd) + if err != nil { + panic(err) } - return ffmpeg.GetPaths(paths) + ffmpegPath = ffmpeg.ResolveFFMpeg(exPath, cwd) + ffprobePath = ffmpeg.ResolveFFProbe(exPath, cwd) + + return ffmpegPath, ffprobePath } func GetDuration(ffprobePath string, videoPath string) int { - FFProbe := ffmpeg.FFProbe(ffprobePath) + FFProbe := ffmpeg.NewFFProbe(ffprobePath) videoProbe, err := FFProbe.NewVideoFile(videoPath) if err != nil { @@ -49,14 +59,14 @@ func FormatDuration(duration int) string { } // Based on https://github.com/stashapp/stash/blob/8b59a3b01418/pkg/file/video/scan.go#L17 -func ProbeResultToVideoFile(videoProbe *ffmpeg.VideoFile, videoPath string) (*file.VideoFile, error) { +func ProbeResultToVideoFile(videoProbe *ffmpeg.VideoFile, videoPath string) (*models.VideoFile, error) { container, err := ffmpeg.MatchContainer(videoProbe.Container, videoPath) if err != nil { return nil, fmt.Errorf("matching container for %q: %w", videoPath, err) } - videoFile := &file.VideoFile{ - BaseFile: &file.BaseFile{ + videoFile := &models.VideoFile{ + BaseFile: &models.BaseFile{ Path: videoPath, }, Format: string(container),