Skip to content

Commit

Permalink
add phashcompare tool
Browse files Browse the repository at this point in the history
  • Loading branch information
peolic committed Sep 23, 2022
1 parent b0e0910 commit 3873548
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
51 changes: 51 additions & 0 deletions cmd/phashcompare/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"os"

"github.com/corona10/goimagehash"
"github.com/stashapp/stash/pkg/utils"
)

func CompareHashes(hash1 string, hash2 string) (int, error) {
phash1, err := utils.StringToPhash(hash1)
if err != nil {
return -1, fmt.Errorf("phash 1 error: %s", err)
}

phash2, err := utils.StringToPhash(hash2)
if err != nil {
return -1, fmt.Errorf("phash 2 error: %s", err)
}

imageHash := goimagehash.NewImageHash(uint64(phash1), goimagehash.PHash)
otherHash := goimagehash.NewImageHash(uint64(phash2), goimagehash.PHash)

return imageHash.Distance(otherHash)
}

func main() {
args := os.Args[1:]

if len(args) != 2 {
fmt.Println("arg 1: phash 1")
fmt.Println("arg 2: phash 2")
return
}

hash1 := args[0]
hash2 := args[1]

distance, err := CompareHashes(hash1, hash2)
if err != nil {
fmt.Println(err)
return
}

fmt.Println()
fmt.Printf("Distance: %d\n", distance)
fmt.Printf("PHash 1: %s\n", hash1)
fmt.Printf("PHash 2: %s\n", hash2)
fmt.Println()
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module github.com/peolic/videohashes

go 1.18

require github.com/stashapp/stash v0.16.2-0.20220726044218-cba0fddf6113
require (
github.com/corona10/goimagehash v1.0.3
github.com/stashapp/stash v0.16.2-0.20220726044218-cba0fddf6113
)

require (
github.com/corona10/goimagehash v1.0.3 // indirect
github.com/disintegration/imaging v1.6.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand Down

0 comments on commit 3873548

Please sign in to comment.