Compare commits
9 Commits
007a726764
...
b5a5807465
Author | SHA1 | Date | |
---|---|---|---|
|
b5a5807465 | ||
|
9ae3b7cbca | ||
|
29ac38b272 | ||
|
25ec3f77cf | ||
|
aa7b613f4b | ||
|
c078c60f29 | ||
|
f6631a01a2 | ||
|
921019b0d4 | ||
|
04f3ae1e64 |
@ -1,6 +1,6 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
args: [--markdown-linebreak-ext=.gitignore]
|
||||
@ -13,6 +13,30 @@ repos:
|
||||
- id: go-imports
|
||||
args: [-w]
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.53.3
|
||||
rev: v1.59.1
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||
rev: v2.5.0
|
||||
hooks:
|
||||
- id: setup-cfg-fmt
|
||||
|
||||
- repo: https://github.com/asottile/reorder-python-imports
|
||||
rev: v3.13.0
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
args: [--py38-plus, --add-import, 'from __future__ import annotations']
|
||||
- repo: https://github.com/asottile/add-trailing-comma
|
||||
rev: v3.1.0
|
||||
hooks:
|
||||
- id: add-trailing-comma
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.17.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py38-plus]
|
||||
exclude: tests
|
||||
- repo: https://github.com/hhatto/autopep8
|
||||
rev: v2.3.1
|
||||
hooks:
|
||||
- id: autopep8
|
||||
|
913
cmd/comic-hasher/main.go
Normal file
913
cmd/comic-hasher/main.go
Normal file
@ -0,0 +1,913 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"cmp"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
_ "golang.org/x/image/tiff"
|
||||
_ "golang.org/x/image/vp8"
|
||||
_ "golang.org/x/image/vp8l"
|
||||
_ "golang.org/x/image/webp"
|
||||
|
||||
ch "gitea.narnian.us/lordwelch/comic-hasher"
|
||||
"gitea.narnian.us/lordwelch/goimagehash"
|
||||
// "github.com/google/uuid"
|
||||
// "github.com/zitadel/oidc/pkg/client/rp"
|
||||
// httphelper "github.com/zitadel/oidc/pkg/http"
|
||||
// "github.com/zitadel/oidc/pkg/oidc"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
mux *http.ServeMux
|
||||
BaseURL *url.URL
|
||||
// token chan<- *oidc.Tokens
|
||||
// Partial hashes are a uint64 split into 8 pieces or a unint64 for quick lookup, the value is an index to covers
|
||||
PartialAhash [8]map[uint8][]uint64
|
||||
PartialDhash [8]map[uint8][]uint64
|
||||
PartialPhash [8]map[uint8][]uint64
|
||||
FullAhash map[uint64][]string // Maps ahash's to lists of ID's domain:id
|
||||
FullDhash map[uint64][]string // Maps dhash's to lists of ID's domain:id
|
||||
FullPhash map[uint64][]string // Maps phash's to lists of ID's domain:id
|
||||
ids map[ch.Source]map[string]struct{}
|
||||
hashMutex sync.RWMutex
|
||||
quit chan struct{}
|
||||
signalQueue chan os.Signal
|
||||
readerQueue chan string
|
||||
hashingQueue chan ch.Im
|
||||
mappingQueue chan ch.Hash
|
||||
}
|
||||
|
||||
// var key = []byte(uuid.New().String())[:16]
|
||||
|
||||
type savedHashes map[ch.Source]map[string][3]uint64
|
||||
|
||||
type Format int
|
||||
|
||||
const (
|
||||
Msgpack = iota + 1
|
||||
JSON
|
||||
)
|
||||
|
||||
var formatNames = map[Format]string{
|
||||
JSON: "json",
|
||||
Msgpack: "msgpack",
|
||||
}
|
||||
|
||||
var formatValues = map[string]Format{
|
||||
"json": JSON,
|
||||
"msgpack": Msgpack,
|
||||
}
|
||||
|
||||
func (f Format) String() string {
|
||||
if name, known := formatNames[f]; known {
|
||||
return name
|
||||
}
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
type Encoder func(any) ([]byte, error)
|
||||
type Decoder func([]byte, interface{}) error
|
||||
|
||||
func (f *Format) Set(s string) error {
|
||||
if format, known := formatValues[strings.ToLower(s)]; known {
|
||||
*f = format
|
||||
} else {
|
||||
return fmt.Errorf("Unknown format: %d", f)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Opts struct {
|
||||
cpuprofile string
|
||||
coverPath string
|
||||
loadEmbeddedHashes bool
|
||||
saveEmbeddedHashes bool
|
||||
format Format
|
||||
hashesPath string
|
||||
}
|
||||
|
||||
func main() {
|
||||
opts := Opts{format: Msgpack} // flag is weird
|
||||
go func() {
|
||||
log.Println(http.ListenAndServe("localhost:6060", nil))
|
||||
}()
|
||||
flag.StringVar(&opts.cpuprofile, "cpuprofile", "", "Write cpu profile to file")
|
||||
|
||||
flag.StringVar(&opts.coverPath, "cover-path", "", "Path to covers to add to hash database. must be in the form '{cover-path}/{domain}/{id}/*' eg for --cover-path /covers it should look like /covers/comicvine.gamespot.com/10000/image.gif")
|
||||
flag.BoolVar(&opts.loadEmbeddedHashes, "use-embedded-hashes", true, "Use hashes embedded in the application as a starting point")
|
||||
flag.BoolVar(&opts.saveEmbeddedHashes, "save-embedded-hashes", false, "Save hashes even if we loaded the embedded hashes")
|
||||
flag.StringVar(&opts.hashesPath, "hashes", "hashes.gz", "Path to optionally gziped hashes in msgpack or json format. You must disable embedded hashes to use this option")
|
||||
flag.Var(&opts.format, "save-format", "Specify the format to export hashes to (json, msgpack)")
|
||||
flag.Parse()
|
||||
|
||||
if opts.coverPath != "" {
|
||||
_, err := os.Stat(opts.coverPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
startServer(opts)
|
||||
}
|
||||
|
||||
func (s *Server) authenticated(w http.ResponseWriter, r *http.Request) (string, bool) {
|
||||
return strings.TrimSpace("lordwelch"), true
|
||||
}
|
||||
|
||||
func (s *Server) setupAppHandlers() {
|
||||
// s.mux.HandleFunc("/get_cover", s.getCover)
|
||||
s.mux.HandleFunc("/add_cover", s.addCover)
|
||||
s.mux.HandleFunc("/match_cover_hash", s.matchCoverHash)
|
||||
s.mux.HandleFunc("/associate_ids", s.associateIDs)
|
||||
}
|
||||
|
||||
func (s *Server) getCover(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
domain = strings.TrimSpace(values.Get("domain"))
|
||||
ID = strings.TrimSpace(values.Get("id"))
|
||||
)
|
||||
if ID == "" {
|
||||
log.Println("No ID Provided")
|
||||
http.Error(w, "No ID Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if domain == "" {
|
||||
log.Println("No domain Provided")
|
||||
http.Error(w, "No domain Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// if index, ok := s.IDToCover[domain+":"+ID]; ok {
|
||||
// covers, err := json.Marshal(s.covers[index])
|
||||
// if err == nil {
|
||||
// w.Header().Add("Content-Type", "application/json")
|
||||
// w.Write(covers)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
fmt.Fprintln(w, "Not implemented")
|
||||
}
|
||||
|
||||
func (s *Server) associateIDs(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
domain = strings.TrimSpace(values.Get("domain"))
|
||||
ID = strings.TrimSpace(values.Get("id"))
|
||||
newDomain = strings.TrimSpace(values.Get("newDomain"))
|
||||
newID = strings.TrimSpace(values.Get("newID"))
|
||||
)
|
||||
if ID == "" {
|
||||
msg := "No ID Provided"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
if domain == "" {
|
||||
msg := "No domain Provided"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
if newID == "" {
|
||||
msg := "No newID Provided"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
if newDomain == "" {
|
||||
msg := "No newDomain Provided"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
if newDomain == domain {
|
||||
msg := "newDomain cannot be the same as the existing domain"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
if _, domainExists := s.ids[ch.Source(domain)]; !domainExists {
|
||||
msg := "No IDs belonging to " + domain + "exist on this server"
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
}
|
||||
log.Printf("Attempting to associate %s:%s to %s:%s", domain, ID, newDomain, newID)
|
||||
found := false
|
||||
for _, hash := range []map[uint64][]string{s.FullAhash, s.FullDhash, s.FullPhash} {
|
||||
for i, idlist := range hash {
|
||||
if _, found_in_hash := slices.BinarySearch(idlist, domain+":"+ID); found_in_hash {
|
||||
found = true
|
||||
hash[i] = ch.Insert(idlist, newDomain+":"+newID)
|
||||
if _, ok := s.ids[ch.Source(newDomain)]; !ok {
|
||||
s.ids[ch.Source(newDomain)] = make(map[string]struct{})
|
||||
}
|
||||
s.ids[ch.Source(newDomain)][newID] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
if found {
|
||||
writeJson(w, http.StatusOK, result{Msg: "New ID added"})
|
||||
} else {
|
||||
writeJson(w, http.StatusOK, result{Msg: "Old ID not found"})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) getMatches(ahash, dhash, phash uint64, max int, skipNonExact bool) []ch.Result {
|
||||
var foundMatches []ch.Result
|
||||
s.hashMutex.RLock()
|
||||
defer s.hashMutex.RUnlock()
|
||||
|
||||
if skipNonExact { // exact matches are also found by partial matches. Don't bother with exact matches so we don't have to de-duplicate
|
||||
if matchedResults, ok := s.FullAhash[ahash]; ok && ahash != 0 {
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: 0, Hash: ch.ImageHash{Hash: ahash, Kind: goimagehash.AHash}})
|
||||
}
|
||||
if matchedResults, ok := s.FullDhash[dhash]; ok && dhash != 0 {
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: 0, Hash: ch.ImageHash{Hash: dhash, Kind: goimagehash.DHash}})
|
||||
}
|
||||
if matchedResults, ok := s.FullPhash[phash]; ok && phash != 0 {
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: 0, Hash: ch.ImageHash{Hash: phash, Kind: goimagehash.PHash}})
|
||||
}
|
||||
|
||||
// If we have exact matches don't bother with other matches
|
||||
if len(foundMatches) > 0 && skipNonExact {
|
||||
return foundMatches
|
||||
}
|
||||
}
|
||||
|
||||
foundHashes := make(map[uint64]struct{})
|
||||
if ahash != 0 {
|
||||
for i, partialHash := range ch.SplitHash(ahash) {
|
||||
for _, match := range ch.Atleast(max, ahash, s.PartialAhash[i][partialHash]) {
|
||||
_, alreadyMatched := foundHashes[match.Hash]
|
||||
if matchedResults, ok := s.FullAhash[match.Hash]; ok && !alreadyMatched {
|
||||
foundHashes[match.Hash] = struct{}{}
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: match.Distance, Hash: ch.ImageHash{Hash: match.Hash, Kind: goimagehash.AHash}})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundHashes = make(map[uint64]struct{})
|
||||
if dhash != 0 {
|
||||
for i, partialHash := range ch.SplitHash(dhash) {
|
||||
for _, match := range ch.Atleast(max, dhash, s.PartialDhash[i][partialHash]) {
|
||||
_, alreadyMatched := foundHashes[match.Hash]
|
||||
if matchedResults, ok := s.FullDhash[match.Hash]; ok && !alreadyMatched {
|
||||
foundHashes[match.Hash] = struct{}{}
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: match.Distance, Hash: ch.ImageHash{Hash: match.Hash, Kind: goimagehash.DHash}})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundHashes = make(map[uint64]struct{})
|
||||
if phash != 0 {
|
||||
for i, partialHash := range ch.SplitHash(phash) {
|
||||
for _, match := range ch.Atleast(max, phash, s.PartialPhash[i][partialHash]) {
|
||||
_, alreadyMatched := foundHashes[match.Hash]
|
||||
if matchedResults, ok := s.FullPhash[match.Hash]; ok && !alreadyMatched {
|
||||
foundHashes[match.Hash] = struct{}{}
|
||||
foundMatches = append(foundMatches, ch.Result{IDs: matchedResults, Distance: match.Distance, Hash: ch.ImageHash{Hash: match.Hash, Kind: goimagehash.PHash}})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundMatches
|
||||
}
|
||||
|
||||
type SimpleResult struct {
|
||||
Distance int
|
||||
IDList ch.IDList
|
||||
}
|
||||
|
||||
func getSimpleResults(fullResults []ch.Result) []SimpleResult {
|
||||
simpleResult := make([]SimpleResult, 0, len(fullResults))
|
||||
|
||||
slices.SortFunc(fullResults, func(a, b ch.Result) int {
|
||||
return cmp.Compare(a.Distance, b.Distance)
|
||||
})
|
||||
|
||||
// Deduplicate IDs
|
||||
idToDistance := make(map[string]int)
|
||||
for _, fullResult := range fullResults {
|
||||
for _, id := range fullResult.IDs {
|
||||
if distance, ok := idToDistance[id]; !ok || fullResult.Distance < distance {
|
||||
idToDistance[id] = fullResult.Distance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Group by distance
|
||||
distanceMap := make(map[int]SimpleResult)
|
||||
for id, distance := range idToDistance {
|
||||
var (
|
||||
sr SimpleResult
|
||||
ok bool
|
||||
)
|
||||
if sr, ok = distanceMap[distance]; !ok {
|
||||
sr.IDList = make(ch.IDList)
|
||||
}
|
||||
sourceID := strings.SplitN(id, ":", 2)
|
||||
sr.Distance = distance
|
||||
sr.IDList[ch.Source(sourceID[0])] = append(sr.IDList[ch.Source(sourceID[0])], sourceID[1])
|
||||
distanceMap[distance] = sr
|
||||
}
|
||||
|
||||
// turn into array
|
||||
for _, sr := range distanceMap {
|
||||
simpleResult = append(simpleResult, sr)
|
||||
}
|
||||
return simpleResult
|
||||
}
|
||||
|
||||
type APIResult struct {
|
||||
IDList ch.IDList
|
||||
Distance int
|
||||
Hash ch.ImageHash
|
||||
}
|
||||
|
||||
func getResults(fullResults []ch.Result) []APIResult {
|
||||
apiResults := make([]APIResult, 0, len(fullResults))
|
||||
for _, res := range fullResults {
|
||||
idlist := make(ch.IDList)
|
||||
for _, id := range res.IDs {
|
||||
sourceID := strings.SplitN(id, ":", 2)
|
||||
idlist[ch.Source(sourceID[0])] = append(idlist[ch.Source(sourceID[0])], sourceID[1])
|
||||
}
|
||||
apiResults = append(apiResults,
|
||||
APIResult{
|
||||
Distance: res.Distance,
|
||||
Hash: res.Hash,
|
||||
IDList: idlist,
|
||||
},
|
||||
)
|
||||
}
|
||||
return apiResults
|
||||
}
|
||||
|
||||
type result struct {
|
||||
Results any `json:"results,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
}
|
||||
|
||||
func writeJson(w http.ResponseWriter, status int, res result) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
var (
|
||||
bytes []byte
|
||||
err error
|
||||
)
|
||||
if bytes, err = json.Marshal(res); err != nil {
|
||||
bytes, _ = json.Marshal(result{Msg: fmt.Sprintf("Failed to create json: %s", err)})
|
||||
}
|
||||
w.WriteHeader(status)
|
||||
_, _ = w.Write(bytes)
|
||||
_, _ = w.Write([]byte("\n"))
|
||||
}
|
||||
|
||||
func (s *Server) matchCoverHash(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
ahashStr = strings.TrimSpace(values.Get("ahash"))
|
||||
dhashStr = strings.TrimSpace(values.Get("dhash"))
|
||||
phashStr = strings.TrimSpace(values.Get("phash"))
|
||||
maxStr = strings.TrimSpace(values.Get("max"))
|
||||
skipNonExact = strings.ToLower(strings.TrimSpace(values.Get("skipNonExact"))) != "false"
|
||||
simple = strings.ToLower(strings.TrimSpace(values.Get("simple"))) == "true"
|
||||
ahash uint64
|
||||
dhash uint64
|
||||
phash uint64
|
||||
max int = 8
|
||||
max_tmp int
|
||||
err error
|
||||
)
|
||||
|
||||
if ahash, err = strconv.ParseUint(ahashStr, 16, 64); err != nil && ahashStr != "" {
|
||||
log.Printf("could not parse ahash: %s", ahashStr)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: "hash parse failed"})
|
||||
return
|
||||
}
|
||||
if dhash, err = strconv.ParseUint(dhashStr, 16, 64); err != nil && dhashStr != "" {
|
||||
log.Printf("could not parse dhash: %s", dhashStr)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: "hash parse failed"})
|
||||
return
|
||||
}
|
||||
if phash, err = strconv.ParseUint(phashStr, 16, 64); err != nil && phashStr != "" {
|
||||
log.Printf("could not parse phash: %s", phashStr)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: "hash parse failed"})
|
||||
return
|
||||
}
|
||||
if max_tmp, err = strconv.Atoi(maxStr); err != nil && maxStr != "" {
|
||||
log.Printf("Invalid Max: %s", maxStr)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: fmt.Sprintf("Invalid Max: %s", maxStr)})
|
||||
return
|
||||
}
|
||||
if maxStr != "" {
|
||||
max = max_tmp
|
||||
}
|
||||
|
||||
if max > 8 {
|
||||
log.Printf("Max must be less than 9: %d", max)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: fmt.Sprintf("Max must be less than 9: %d", max)})
|
||||
return
|
||||
}
|
||||
matches := s.getMatches(ahash, dhash, phash, max, skipNonExact)
|
||||
if len(matches) > 0 {
|
||||
if simple {
|
||||
writeJson(w, http.StatusOK, result{Results: getSimpleResults(matches)})
|
||||
return
|
||||
}
|
||||
writeJson(w, http.StatusOK, result{Results: getResults(matches)})
|
||||
return
|
||||
}
|
||||
|
||||
writeJson(w, http.StatusNotFound, result{Msg: "No hashes found"})
|
||||
}
|
||||
|
||||
func (s *Server) addCover(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
domain = strings.TrimSpace(values.Get("domain"))
|
||||
ID = strings.TrimSpace(values.Get("id"))
|
||||
)
|
||||
if ID == "" {
|
||||
log.Println("No ID Provided")
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: "No ID Provided"})
|
||||
return
|
||||
}
|
||||
if domain == "" {
|
||||
log.Println("No domain Provided")
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: "No Domain Provided"})
|
||||
return
|
||||
}
|
||||
i, format, err := image.Decode(r.Body)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to decode Image: %s", err)
|
||||
log.Println(msg)
|
||||
writeJson(w, http.StatusBadRequest, result{Msg: msg})
|
||||
return
|
||||
}
|
||||
log.Printf("Decoded %s image from %s", format, user)
|
||||
select {
|
||||
case <-s.quit:
|
||||
log.Println("Recieved quit")
|
||||
return
|
||||
default:
|
||||
}
|
||||
s.hashingQueue <- ch.Im{Im: i, Format: format, Domain: ch.Source(domain), ID: ID, Path: ""}
|
||||
writeJson(w, http.StatusOK, result{Msg: "Success"})
|
||||
}
|
||||
|
||||
func (s *Server) MapHashes(hash ch.Hash) {
|
||||
s.hashMutex.Lock()
|
||||
defer s.hashMutex.Unlock()
|
||||
s.mapHashes(hash.Ahash.GetHash(), hash.Dhash.GetHash(), hash.Phash.GetHash(), hash.Domain, hash.ID)
|
||||
}
|
||||
|
||||
func (s *Server) mapHashes(ahash, dhash, phash uint64, domain ch.Source, id string) {
|
||||
|
||||
if _, ok := s.ids[domain]; !ok {
|
||||
s.ids[domain] = make(map[string]struct{})
|
||||
}
|
||||
s.ids[domain][id] = struct{}{}
|
||||
|
||||
if _, ok := s.FullAhash[ahash]; !ok {
|
||||
s.FullAhash[ahash] = make([]string, 0, 3)
|
||||
}
|
||||
s.FullAhash[ahash] = ch.Insert(s.FullAhash[ahash], string(domain)+":"+id)
|
||||
|
||||
if _, ok := s.FullDhash[dhash]; !ok {
|
||||
s.FullDhash[dhash] = make([]string, 0, 3)
|
||||
}
|
||||
s.FullDhash[dhash] = ch.Insert(s.FullDhash[dhash], string(domain)+":"+id)
|
||||
|
||||
if _, ok := s.FullPhash[phash]; !ok {
|
||||
s.FullPhash[phash] = make([]string, 0, 3)
|
||||
}
|
||||
s.FullPhash[phash] = ch.Insert(s.FullPhash[phash], string(domain)+":"+id)
|
||||
|
||||
for i, partialHash := range ch.SplitHash(ahash) {
|
||||
s.PartialAhash[i][partialHash] = append(s.PartialAhash[i][partialHash], ahash)
|
||||
}
|
||||
for i, partialHash := range ch.SplitHash(dhash) {
|
||||
s.PartialDhash[i][partialHash] = append(s.PartialDhash[i][partialHash], dhash)
|
||||
}
|
||||
for i, partialHash := range ch.SplitHash(phash) {
|
||||
s.PartialPhash[i][partialHash] = append(s.PartialPhash[i][partialHash], phash)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) initHashes() {
|
||||
for i := range s.PartialAhash {
|
||||
s.PartialAhash[i] = make(map[uint8][]uint64)
|
||||
}
|
||||
for i := range s.PartialDhash {
|
||||
s.PartialDhash[i] = make(map[uint8][]uint64)
|
||||
}
|
||||
for i := range s.PartialPhash {
|
||||
s.PartialPhash[i] = make(map[uint8][]uint64)
|
||||
}
|
||||
s.FullAhash = make(map[uint64][]string)
|
||||
s.FullDhash = make(map[uint64][]string)
|
||||
s.FullPhash = make(map[uint64][]string)
|
||||
s.ids = make(map[ch.Source]map[string]struct{})
|
||||
}
|
||||
|
||||
func (s *Server) mapper(done func()) {
|
||||
defer done()
|
||||
for hash := range s.mappingQueue {
|
||||
s.MapHashes(hash)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) hasher(workerID int, done func()) {
|
||||
defer done()
|
||||
for image := range s.hashingQueue {
|
||||
start := time.Now()
|
||||
|
||||
hash := ch.HashImage(image)
|
||||
if hash.Domain == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
select {
|
||||
case <-s.quit:
|
||||
log.Println("Recieved quit")
|
||||
return
|
||||
case s.mappingQueue <- hash:
|
||||
default:
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("Hashing took %v: worker: %v. path: %s ahash: %064b id: %s\n", elapsed, workerID, image.Path, hash.Ahash.GetHash(), hash.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) reader(workerID int, done func()) {
|
||||
defer done()
|
||||
for path := range s.readerQueue {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
i, format, err := image.Decode(bufio.NewReader(file))
|
||||
if err != nil {
|
||||
continue // skip this image
|
||||
}
|
||||
file.Close()
|
||||
|
||||
im := ch.Im{Im: i, Format: format, Domain: ch.Source(filepath.Base(filepath.Dir(filepath.Dir(path)))), ID: filepath.Base(filepath.Dir(path)), Path: path}
|
||||
select {
|
||||
case <-s.quit:
|
||||
log.Println("Recieved quit")
|
||||
return
|
||||
case s.hashingQueue <- im:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) encodeHashes(e Encoder) ([]byte, error) {
|
||||
hashes := make(savedHashes)
|
||||
for source, ids := range s.ids {
|
||||
hashes[source] = make(map[string][3]uint64, len(ids))
|
||||
}
|
||||
for hash, idlist := range s.FullAhash {
|
||||
for _, id := range idlist {
|
||||
sourceID := strings.SplitN(id, ":", 2)
|
||||
h := hashes[ch.Source(sourceID[0])][sourceID[1]]
|
||||
h[0] = hash
|
||||
hashes[ch.Source(sourceID[0])][sourceID[1]] = h
|
||||
}
|
||||
}
|
||||
for hash, idlist := range s.FullDhash {
|
||||
for _, id := range idlist {
|
||||
sourceID := strings.SplitN(id, ":", 2)
|
||||
h := hashes[ch.Source(sourceID[0])][sourceID[1]]
|
||||
h[1] = hash
|
||||
hashes[ch.Source(sourceID[0])][sourceID[1]] = h
|
||||
}
|
||||
|
||||
}
|
||||
for hash, idlist := range s.FullPhash {
|
||||
for _, id := range idlist {
|
||||
sourceID := strings.SplitN(id, ":", 2)
|
||||
h := hashes[ch.Source(sourceID[0])][sourceID[1]]
|
||||
h[2] = hash
|
||||
hashes[ch.Source(sourceID[0])][sourceID[1]] = h
|
||||
}
|
||||
|
||||
}
|
||||
return e(hashes)
|
||||
}
|
||||
|
||||
// EncodeHashes must have a lock to s.hashMutex
|
||||
func (s *Server) EncodeHashes(format Format) ([]byte, error) {
|
||||
switch format {
|
||||
case Msgpack:
|
||||
return s.encodeHashes(msgpack.Marshal)
|
||||
case JSON:
|
||||
return s.encodeHashes(json.Marshal)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown format: %v", format)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) decodeHashes(d Decoder, hashes []byte) error {
|
||||
loadedHashes := make(savedHashes)
|
||||
err := d(hashes, &loadedHashes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for domain, ids := range loadedHashes {
|
||||
for id := range ids {
|
||||
if _, ok := s.ids[domain]; ok {
|
||||
s.ids[domain][id] = struct{}{}
|
||||
} else {
|
||||
s.ids[domain] = make(map[string]struct{})
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, sourceHashes := range loadedHashes {
|
||||
s.FullAhash = make(map[uint64][]string, len(sourceHashes))
|
||||
s.FullDhash = make(map[uint64][]string, len(sourceHashes))
|
||||
s.FullPhash = make(map[uint64][]string, len(sourceHashes))
|
||||
break
|
||||
}
|
||||
for domain, sourceHashes := range loadedHashes {
|
||||
for id, h := range sourceHashes {
|
||||
s.mapHashes(h[0], h[1], h[2], domain, id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeHashes must have a lock to s.hashMutex
|
||||
func (s *Server) DecodeHashes(format Format, hashes []byte) error {
|
||||
switch format {
|
||||
case Msgpack:
|
||||
return s.decodeHashes(msgpack.Unmarshal, hashes)
|
||||
case JSON:
|
||||
return s.decodeHashes(json.Unmarshal, hashes)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("Unknown format: %v", format)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) HashLocalImages(opts Opts) {
|
||||
go func() {
|
||||
alreadyQuit := false
|
||||
if opts.coverPath == "" {
|
||||
select {
|
||||
case sig := <-s.signalQueue:
|
||||
log.Printf("Signal: %v\n", sig)
|
||||
close(s.quit)
|
||||
case <-s.quit:
|
||||
log.Println("Recieved quit")
|
||||
}
|
||||
err := s.httpServer.Shutdown(context.TODO())
|
||||
fmt.Println("Err:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Hashing covers at ", opts.coverPath)
|
||||
start := time.Now()
|
||||
err := filepath.WalkDir(opts.coverPath, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
select {
|
||||
case signal := <-s.signalQueue:
|
||||
err = s.httpServer.Shutdown(context.TODO())
|
||||
alreadyQuit = true
|
||||
close(s.quit)
|
||||
return fmt.Errorf("signal: %v, %w", signal, err)
|
||||
case <-s.quit:
|
||||
log.Println("Recieved quit")
|
||||
err = s.httpServer.Shutdown(context.TODO())
|
||||
return fmt.Errorf("Recieved quit: %w", err)
|
||||
default:
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.readerQueue <- path
|
||||
return nil
|
||||
})
|
||||
elapsed := time.Since(start)
|
||||
fmt.Println("Err:", err, "local hashing took", elapsed)
|
||||
|
||||
sig := <-s.signalQueue
|
||||
if !alreadyQuit {
|
||||
close(s.quit)
|
||||
}
|
||||
err = s.httpServer.Shutdown(context.TODO())
|
||||
log.Printf("Signal: %v, error: %v", sig, err)
|
||||
}()
|
||||
}
|
||||
|
||||
func startServer(opts Opts) {
|
||||
if opts.cpuprofile != "" {
|
||||
f, err := os.Create(opts.cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
server := Server{
|
||||
// token: make(chan *oidc.Tokens),
|
||||
quit: make(chan struct{}),
|
||||
signalQueue: make(chan os.Signal, 1),
|
||||
readerQueue: make(chan string, 1120130), // Number gotten from checking queue size
|
||||
hashingQueue: make(chan ch.Im),
|
||||
mappingQueue: make(chan ch.Hash),
|
||||
mux: mux,
|
||||
httpServer: &http.Server{
|
||||
Addr: ":8080",
|
||||
Handler: mux,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
},
|
||||
}
|
||||
Notify(server.signalQueue)
|
||||
imaging.SetMaxProcs(1)
|
||||
fmt.Println("init hashes")
|
||||
server.initHashes()
|
||||
// server.setupOauthHandlers()
|
||||
fmt.Println("init handlers")
|
||||
server.setupAppHandlers()
|
||||
fmt.Println("init hashers")
|
||||
rwg := sync.WaitGroup{}
|
||||
for i := range 10 {
|
||||
rwg.Add(1)
|
||||
go server.reader(i, func() { fmt.Println("Reader completed"); rwg.Done() })
|
||||
}
|
||||
|
||||
hwg := sync.WaitGroup{}
|
||||
for i := range 10 {
|
||||
hwg.Add(1)
|
||||
go server.hasher(i, func() { fmt.Println("Hasher completed"); hwg.Done() })
|
||||
}
|
||||
|
||||
fmt.Println("init mapper")
|
||||
mwg := sync.WaitGroup{}
|
||||
mwg.Add(1)
|
||||
go server.mapper(func() { fmt.Println("Mapper completed"); mwg.Done() })
|
||||
|
||||
if opts.loadEmbeddedHashes && len(ch.Hashes) != 0 {
|
||||
var err error
|
||||
hashes := ch.Hashes
|
||||
if gr, err := gzip.NewReader(bytes.NewReader(ch.Hashes)); err == nil {
|
||||
hashes, err = io.ReadAll(gr)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to read embedded hashes: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
var format Format
|
||||
for _, format = range []Format{Msgpack, JSON} {
|
||||
if err = server.DecodeHashes(format, hashes); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to decode embedded hashes: %s", err))
|
||||
}
|
||||
fmt.Printf("Loaded embedded %s hashes ahashes: %d dhashes: %d phashes: %d\n", format, len(server.FullAhash), len(server.FullDhash), len(server.FullPhash))
|
||||
} else {
|
||||
if f, err := os.Open(opts.hashesPath); err == nil {
|
||||
var buf io.Reader = f
|
||||
if gr, err := gzip.NewReader(buf); err == nil {
|
||||
buf = bufio.NewReader(gr)
|
||||
} else {
|
||||
_, _ = f.Seek(0, io.SeekStart)
|
||||
}
|
||||
hashes, err := io.ReadAll(buf)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to load hashes from disk: %s", err))
|
||||
}
|
||||
|
||||
var format Format
|
||||
for _, format = range []Format{Msgpack, JSON} {
|
||||
if err = server.DecodeHashes(format, hashes); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to decode hashes from disk: %s", err))
|
||||
}
|
||||
fmt.Printf("Loaded hashes from %q %s hashes ahashes: %d dhashes: %d phashes: %d\n", opts.hashesPath, format, len(server.FullAhash), len(server.FullDhash), len(server.FullPhash))
|
||||
} else {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
fmt.Println("No saved hashes to load")
|
||||
} else {
|
||||
fmt.Println("Unable to load saved hashes", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server.HashLocalImages(opts)
|
||||
|
||||
fmt.Println("Listening on ", server.httpServer.Addr)
|
||||
err := server.httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
close(server.readerQueue)
|
||||
fmt.Println("waiting on readers")
|
||||
rwg.Wait()
|
||||
for range server.readerQueue {
|
||||
}
|
||||
close(server.hashingQueue)
|
||||
fmt.Println("waiting on hashers")
|
||||
hwg.Wait()
|
||||
for range server.hashingQueue {
|
||||
}
|
||||
close(server.mappingQueue)
|
||||
fmt.Println("waiting on mapper")
|
||||
mwg.Wait()
|
||||
for range server.mappingQueue {
|
||||
}
|
||||
close(server.signalQueue)
|
||||
for range server.signalQueue {
|
||||
}
|
||||
|
||||
if !opts.loadEmbeddedHashes || opts.saveEmbeddedHashes {
|
||||
encodedHashes, err := server.EncodeHashes(opts.format)
|
||||
if err == nil {
|
||||
if f, err := os.Create(opts.hashesPath); err == nil {
|
||||
gzw := gzip.NewWriter(f)
|
||||
_, err := gzw.Write(encodedHashes)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to write hashes", err)
|
||||
} else {
|
||||
fmt.Println("Successfully saved hashes")
|
||||
}
|
||||
gzw.Close()
|
||||
f.Close()
|
||||
} else {
|
||||
fmt.Println("Unabled to save hashes", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Unable to encode hashes as %v: %v", opts.format, err)
|
||||
}
|
||||
}
|
||||
}
|
12
cmd/comic-hasher/main_not_unix.go
Normal file
12
cmd/comic-hasher/main_not_unix.go
Normal file
@ -0,0 +1,12 @@
|
||||
//go:build !unix
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
)
|
||||
|
||||
func Notify(sig chan os.Signal) {
|
||||
signal.Notify(sig, os.Interrupt, os.Kill)
|
||||
}
|
13
cmd/comic-hasher/main_unix.go
Normal file
13
cmd/comic-hasher/main_unix.go
Normal file
@ -0,0 +1,13 @@
|
||||
//go:build unix
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func Notify(sig chan os.Signal) {
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGABRT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||
}
|
65
cmd/hash.py
65
cmd/hash.py
@ -1,10 +1,19 @@
|
||||
from typing import Collection, Sequence
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
import sys
|
||||
from typing import Collection
|
||||
from typing import Sequence
|
||||
|
||||
import imagehash
|
||||
import numpy
|
||||
from PIL import Image
|
||||
import argparse,pathlib,numpy,imagehash
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
|
||||
ap.add_argument("--file", type=pathlib.Path)
|
||||
ap.add_argument('--file', type=pathlib.Path)
|
||||
ap.add_argument('--debug', action='store_true')
|
||||
|
||||
opts = ap.parse_args()
|
||||
opts.file = pathlib.Path(opts.file)
|
||||
@ -18,39 +27,43 @@ resized = gray.copy().resize((hash_size, hash_size), Image.Resampling.LANCZOS)
|
||||
|
||||
def print_image(image: Image.Image) -> None:
|
||||
for row in numpy.asarray(image):
|
||||
print('[ ', end='')
|
||||
print('[ ', end='', file=sys.stderr)
|
||||
for i in row:
|
||||
if isinstance(i, Collection):
|
||||
print('{ ', end='')
|
||||
print('{ ', end='', file=sys.stderr)
|
||||
for idx, x in enumerate(i):
|
||||
if idx == len(i)-1:
|
||||
print(f'{int(x):03d} ', end='')
|
||||
if idx == len(i) - 1:
|
||||
print(f'{int(x):03d} ', end='', file=sys.stderr)
|
||||
else:
|
||||
print(f'{int(x):03d}, ', end='')
|
||||
print('}, ', end='')
|
||||
print(f'{int(x):03d}, ', end='', file=sys.stderr)
|
||||
print('}, ', end='', file=sys.stderr)
|
||||
else:
|
||||
print(f'{int(i):03d}, ', end='')
|
||||
print(']')
|
||||
print(f'{int(i):03d}, ', end='', file=sys.stderr)
|
||||
print(']', file=sys.stderr)
|
||||
|
||||
|
||||
def bin_str(hash):
|
||||
return ''.join(str(b) for b in 1 * hash.hash.flatten())
|
||||
|
||||
|
||||
print("rgb")
|
||||
print_image(image)
|
||||
print()
|
||||
image.save("py.rgb.png")
|
||||
if opts.debug:
|
||||
image.save('py.rgb.png')
|
||||
print('rgb', file=sys.stderr)
|
||||
print_image(image)
|
||||
print(file=sys.stderr)
|
||||
|
||||
print("gray")
|
||||
print_image(gray)
|
||||
gray.save("py.gray.png")
|
||||
print()
|
||||
if opts.debug:
|
||||
gray.save('py.gray.png')
|
||||
print('gray', file=sys.stderr)
|
||||
print_image(gray)
|
||||
print(file=sys.stderr)
|
||||
|
||||
print("resized")
|
||||
print_image(resized)
|
||||
resized.save("py.resized.png")
|
||||
print()
|
||||
if opts.debug:
|
||||
resized.save('py.resized.png')
|
||||
print('resized', file=sys.stderr)
|
||||
print_image(resized)
|
||||
print(file=sys.stderr)
|
||||
|
||||
print('ahash: ', bin_str(imagehash.average_hash(image)))
|
||||
print('dhash: ', bin_str(imagehash.dhash(image)))
|
||||
print('phash: ', bin_str(imagehash.phash(image)))
|
||||
print('ahash: ', str(imagehash.average_hash(image)))
|
||||
print('dhash: ', str(imagehash.dhash(image)))
|
||||
print('phash: ', str(imagehash.phash(image)))
|
||||
|
91
cmd/hash/cover_extract/main.go
Normal file
91
cmd/hash/cover_extract/main.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/fmartingr/go-comicinfo/v2"
|
||||
|
||||
"github.com/mholt/archiver/v4"
|
||||
"golang.org/x/text/collate"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := collate.New(language.English, collate.Loose, collate.Numeric, collate.Force)
|
||||
fileArchive := flag.String("file", "", "archive to extract cover")
|
||||
flag.Parse()
|
||||
if fileArchive == nil || *fileArchive == "" {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
file, err := os.Open(*fileArchive)
|
||||
if err != nil {
|
||||
log.Printf("Failed to open file %s: %s", *fileArchive, err)
|
||||
return
|
||||
}
|
||||
unrar := archiver.Rar{}
|
||||
fileList := []string{}
|
||||
err = unrar.Extract(context.TODO(), file, nil, func(ctx context.Context, f archiver.File) error {
|
||||
if !strings.HasSuffix(f.NameInArchive, ".xml") {
|
||||
fileList = append(fileList, f.NameInArchive)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = file.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.SortStrings(fileList)
|
||||
var (
|
||||
image []byte
|
||||
issueID string
|
||||
files = []string{"ComicInfo.xml", fileList[0]}
|
||||
)
|
||||
fmt.Printf("Extracting %s\n", fileList[0])
|
||||
err = unrar.Extract(context.TODO(), file, files, func(ctx context.Context, f archiver.File) error {
|
||||
r, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if f.Name() == "ComicInfo.xml" {
|
||||
ci, err := comicinfo.Read(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parts := strings.Split(strings.TrimRight(ci.Web, "/"), "/")
|
||||
ids := strings.Split(parts[len(parts)-1], "-")
|
||||
issueID = ids[1]
|
||||
} else {
|
||||
image, err = io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
file.Close()
|
||||
file, err = os.Create(*fileArchive + "." + issueID + ".image")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
_, err = file.Write(image)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// os.Remove(*fileArchive)
|
||||
// fmt.Println("removed " + *fileArchive)
|
||||
}
|
@ -1,27 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/draw"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
|
||||
// "github.com/pixiv/go-libjpeg/jpeg"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gitea.narnian.us/lordwelch/goimagehash"
|
||||
"gitea.narnian.us/lordwelch/goimagehash/transforms"
|
||||
"github.com/anthonynsimon/bild/transform"
|
||||
_ "github.com/gen2brain/avif"
|
||||
_ "github.com/spakin/netpbm"
|
||||
_ "golang.org/x/image/bmp"
|
||||
_ "golang.org/x/image/tiff"
|
||||
_ "golang.org/x/image/webp"
|
||||
|
||||
ch "gitea.narnian.us/lordwelch/comic-hasher"
|
||||
"gitea.narnian.us/lordwelch/goimagehash"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -30,23 +23,9 @@ func init() {
|
||||
// DisableBlockSmoothing: false,
|
||||
// DCTMethod: jpeg.DCTFloat,
|
||||
// })}, jpeg.DecodeConfig)
|
||||
|
||||
}
|
||||
|
||||
func ToGray(img image.Image) *image.Gray {
|
||||
gray := image.NewGray(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()))
|
||||
gray.Pix = transforms.Rgb2Gray(img)
|
||||
return gray
|
||||
}
|
||||
|
||||
func resize(img image.Image, w, h int) *image.Gray {
|
||||
resized := transform.Resize(img, w, h, transform.Lanczos)
|
||||
r_gray := image.NewGray(image.Rect(0, 0, resized.Bounds().Dx(), resized.Bounds().Dy()))
|
||||
draw.Draw(r_gray, resized.Bounds(), resized, resized.Bounds().Min, draw.Src)
|
||||
return r_gray
|
||||
}
|
||||
|
||||
func save_image(im image.Image, name string) {
|
||||
func saveImage(im image.Image, name string) {
|
||||
file, err := os.Create(name)
|
||||
if err != nil {
|
||||
log.Printf("Failed to open file %s: %s", "tmp.png", err)
|
||||
@ -80,22 +59,26 @@ func fmtImage(im image.Image) string {
|
||||
}
|
||||
|
||||
func debugImage(im image.Image, width, height int) {
|
||||
gray := ToGray(im)
|
||||
resized := resize(gray, width, height)
|
||||
gray := goimagehash.ToGray(im, nil)
|
||||
resized := goimagehash.Resize(gray, width, height, nil)
|
||||
|
||||
fmt.Println("rgb")
|
||||
fmt.Println(fmtImage(im))
|
||||
save_image(im, "go.rgb.png")
|
||||
fmt.Println("gray")
|
||||
fmt.Println(fmtImage(gray))
|
||||
save_image(gray, "go.gray.png")
|
||||
fmt.Println("resized")
|
||||
fmt.Println(fmtImage(resized))
|
||||
save_image(resized, "go.resized.png")
|
||||
saveImage(im, "go.rgb.png")
|
||||
log.Println("rgb")
|
||||
log.Println(fmtImage(im))
|
||||
|
||||
saveImage(gray, "go.gray.png")
|
||||
log.Println("gray")
|
||||
log.Println(fmtImage(gray))
|
||||
|
||||
saveImage(resized, "go.resized.png")
|
||||
log.Println("resized")
|
||||
log.Println(fmtImage(resized))
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
imPath := flag.String("file", "", "image file to hash")
|
||||
debug := flag.Bool("debug", false, "Enable debug output")
|
||||
flag.Parse()
|
||||
if imPath == nil || *imPath == "" {
|
||||
flag.Usage()
|
||||
@ -108,47 +91,24 @@ func main() {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
im, format, err := image.Decode(file)
|
||||
im, format, err := image.Decode(bufio.NewReader(file))
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to decode Image: %s", err)
|
||||
log.Println(msg)
|
||||
return
|
||||
}
|
||||
|
||||
debugim := im
|
||||
if format == "webp" {
|
||||
im = goimagehash.FancyUpscale(im.(*image.YCbCr))
|
||||
debugim = goimagehash.FancyUpscale(im.(*image.YCbCr))
|
||||
}
|
||||
|
||||
debugImage(im, 8, 8)
|
||||
|
||||
var (
|
||||
ahash *goimagehash.ImageHash
|
||||
dhash *goimagehash.ImageHash
|
||||
phash *goimagehash.ImageHash
|
||||
)
|
||||
|
||||
ahash, err = goimagehash.AverageHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to ahash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return
|
||||
if *debug {
|
||||
debugImage(debugim, 8, 8)
|
||||
}
|
||||
|
||||
dhash, err = goimagehash.DifferenceHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to ahash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return
|
||||
}
|
||||
hash := ch.HashImage(ch.Im{Im: im, Format: format, Domain: ch.Source(ch.ComicVine), ID: "nothing"})
|
||||
|
||||
phash, err = goimagehash.PerceptionHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to ahash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("ahash: ", ahash.BinString())
|
||||
fmt.Println("dhash: ", dhash.BinString())
|
||||
fmt.Println("phash: ", phash.BinString())
|
||||
fmt.Println("ahash: ", hash.Ahash.BinString())
|
||||
fmt.Println("dhash: ", hash.Dhash.BinString())
|
||||
fmt.Println("phash: ", hash.Phash.BinString())
|
||||
}
|
||||
|
34
cmd/hash/natsort/main.go
Normal file
34
cmd/hash/natsort/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/collate"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := collate.New(language.English, collate.Loose, collate.Numeric, collate.Force)
|
||||
list := []string{
|
||||
"11.jpg",
|
||||
"12.jpg",
|
||||
"2.jpg",
|
||||
"99999999999999999.jpg",
|
||||
"02.jpg",
|
||||
"00.jpg",
|
||||
"0.jpg",
|
||||
"00.jpg",
|
||||
"1.jpg",
|
||||
"01.jpg",
|
||||
"Page3.gif",
|
||||
"page0.jpg",
|
||||
"Page1.jpeg",
|
||||
"Page2.png",
|
||||
"!cover.jpg", // Depending on locale punctuation or numbers might come first (Linux)
|
||||
"page4.webp",
|
||||
"page10.jpg",
|
||||
}
|
||||
c.SortStrings(list)
|
||||
fmt.Println(strings.Join(list, "\n"))
|
||||
}
|
548
cmd/quick_tag.py
Normal file
548
cmd/quick_tag.py
Normal file
@ -0,0 +1,548 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
import pathlib
|
||||
from datetime import datetime
|
||||
from enum import auto
|
||||
from io import BytesIO
|
||||
from typing import Any
|
||||
from typing import cast
|
||||
from typing import TypedDict
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import appdirs
|
||||
import comictaggerlib.cli
|
||||
import imagehash
|
||||
import requests
|
||||
import settngs
|
||||
from comicapi import comicarchive
|
||||
from comicapi import merge
|
||||
from comicapi import utils
|
||||
from comicapi.genericmetadata import GenericMetadata
|
||||
from comicapi.issuestring import IssueString
|
||||
from comictalker.comiccacher import ComicCacher
|
||||
from comictalker.comiccacher import Issue
|
||||
from comictalker.comiccacher import Series
|
||||
from comictalker.comictalker import ComicSeries
|
||||
from comictalker.talker_utils import cleanup_html
|
||||
from comictalker.talkers.comicvine import ComicVineTalker
|
||||
from comictalker.talkers.comicvine import CVIssue
|
||||
from comictalker.talkers.comicvine import CVResult
|
||||
from comictalker.talkers.comicvine import CVSeries
|
||||
from PIL import Image
|
||||
|
||||
logger = logging.getLogger('quick_tag')
|
||||
|
||||
__version__ = '0.1'
|
||||
|
||||
|
||||
class CV(ComicVineTalker):
|
||||
def fetch_comics(self, *, issue_ids: list[str]) -> list[GenericMetadata]:
|
||||
# before we search online, look in our cache, since we might already have this info
|
||||
cvc = ComicCacher(self.cache_folder, self.version)
|
||||
cached_results: list[GenericMetadata] = []
|
||||
needed_issues: list[int] = []
|
||||
for issue_id in issue_ids:
|
||||
cached_issue = cvc.get_issue_info(issue_id, self.id)
|
||||
|
||||
if cached_issue and cached_issue[1]:
|
||||
cached_results.append(
|
||||
self._map_comic_issue_to_metadata(
|
||||
json.loads(cached_issue[0].data), self._fetch_series([int(cached_issue[0].series_id)])[0][0],
|
||||
),
|
||||
)
|
||||
else:
|
||||
needed_issues.append(int(issue_id)) # CV uses integers for it's IDs
|
||||
|
||||
if not needed_issues:
|
||||
return cached_results
|
||||
issue_filter = ""
|
||||
for iid in needed_issues:
|
||||
issue_filter += str(iid) + "|"
|
||||
flt = "id:" + issue_filter.rstrip('|')
|
||||
|
||||
issue_url = urljoin(self.api_url, "issues/")
|
||||
params: dict[str, Any] = {
|
||||
"api_key": self.api_key,
|
||||
"format": "json",
|
||||
"filter": flt,
|
||||
}
|
||||
cv_response: CVResult[list[CVIssue]] = self._get_cv_content(issue_url, params)
|
||||
|
||||
issue_results = cv_response["results"]
|
||||
page = 1
|
||||
offset = 0
|
||||
current_result_count = cv_response["number_of_page_results"]
|
||||
total_result_count = cv_response["number_of_total_results"]
|
||||
|
||||
# see if we need to keep asking for more pages...
|
||||
while current_result_count < total_result_count:
|
||||
page += 1
|
||||
offset += cv_response["number_of_page_results"]
|
||||
|
||||
params["offset"] = offset
|
||||
cv_response = self._get_cv_content(issue_url, params)
|
||||
|
||||
issue_results.extend(cv_response["results"])
|
||||
current_result_count += cv_response["number_of_page_results"]
|
||||
|
||||
series_info = {s[0].id: s[0] for s in self._fetch_series([int(i["volume"]["id"]) for i in issue_results])}
|
||||
|
||||
for issue in issue_results:
|
||||
cvc.add_issues_info(
|
||||
self.id,
|
||||
[
|
||||
Issue(
|
||||
id=str(issue["id"]),
|
||||
series_id=str(issue["volume"]["id"]),
|
||||
data=json.dumps(issue).encode("utf-8"),
|
||||
),
|
||||
],
|
||||
True,
|
||||
)
|
||||
cached_results.append(
|
||||
self._map_comic_issue_to_metadata(issue, series_info[str(issue["volume"]["id"])]),
|
||||
)
|
||||
|
||||
return cached_results
|
||||
|
||||
def _fetch_series(self, series_ids: list[int]) -> list[tuple[ComicSeries, bool]]:
|
||||
# before we search online, look in our cache, since we might already have this info
|
||||
cvc = ComicCacher(self.cache_folder, self.version)
|
||||
cached_results: list[tuple[ComicSeries, bool]] = []
|
||||
needed_series: list[int] = []
|
||||
for series_id in series_ids:
|
||||
cached_series = cvc.get_series_info(str(series_id), self.id)
|
||||
if cached_series is not None:
|
||||
cached_results.append((self._format_series(json.loads(cached_series[0].data)), cached_series[1]))
|
||||
else:
|
||||
needed_series.append(series_id)
|
||||
|
||||
if needed_series == []:
|
||||
return cached_results
|
||||
|
||||
series_filter = ""
|
||||
for vid in needed_series:
|
||||
series_filter += str(vid) + "|"
|
||||
flt = "id:" + series_filter.rstrip('|') # CV uses volume to mean series
|
||||
|
||||
series_url = urljoin(self.api_url, "volumes/") # CV uses volume to mean series
|
||||
params: dict[str, Any] = {
|
||||
"api_key": self.api_key,
|
||||
"format": "json",
|
||||
"filter": flt,
|
||||
}
|
||||
cv_response: CVResult[list[CVSeries]] = self._get_cv_content(series_url, params)
|
||||
|
||||
series_results = cv_response["results"]
|
||||
page = 1
|
||||
offset = 0
|
||||
current_result_count = cv_response["number_of_page_results"]
|
||||
total_result_count = cv_response["number_of_total_results"]
|
||||
|
||||
# see if we need to keep asking for more pages...
|
||||
while current_result_count < total_result_count:
|
||||
page += 1
|
||||
offset += cv_response["number_of_page_results"]
|
||||
|
||||
params["offset"] = offset
|
||||
cv_response = self._get_cv_content(series_url, params)
|
||||
|
||||
series_results.extend(cv_response["results"])
|
||||
current_result_count += cv_response["number_of_page_results"]
|
||||
|
||||
if series_results:
|
||||
for series in series_results:
|
||||
cvc.add_series_info(
|
||||
self.id, Series(id=str(series["id"]), data=json.dumps(series).encode("utf-8")), True,
|
||||
)
|
||||
cached_results.append((self._format_series(series), True))
|
||||
|
||||
return cached_results
|
||||
|
||||
|
||||
class HashType(utils.StrEnum):
|
||||
AHASH = auto()
|
||||
DHASH = auto()
|
||||
PHASH = auto()
|
||||
|
||||
|
||||
class SimpleResult(TypedDict):
|
||||
Distance: int
|
||||
# Mapping of domains (eg comicvine.gamespot.com) to IDs
|
||||
IDList: dict[str, list[str]]
|
||||
|
||||
|
||||
class Hash(TypedDict):
|
||||
Hash: int
|
||||
Kind: str
|
||||
|
||||
|
||||
class Result(TypedDict):
|
||||
# Mapping of domains (eg comicvine.gamespot.com) to IDs
|
||||
IDList: dict[str, list[str]]
|
||||
Distance: int
|
||||
Hash: Hash
|
||||
|
||||
|
||||
def ihash(types: str) -> list[str]:
|
||||
result = []
|
||||
types = types.casefold()
|
||||
choices = ", ".join(HashType)
|
||||
for typ in utils.split(types, ","):
|
||||
if typ not in list(HashType):
|
||||
raise argparse.ArgumentTypeError(f"invalid choice: {typ} (choose from {choices.upper()})")
|
||||
result.append(HashType[typ.upper()])
|
||||
|
||||
if not result:
|
||||
raise argparse.ArgumentTypeError(f"invalid choice: {types} (choose from {choices.upper()})")
|
||||
return result
|
||||
|
||||
|
||||
def settings(manager: settngs.Manager):
|
||||
manager.add_setting(
|
||||
'--url', '-u', default='https://comic-hasher.narnian.us',
|
||||
type=utils.parse_url, help='Website to use for searching cover hashes',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--max', '-m', default=8, type=int,
|
||||
help='Maximum score to allow. Lower score means more accurate',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--simple', '-s', default=False, action=argparse.BooleanOptionalAction,
|
||||
help='Whether to retrieve simple results or full results',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--force-interactive', '-f', default=True, action=argparse.BooleanOptionalAction,
|
||||
help='When not set will automatically tag comics that have a single match with a score of 4 or lower',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--aggressive-filtering', '-a', default=False, action=argparse.BooleanOptionalAction,
|
||||
help='Will filter out worse matches if better matches are found',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--hash', default=['ahash', 'dhash', 'phash'], type=ihash,
|
||||
help='Pick what hashes you want to use to search',
|
||||
)
|
||||
manager.add_setting(
|
||||
'--skip-non-exact', default=True, action=argparse.BooleanOptionalAction,
|
||||
help='Skip non-exact matches if we have exact matches',
|
||||
)
|
||||
manager.add_setting('--cv-api-key', '-c')
|
||||
manager.add_setting('comic_archive', type=pathlib.Path)
|
||||
|
||||
|
||||
def SearchHashes(url: str, simple: bool, max: int, ahash: str, dhash: str, phash: str, skip_non_exact: bool) -> list[SimpleResult] | list[Result]:
|
||||
resp = requests.get(
|
||||
urljoin(url, '/match_cover_hash'),
|
||||
{
|
||||
'simple': simple,
|
||||
'max': max,
|
||||
'ahash': ahash,
|
||||
'dhash': dhash,
|
||||
'phash': phash,
|
||||
'skipNonExact': skip_non_exact,
|
||||
},
|
||||
)
|
||||
if resp.status_code != 200:
|
||||
try:
|
||||
text = resp.json()['msg']
|
||||
except Exception:
|
||||
text = resp.text
|
||||
logger.error('message from server: %s', text)
|
||||
raise SystemExit(3)
|
||||
return resp.json()['results']
|
||||
|
||||
|
||||
def get_simple_results(results: list[SimpleResult], cv_api_key: str | None = None) -> list[tuple[int, GenericMetadata]]:
|
||||
cache_dir = pathlib.Path(appdirs.user_cache_dir('quick_tag'))
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
cv = CV(f"quick_tag/{__version__}", cache_dir)
|
||||
cv.parse_settings({
|
||||
'comicvine_key': cv_api_key,
|
||||
'cv_use_series_start_as_volume': True,
|
||||
})
|
||||
md_results: list[tuple[int, GenericMetadata]] = []
|
||||
results.sort(key=lambda r: r['Distance'])
|
||||
all_cv_ids = set()
|
||||
for res in results:
|
||||
all_cv_ids.update(res['IDList']['comicvine.gamespot.com'])
|
||||
# Do a bulk feth of basic issue data
|
||||
mds = cv.fetch_comics(issue_ids=list(all_cv_ids))
|
||||
|
||||
# Re-associate the md to the distance
|
||||
for res in results:
|
||||
for md in mds:
|
||||
if md.issue_id in res['IDList']['comicvine.gamespot.com']:
|
||||
md_results.append((res['Distance'], md))
|
||||
return md_results
|
||||
|
||||
|
||||
def get_results(results: list[Result], cv_api_key: str | None = None) -> list[tuple[int, Hash, GenericMetadata]]:
|
||||
cache_dir = pathlib.Path(appdirs.user_cache_dir('quick_tag'))
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
cv = CV(f"quick_tag/{__version__}", cache_dir)
|
||||
cv.parse_settings({
|
||||
'comicvine_key': cv_api_key,
|
||||
'cv_use_series_start_as_volume': True,
|
||||
})
|
||||
md_results: list[tuple[int, Hash, GenericMetadata]] = []
|
||||
results.sort(key=lambda r: r['Distance'])
|
||||
all_cv_ids = set()
|
||||
for res in results:
|
||||
all_cv_ids.update(res['IDList']['comicvine.gamespot.com'])
|
||||
# Do a bulk feth of basic issue data
|
||||
mds = cv.fetch_comics(issue_ids=list(all_cv_ids))
|
||||
|
||||
# Re-associate the md to the distance
|
||||
for res in results:
|
||||
for md in mds:
|
||||
if md.issue_id in res['IDList']['comicvine.gamespot.com']:
|
||||
md_results.append((res['Distance'], res['Hash'], md))
|
||||
return md_results
|
||||
|
||||
|
||||
def filter_simple_results(results: list[SimpleResult], force_interactive=True, aggressive_filtering=False) -> list[SimpleResult]:
|
||||
if not force_interactive:
|
||||
# If there is a single exact match return it
|
||||
exact = [r for r in results if r['Distance'] == 0]
|
||||
if len(exact) == 1:
|
||||
return exact
|
||||
|
||||
# If ther are more than 4 results and any are better than 6 return the first group of results
|
||||
if len(results) > 4:
|
||||
dist: list[tuple[int, list[SimpleResult]]] = []
|
||||
filtered_results: list[SimpleResult] = []
|
||||
for distance, group in itertools.groupby(results, key=lambda r: r['Distance']):
|
||||
dist.append((distance, list(group)))
|
||||
if aggressive_filtering and dist[0][0] < 6:
|
||||
for _, res in dist[:1]:
|
||||
filtered_results.extend(res)
|
||||
return filtered_results
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def filter_results(results: list[Result], force_interactive=True, aggressive_filtering=False) -> list[Result]:
|
||||
ahash_results = sorted([r for r in results if r['Hash']['Kind'] == 'ahash'], key=lambda r: r['Distance'])
|
||||
dhash_results = sorted([r for r in results if r['Hash']['Kind'] == 'dhash'], key=lambda r: r['Distance'])
|
||||
phash_results = sorted([r for r in results if r['Hash']['Kind'] == 'phash'], key=lambda r: r['Distance'])
|
||||
hash_results = [phash_results, dhash_results, ahash_results]
|
||||
if not force_interactive:
|
||||
# If any of the hash types have a single exact match return it. Prefer phash for no particular reason
|
||||
for hashed_results in (phash_results, dhash_results, ahash_results):
|
||||
exact = [r for r in hashed_results if r['Distance'] == 0]
|
||||
if len(exact) == 1:
|
||||
return exact
|
||||
|
||||
# If any of the hash types have more than 4 results and they have results better than 6 return the first group of results for each hash type
|
||||
for i, hashed_results in enumerate(hash_results):
|
||||
filtered_results: list[Result] = []
|
||||
if len(hashed_results) > 4:
|
||||
dist: list[tuple[int, list[Result]]] = []
|
||||
for distance, group in itertools.groupby(hashed_results, key=lambda r: r['Distance']):
|
||||
dist.append((distance, list(group)))
|
||||
|
||||
if aggressive_filtering and dist[0][0] < 6:
|
||||
for _, res in dist[:1]:
|
||||
filtered_results.extend(res)
|
||||
|
||||
if filtered_results:
|
||||
hash_results[i] = filtered_results
|
||||
|
||||
return list(itertools.chain(*hash_results))
|
||||
|
||||
|
||||
def display_simple_results(md_results: list[tuple[int, GenericMetadata]], ca: comictaggerlib.cli.ComicArchive, force_interactive=True) -> GenericMetadata:
|
||||
filename_md = ca.metadata_from_filename(utils.Parser.COMICFN2DICT)
|
||||
if len(md_results) < 1:
|
||||
logger.warning('No results found for comic')
|
||||
raise SystemExit(4)
|
||||
if not force_interactive:
|
||||
if len(md_results) == 1 and md_results[0][0] <= 4:
|
||||
return md_results[0][1]
|
||||
series_match = []
|
||||
for score, md in md_results:
|
||||
if (
|
||||
score < 10
|
||||
and filename_md.series
|
||||
and md.series
|
||||
and utils.titles_match(filename_md.series, md.series)
|
||||
and IssueString(filename_md.issue).as_string() == IssueString(md.issue).as_string()
|
||||
):
|
||||
series_match.append(md)
|
||||
if len(series_match) == 1:
|
||||
return series_match[0]
|
||||
|
||||
md_results.sort(key=lambda r: (r[0], len(r[1].publisher or '')))
|
||||
for counter, r in enumerate(md_results, 1):
|
||||
print(
|
||||
' {:2}. score: {} [{:15}] ({:02}/{:04}) - {} #{} - {}'.format(
|
||||
counter,
|
||||
r[0],
|
||||
r[1].publisher,
|
||||
r[1].month or 0,
|
||||
r[1].year or 0,
|
||||
r[1].series,
|
||||
r[1].issue,
|
||||
r[1].title,
|
||||
),
|
||||
)
|
||||
while True:
|
||||
i = input(
|
||||
f'Please select a result to tag the comic with or "q" to quit: [1-{len(md_results)}] ',
|
||||
).casefold()
|
||||
if (i.isdigit() and int(i) in range(1, len(md_results) + 1)):
|
||||
break
|
||||
if i == 'q':
|
||||
logger.warning('User quit without saving metadata')
|
||||
raise SystemExit(4)
|
||||
|
||||
return md_results[int(i) - 1][1]
|
||||
|
||||
|
||||
def display_results(md_results: list[tuple[int, Hash, GenericMetadata]], ca: comictaggerlib.cli.ComicArchive, force_interactive=True) -> GenericMetadata:
|
||||
filename_md = ca.metadata_from_filename(utils.Parser.COMICFN2DICT)
|
||||
if len(md_results) < 1:
|
||||
logger.warning('No results found for comic')
|
||||
raise SystemExit(4)
|
||||
if not force_interactive:
|
||||
if len(md_results) == 1 and md_results[0][0] <= 4:
|
||||
return md_results[0][2]
|
||||
series_match = []
|
||||
for score, hash, md in md_results:
|
||||
if (
|
||||
score < 10
|
||||
and filename_md.series
|
||||
and md.series
|
||||
and utils.titles_match(filename_md.series, md.series)
|
||||
and IssueString(filename_md.issue).as_string() == IssueString(md.issue).as_string()
|
||||
):
|
||||
series_match.append(md)
|
||||
if len(series_match) == 1:
|
||||
return series_match[0]
|
||||
md_results.sort(key=lambda r: (r[0], len(r[2].publisher or ''), r[1]["Kind"]))
|
||||
for counter, r in enumerate(md_results, 1):
|
||||
print(
|
||||
' {:2}. score: {} {}: {:064b} [{:15}] ({:02}/{:04}) - {} #{} - {}'.format(
|
||||
counter,
|
||||
r[0],
|
||||
r[1]["Kind"],
|
||||
r[1]["Hash"],
|
||||
r[2].publisher,
|
||||
r[2].month or 0,
|
||||
r[2].year or 0,
|
||||
r[2].series,
|
||||
r[2].issue,
|
||||
r[2].title,
|
||||
),
|
||||
)
|
||||
while True:
|
||||
i = input(
|
||||
f'Please select a result to tag the comic with or "q" to quit: [1-{len(md_results)}] ',
|
||||
).casefold()
|
||||
if (i.isdigit() and int(i) in range(1, len(md_results) + 1)):
|
||||
break
|
||||
if i == 'q':
|
||||
logger.warning('User quit without saving metadata')
|
||||
raise SystemExit(4)
|
||||
|
||||
return md_results[int(i) - 1][2]
|
||||
|
||||
|
||||
def fetch_full_issue_data(md: GenericMetadata, cv_api_key: str | None = None) -> GenericMetadata:
|
||||
cache_dir = pathlib.Path(appdirs.user_cache_dir('quick_tag'))
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
cv = CV(f"quick_tag/{__version__}", cache_dir)
|
||||
cv.parse_settings({
|
||||
'comicvine_key': cv_api_key,
|
||||
'cv_use_series_start_as_volume': True,
|
||||
})
|
||||
return cv.fetch_comic_data(issue_id=md.issue_id)
|
||||
|
||||
|
||||
def prepare_metadata(md: GenericMetadata, new_md: GenericMetadata, clear_tags: bool, auto_imprint: bool, remove_html_tables: bool) -> GenericMetadata:
|
||||
|
||||
final_md = md.copy()
|
||||
if clear_tags:
|
||||
final_md = GenericMetadata()
|
||||
|
||||
final_md.overlay(new_md, merge.Mode.OVERLAY, True)
|
||||
|
||||
issue_id = ''
|
||||
if final_md.issue_id:
|
||||
issue_id = f" [Issue ID {final_md.issue_id}]"
|
||||
|
||||
origin = ''
|
||||
if final_md.data_origin is not None:
|
||||
origin = f" using info from {final_md.data_origin.name}"
|
||||
notes = f"Tagged with quick_tag {__version__}{origin} on {datetime.now():%Y-%m-%d %H:%M:%S}.{issue_id}"
|
||||
|
||||
if auto_imprint:
|
||||
final_md.fix_publisher()
|
||||
|
||||
return final_md.replace(
|
||||
is_empty=False,
|
||||
notes=utils.combine_notes(final_md.notes, notes, 'Tagged with quick_tag'),
|
||||
description=cleanup_html(final_md.description, remove_html_tables),
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
manager = settngs.Manager('Simple comictagging script using ImageHash: https://pypi.org/project/ImageHash/')
|
||||
manager.add_group('runtime', settings)
|
||||
opts, _ = manager.parse_cmdline()
|
||||
url: utils.Url = opts['runtime']['url']
|
||||
max_hamming_distance: int = opts['runtime']['max']
|
||||
simple: bool = opts['runtime']['simple']
|
||||
|
||||
ca = comicarchive.ComicArchive(opts['runtime']['comic_archive'])
|
||||
if not ca.seems_to_be_a_comic_archive():
|
||||
logger.error('Could not open %s as an archive', ca.path)
|
||||
raise SystemExit(1)
|
||||
|
||||
try:
|
||||
tags = ca.read_tags('cr')
|
||||
cover_index = tags.get_cover_page_index_list()[0]
|
||||
cover_image = Image.open(BytesIO(ca.get_page(cover_index)))
|
||||
except Exception:
|
||||
logger.exception('Unable to read cover image from archive')
|
||||
raise SystemExit(2)
|
||||
print('Tagging: ', ca.path)
|
||||
|
||||
print("hashing cover")
|
||||
phash = dhash = ahash = ''
|
||||
if HashType.AHASH in opts['runtime']['hash']:
|
||||
ahash = imagehash.average_hash(cover_image)
|
||||
if HashType.DHASH in opts['runtime']['hash']:
|
||||
dhash = imagehash.dhash(cover_image)
|
||||
if HashType.PHASH in opts['runtime']['hash']:
|
||||
phash = imagehash.phash(cover_image)
|
||||
|
||||
print("Searching hashes")
|
||||
results = SearchHashes(url.url, simple, max_hamming_distance, str(ahash), str(dhash), str(phash), opts['runtime']['skip_non_exact'])
|
||||
|
||||
print("Retrieving basic ComicVine data")
|
||||
if simple:
|
||||
filtered_results = filter_simple_results(cast(list[SimpleResult], results), opts['runtime']['force_interactive'], opts['runtime']['aggressive_filtering'])
|
||||
metadata_results = get_simple_results(filtered_results, opts['runtime']['cv_api_key'])
|
||||
chosen_result = display_simple_results(metadata_results, ca, opts['runtime']['force_interactive'])
|
||||
else:
|
||||
filtered_results = filter_results(cast(list[Result], results), opts['runtime']['force_interactive'], opts['runtime']['aggressive_filtering'])
|
||||
metadata_results = get_results(filtered_results, opts['runtime']['cv_api_key'])
|
||||
chosen_result = display_results(metadata_results, ca, opts['runtime']['force_interactive'])
|
||||
|
||||
full_cv_md = fetch_full_issue_data(chosen_result, opts['runtime']['cv_api_key'])
|
||||
|
||||
if ca.write_tags(prepare_metadata(tags, full_cv_md, clear_tags=False, auto_imprint=True, remove_html_tables=True), 'cr'):
|
||||
print(f'successfully saved metadata to {ca.path}')
|
||||
raise SystemExit(0)
|
||||
logger.error('Failed to save metadata to %s', ca.path)
|
||||
raise SystemExit(2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
54
go.mod
54
go.mod
@ -1,38 +1,42 @@
|
||||
module gitea.narnian.us/lordwelch/image-hasher
|
||||
module gitea.narnian.us/lordwelch/comic-hasher
|
||||
|
||||
go 1.22.1
|
||||
|
||||
toolchain go1.22.2
|
||||
|
||||
require (
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240502010648-cb5a8237c420
|
||||
github.com/anthonynsimon/bild v0.13.0
|
||||
github.com/corona10/goimagehash v1.1.0
|
||||
github.com/gen2brain/avif v0.3.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/spakin/netpbm v1.3.0
|
||||
github.com/zitadel/oidc v1.13.4
|
||||
golang.org/x/image v0.7.0
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240812025715-33ff96e45f00
|
||||
github.com/disintegration/imaging v1.6.3-0.20201218193011-d40f48ce0f09
|
||||
github.com/fmartingr/go-comicinfo/v2 v2.0.2
|
||||
github.com/mholt/archiver/v4 v4.0.0-alpha.8
|
||||
golang.org/x/image v0.19.0
|
||||
golang.org/x/text v0.17.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.7.1 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||
github.com/tetratelabs/wazero v1.7.1 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/gorilla/schema v1.2.0 // indirect
|
||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/oauth2 v0.7.0 // indirect
|
||||
golang.org/x/text v0.14.0
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/bodgit/plumbing v1.2.0 // indirect
|
||||
github.com/bodgit/sevenzip v1.3.0 // indirect
|
||||
github.com/bodgit/windows v1.0.0 // indirect
|
||||
github.com/connesc/cipherio v0.2.1 // indirect
|
||||
github.com/dsnet/compress v0.0.1 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
||||
github.com/therootcompany/xz v1.0.1 // indirect
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
|
||||
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
|
||||
)
|
||||
|
||||
replace golang.org/x/text v0.17.0 => github.com/lordwelch/text v0.0.0-20240505231825-4893f344170f
|
||||
|
382
go.sum
382
go.sum
@ -1,136 +1,296 @@
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240502010648-cb5a8237c420 h1:yOLLICl64x5lMeYYhUABETfsd4ZO0tQjBSVfVLKbuz8=
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240502010648-cb5a8237c420/go.mod h1:usqHLOGYaIIBV579DJAlZapMEUImOdzleurWyeahfDI=
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
||||
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
||||
cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
|
||||
cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240812025715-33ff96e45f00 h1:RNqy72W8N/mlnZGxvPoC9ch+zI3GlAGVYbBGpXOHmuY=
|
||||
gitea.narnian.us/lordwelch/goimagehash v0.0.0-20240812025715-33ff96e45f00/go.mod h1:kLCabSskchnLGV41s6YVXZdnLYwAxKwdXPlEuyFhC9E=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/anthonynsimon/bild v0.13.0 h1:mN3tMaNds1wBWi1BrJq0ipDBhpkooYfu7ZFSMhXt1C8=
|
||||
github.com/anthonynsimon/bild v0.13.0/go.mod h1:tpzzp0aYkAsMi1zmfhimaDyX1xjn2OUc1AJZK/TF0AE=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
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/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/bodgit/plumbing v1.2.0 h1:gg4haxoKphLjml+tgnecR4yLBV5zo4HAZGCtAh3xCzM=
|
||||
github.com/bodgit/plumbing v1.2.0/go.mod h1:b9TeRi7Hvc6Y05rjm8VML3+47n4XTZPtQ/5ghqic2n8=
|
||||
github.com/bodgit/sevenzip v1.3.0 h1:1ljgELgtHqvgIp8W8kgeEGHIWP4ch3xGI8uOBZgLVKY=
|
||||
github.com/bodgit/sevenzip v1.3.0/go.mod h1:omwNcgZTEooWM8gA/IJ2Nk/+ZQ94+GsytRzOJJ8FBlM=
|
||||
github.com/bodgit/windows v1.0.0 h1:rLQ/XjsleZvx4fR1tB/UxQrK+SJ2OFHzfPjLWWOhDIA=
|
||||
github.com/bodgit/windows v1.0.0/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/connesc/cipherio v0.2.1 h1:FGtpTPMbKNNWByNrr9aEBtaJtXjqOzkIXNYJp6OEycw=
|
||||
github.com/connesc/cipherio v0.2.1/go.mod h1:ukY0MWJDFnJEbXMQtOcn2VmTpRfzcTz4OoVrWGGJZcA=
|
||||
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.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
|
||||
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gen2brain/avif v0.3.1 h1:womS2LKvhS/dSR3zIKUxtJW+riGlY48akGWqc+YgHtE=
|
||||
github.com/gen2brain/avif v0.3.1/go.mod h1:s9sI2zo2cF6EdyRVCtnIfwL/Qb3k0TkOIEsz6ovK1ms=
|
||||
github.com/disintegration/imaging v1.6.3-0.20201218193011-d40f48ce0f09 h1:MJFqtdxTq94XqUgg7DcGCaOIXrDTJE/tPHK66Jshguc=
|
||||
github.com/disintegration/imaging v1.6.3-0.20201218193011-d40f48ce0f09/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
|
||||
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
|
||||
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fmartingr/go-comicinfo/v2 v2.0.2 h1:VppvrHr8C4+iktBTOd7vzTMNbVecZ7F/Ji1kPTOIGg4=
|
||||
github.com/fmartingr/go-comicinfo/v2 v2.0.2/go.mod h1:LUu/VenzEJkJt2PN49Kfpe50IgZkVkvH0m9Fnld8Dh0=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
|
||||
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jeremija/gosubmit v0.2.7 h1:At0OhGCFGPXyjPYAsCchoBUhE099pcBXmsb4iZqROIc=
|
||||
github.com/jeremija/gosubmit v0.2.7/go.mod h1:Ui+HS073lCFREXBbdfrJzMB57OI/bdxTiLtrDHHhFPI=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
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/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
|
||||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
|
||||
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lordwelch/text v0.0.0-20240505231825-4893f344170f h1:RMKTfrT4gjJfmB/aWuvCcFxUSvWAJfOAc5khGL6ASjk=
|
||||
github.com/lordwelch/text v0.0.0-20240505231825-4893f344170f/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrSSDunscGsRM=
|
||||
github.com/mholt/archiver/v4 v4.0.0-alpha.8/go.mod h1:5f7FUYGXdJWUjESffJaYR4R60VhnHxb2X3T1teMyv5A=
|
||||
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 h1:e3mzJFJs4k83GXBEiTaQ5HgSc/kOK8q0rDaRO0MPaOk=
|
||||
github.com/nwaples/rardecode/v2 v2.0.0-beta.2/go.mod h1:yntwv/HfMc/Hbvtq9I19D1n58te3h6KsqCf3GxyfBGY=
|
||||
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0=
|
||||
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
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/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo=
|
||||
github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spakin/netpbm v1.3.0 h1:eDX7VvrkN5sHXW0luZXRA4AKDlLmu0E5sNxJ7VSTwxc=
|
||||
github.com/spakin/netpbm v1.3.0/go.mod h1:Q+ep6vNv1G44qSWp0wt3Y9o1m/QXjmaXZIFC0PMVpq0=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
|
||||
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/zitadel/logging v0.3.4 h1:9hZsTjMMTE3X2LUi0xcF9Q9EdLo+FAezeu52ireBbHM=
|
||||
github.com/zitadel/logging v0.3.4/go.mod h1:aPpLQhE+v6ocNK0TWrBrd363hZ95KcI17Q1ixAQwZF0=
|
||||
github.com/zitadel/oidc v1.13.4 h1:+k2GKqP9Ld9S2MSFlj+KaNsoZ3J9oy+Ezw51EzSFuC8=
|
||||
github.com/zitadel/oidc v1.13.4/go.mod h1:3h2DhUcP02YV6q/CA/BG4yla0o6rXjK+DkJGK/dwJfw=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw=
|
||||
github.com/therootcompany/xz v1.0.1/go.mod h1:3K3UH1yCKgBneZYhuQUvJ9HPD19UEXEI0BWbMn8qNMY=
|
||||
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
|
||||
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
|
||||
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go4.org v0.0.0-20200411211856-f5505b9728dd h1:BNJlw5kRTzdmyfh5U8F93HA2OwkP7ZGwA51eJ/0wKOU=
|
||||
go4.org v0.0.0-20200411211856-f5505b9728dd/go.mod h1:CIiUVy99QCPfoE13bO4EZaz5GZMZXMSBGhxRdsvzbkg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
|
||||
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
|
||||
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
|
||||
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
|
||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g=
|
||||
golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
|
||||
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
|
159
hashing.go
Normal file
159
hashing.go
Normal file
@ -0,0 +1,159 @@
|
||||
package ch
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"image"
|
||||
"log"
|
||||
"math/bits"
|
||||
"runtime"
|
||||
"slices"
|
||||
|
||||
"gitea.narnian.us/lordwelch/goimagehash"
|
||||
)
|
||||
|
||||
//go:embed hashes.gz
|
||||
var Hashes []byte
|
||||
|
||||
const (
|
||||
H0 uint64 = 0b11111111 << (8 * iota)
|
||||
H1
|
||||
H2
|
||||
H3
|
||||
H4
|
||||
H5
|
||||
H6
|
||||
H7
|
||||
)
|
||||
|
||||
const (
|
||||
Shift0 = (8 * iota)
|
||||
Shift1
|
||||
Shift2
|
||||
Shift3
|
||||
Shift4
|
||||
Shift5
|
||||
Shift6
|
||||
Shift7
|
||||
)
|
||||
|
||||
const (
|
||||
ComicVine Source = "comicvine.gamespot.com"
|
||||
)
|
||||
|
||||
type Source string
|
||||
|
||||
type Match struct {
|
||||
Distance int
|
||||
Hash uint64
|
||||
}
|
||||
|
||||
type ID struct {
|
||||
Domain, ID string
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
IDs []string // domain:id
|
||||
Distance int
|
||||
Hash ImageHash
|
||||
}
|
||||
|
||||
type Im struct {
|
||||
Im image.Image
|
||||
Format string
|
||||
Domain Source
|
||||
ID, Path string
|
||||
}
|
||||
|
||||
type Hash struct {
|
||||
Ahash *goimagehash.ImageHash
|
||||
Dhash *goimagehash.ImageHash
|
||||
Phash *goimagehash.ImageHash
|
||||
Domain Source
|
||||
ID string
|
||||
}
|
||||
|
||||
type ImageHash struct {
|
||||
Hash uint64
|
||||
Kind goimagehash.Kind
|
||||
}
|
||||
|
||||
func Atleast(maxDistance int, searchHash uint64, hashes []uint64) []Match {
|
||||
matchingHashes := make([]Match, 0, len(hashes)/2) // hope that we don't need all of them
|
||||
for _, storedHash := range hashes {
|
||||
distance := bits.OnesCount64(searchHash ^ storedHash)
|
||||
if distance <= maxDistance {
|
||||
matchingHashes = append(matchingHashes, Match{distance, storedHash})
|
||||
}
|
||||
}
|
||||
return matchingHashes
|
||||
}
|
||||
|
||||
func Insert[S ~[]E, E cmp.Ordered](slice S, item E) S {
|
||||
index, itemFound := slices.BinarySearch(slice, item)
|
||||
if itemFound {
|
||||
return slice
|
||||
}
|
||||
return slices.Insert(slice, index, item)
|
||||
}
|
||||
|
||||
func MemStats() uint64 {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
return m.Alloc
|
||||
}
|
||||
|
||||
func HashImage(i Im) Hash {
|
||||
if i.Format == "webp" {
|
||||
i.Im = goimagehash.FancyUpscale(i.Im.(*image.YCbCr))
|
||||
}
|
||||
|
||||
var (
|
||||
err error = nil
|
||||
ahash *goimagehash.ImageHash
|
||||
dhash *goimagehash.ImageHash
|
||||
phash *goimagehash.ImageHash
|
||||
)
|
||||
|
||||
ahash, err = goimagehash.AverageHash(i.Im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to ahash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return Hash{}
|
||||
}
|
||||
dhash, err = goimagehash.DifferenceHash(i.Im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to dhash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return Hash{}
|
||||
}
|
||||
phash, err = goimagehash.PerceptionHash(i.Im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to phash Image: %s", err)
|
||||
log.Println(msg)
|
||||
return Hash{}
|
||||
}
|
||||
return Hash{
|
||||
Ahash: ahash,
|
||||
Dhash: dhash,
|
||||
Phash: phash,
|
||||
Domain: i.Domain,
|
||||
ID: i.ID,
|
||||
}
|
||||
}
|
||||
|
||||
func SplitHash(hash uint64) [8]uint8 {
|
||||
return [8]uint8{
|
||||
uint8((hash & H7) >> Shift7),
|
||||
uint8((hash & H6) >> Shift6),
|
||||
uint8((hash & H5) >> Shift5),
|
||||
uint8((hash & H4) >> Shift4),
|
||||
uint8((hash & H3) >> Shift3),
|
||||
uint8((hash & H2) >> Shift2),
|
||||
uint8((hash & H1) >> Shift1),
|
||||
uint8((hash & H0) >> Shift0),
|
||||
}
|
||||
}
|
||||
|
||||
type IDList map[Source][]string // IDs is a map of domain to ID eg IDs['comicvine.gamespot.com'] = []string{"1235"}
|
377
main.go
377
main.go
@ -1,377 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/image/bmp"
|
||||
_ "golang.org/x/image/tiff"
|
||||
_ "golang.org/x/image/vp8"
|
||||
_ "golang.org/x/image/vp8l"
|
||||
_ "golang.org/x/image/webp"
|
||||
|
||||
"github.com/corona10/goimagehash"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/zitadel/oidc/pkg/client/rp"
|
||||
httphelper "github.com/zitadel/oidc/pkg/http"
|
||||
"github.com/zitadel/oidc/pkg/oidc"
|
||||
)
|
||||
|
||||
const (
|
||||
h_1 uint64 = 0b11111111 << (8 * iota)
|
||||
h_2
|
||||
h_3
|
||||
h_4
|
||||
h_5
|
||||
h_6
|
||||
h_7
|
||||
h_8
|
||||
)
|
||||
|
||||
const (
|
||||
shift_1 = (8 * iota)
|
||||
shift_2
|
||||
shift_3
|
||||
shift_4
|
||||
shift_5
|
||||
shift_6
|
||||
shift_7
|
||||
shift_8
|
||||
)
|
||||
|
||||
type Cover map[string][]string // IDs is a map of domain to ID eg IDs['comicvine.gamespot.com'] = []string{"1235"}
|
||||
|
||||
// type Cover struct {
|
||||
// AHash uint64
|
||||
// DHash uint64
|
||||
// PHash uint64
|
||||
// IDs map[string][]string // IDs is a map of domain to ID eg IDs['comicvine.gamespot.com'] = []string{"1235"}
|
||||
// }
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
mux *http.ServeMux
|
||||
BaseURL *url.URL
|
||||
token chan<- *oidc.Tokens
|
||||
ahash [8]map[uint8]uint32
|
||||
dhash [8]map[uint8]uint32
|
||||
phash [8]map[uint8]uint32
|
||||
fAhash map[uint64]uint32
|
||||
fDhash map[uint64]uint32
|
||||
fPhash map[uint64]uint32
|
||||
IDToCover map[string]uint32 // IDToCover is a map of domain:id to an index to covers eg IDToCover['comicvine.gamespot.com:12345'] = 0
|
||||
covers []Cover
|
||||
// hashes are a uint64 split into 8 pieces or a unint64 for quick lookup, the value is an index to covers
|
||||
}
|
||||
|
||||
var key = []byte(uuid.New().String())[:16]
|
||||
|
||||
func main() {
|
||||
// mustDropPrivileges()
|
||||
startServer()
|
||||
}
|
||||
|
||||
func (s *Server) authenticated(w http.ResponseWriter, r *http.Request) (string, bool) {
|
||||
return strings.TrimSpace("lordwelch"), true
|
||||
}
|
||||
|
||||
func (s *Server) setupOauthHandlers() error {
|
||||
redirectURI := *s.BaseURL
|
||||
redirectURI.Path = "/oauth/callback"
|
||||
successURI := *s.BaseURL
|
||||
successURI.Path = "/success"
|
||||
failURI := *s.BaseURL
|
||||
failURI.RawQuery = url.Values{"auth": []string{"fail"}}.Encode()
|
||||
|
||||
cookieHandler := httphelper.NewCookieHandler(key, key, httphelper.WithUnsecure())
|
||||
|
||||
options := []rp.Option{
|
||||
rp.WithCookieHandler(cookieHandler),
|
||||
rp.WithVerifierOpts(rp.WithIssuedAtOffset(5 * time.Second)),
|
||||
}
|
||||
|
||||
provider, err := rp.NewRelyingPartyOIDC(os.Getenv("COMICHASHER_PROVIDER_URL"), os.Getenv("COMICHASHER_CLIENT_ID"), os.Getenv("COMICHASHER_CLIENT_SECRET"), redirectURI.String(), strings.Split(os.Getenv("COMICHASHER_SCOPES"), ","), options...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating provider: %w", err)
|
||||
}
|
||||
|
||||
// generate some state (representing the state of the user in your application,
|
||||
// e.g. the page where he was before sending him to login
|
||||
state := func() string {
|
||||
return uuid.New().String()
|
||||
}
|
||||
|
||||
// register the AuthURLHandler at your preferred path
|
||||
// the AuthURLHandler creates the auth request and redirects the user to the auth server
|
||||
// including state handling with secure cookie and the possibility to use PKCE
|
||||
s.mux.Handle("/login", rp.AuthURLHandler(state, provider))
|
||||
|
||||
// for demonstration purposes the returned userinfo response is written as JSON object onto response
|
||||
marshalUserinfo := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string, rp rp.RelyingParty) {
|
||||
s.token <- tokens
|
||||
w.Header().Add("location", successURI.String())
|
||||
w.WriteHeader(301)
|
||||
}
|
||||
|
||||
// register the CodeExchangeHandler at the callbackPath
|
||||
// the CodeExchangeHandler handles the auth response, creates the token request and calls the callback function
|
||||
// with the returned tokens from the token endpoint
|
||||
s.mux.Handle(redirectURI.Path, rp.CodeExchangeHandler(marshalUserinfo, provider))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) setupAppHandlers() {
|
||||
s.mux.HandleFunc("/add_cover", s.add_cover)
|
||||
s.mux.HandleFunc("/get_cover", s.get_cover)
|
||||
s.mux.HandleFunc("/match_cover_hash", s.match_cover_hash)
|
||||
}
|
||||
|
||||
func (s *Server) get_cover(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
domain = strings.TrimSpace(values.Get("domain"))
|
||||
id = strings.TrimSpace(values.Get("id"))
|
||||
)
|
||||
if id == "" {
|
||||
log.Println("No ID Provided")
|
||||
http.Error(w, "No ID Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if domain == "" {
|
||||
log.Println("No domain Provided")
|
||||
http.Error(w, "No domain Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if index, ok := s.IDToCover[domain+":"+id]; ok {
|
||||
covers, err := json.Marshal(s.covers[index])
|
||||
if err == nil {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.Write(covers)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) match_cover_hash(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
ahashStr = strings.TrimSpace(values.Get("ahash"))
|
||||
dhashStr = strings.TrimSpace(values.Get("dhash"))
|
||||
phashStr = strings.TrimSpace(values.Get("phash"))
|
||||
ahash uint64
|
||||
dhash uint64
|
||||
phash uint64
|
||||
err error
|
||||
)
|
||||
if ahash, err = strconv.ParseUint(ahashStr, 16, 64); err != nil && ahashStr != "" {
|
||||
log.Printf("could not parse ahash: %s", ahashStr)
|
||||
http.Error(w, "parse fail", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if dhash, err = strconv.ParseUint(dhashStr, 16, 64); err != nil && dhashStr != "" {
|
||||
log.Printf("could not parse dhash: %s", dhashStr)
|
||||
http.Error(w, "parse fail", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if phash, err = strconv.ParseUint(phashStr, 16, 64); err != nil && phashStr != "" {
|
||||
log.Printf("could not parse phash: %s", phashStr)
|
||||
http.Error(w, "parse fail", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if index, ok := s.fAhash[ahash]; ok {
|
||||
covers, err := json.Marshal(s.covers[index])
|
||||
if err == nil {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.Write(covers)
|
||||
return
|
||||
}
|
||||
}
|
||||
if index, ok := s.fDhash[dhash]; ok {
|
||||
covers, err := json.Marshal(s.covers[index])
|
||||
if err == nil {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.Write(covers)
|
||||
return
|
||||
}
|
||||
}
|
||||
if index, ok := s.fPhash[phash]; ok {
|
||||
covers, err := json.Marshal(s.covers[index])
|
||||
if err == nil {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.Write(covers)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprintln(w, "{\"msg\":\"No hashes found\"}")
|
||||
}
|
||||
|
||||
func (s *Server) add_cover(w http.ResponseWriter, r *http.Request) {
|
||||
user, authed := s.authenticated(w, r)
|
||||
if !authed || user == "" {
|
||||
http.Error(w, "Invalid Auth", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var (
|
||||
values = r.URL.Query()
|
||||
domain = strings.TrimSpace(values.Get("domain"))
|
||||
id = strings.TrimSpace(values.Get("id"))
|
||||
)
|
||||
if id == "" {
|
||||
log.Println("No ID Provided")
|
||||
http.Error(w, "No ID Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if domain == "" {
|
||||
log.Println("No domain Provided")
|
||||
http.Error(w, "No domain Provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
im, format, err := image.Decode(r.Body)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to decode Image: %s", err)
|
||||
log.Println(msg)
|
||||
http.Error(w, msg, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
log.Printf("Decoded %s image from %s", format, user)
|
||||
im = &goimagehash.YCbCr{YCbCr: im.(*image.YCbCr)}
|
||||
i := imaging.Resize(im, 9, 8, imaging.Linear)
|
||||
bmp.Encode(w, i)
|
||||
fmt.Println(im.Bounds())
|
||||
|
||||
var (
|
||||
ahash *goimagehash.ImageHash
|
||||
dhash *goimagehash.ImageHash
|
||||
phash *goimagehash.ImageHash
|
||||
)
|
||||
|
||||
ahash, err = goimagehash.AverageHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to ahash Image: %s", err)
|
||||
log.Println(msg)
|
||||
http.Error(w, msg, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
dhash, err = goimagehash.DifferenceHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to dhash Image: %s", err)
|
||||
log.Println(msg)
|
||||
http.Error(w, msg, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
phash, err = goimagehash.PerceptionHash(im)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to phash Image: %s", err)
|
||||
log.Println(msg)
|
||||
http.Error(w, msg, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%#064b\n", ahash.GetHash())
|
||||
fmt.Printf("%#064b\n", dhash.GetHash())
|
||||
fmt.Printf("%#064b\n", phash.GetHash())
|
||||
|
||||
s.covers = append(s.covers, make(Cover))
|
||||
|
||||
s.covers[len(s.covers)-1][domain] = append(s.covers[len(s.covers)-1][domain], id)
|
||||
|
||||
s.IDToCover[domain+":"+id] = uint32(len(s.covers) - 1)
|
||||
|
||||
s.mapHashes(uint32(len(s.covers)-1), ahash, dhash, phash)
|
||||
}
|
||||
|
||||
func (s *Server) mapHashes(index uint32, ahash, dhash, phash *goimagehash.ImageHash) {
|
||||
s.fAhash[ahash.GetHash()] = index
|
||||
s.fDhash[dhash.GetHash()] = index
|
||||
s.fPhash[phash.GetHash()] = index
|
||||
for i, partial_hash := range SplitHash(ahash.GetHash()) {
|
||||
s.ahash[i][partial_hash] = index
|
||||
}
|
||||
for i, partial_hash := range SplitHash(dhash.GetHash()) {
|
||||
s.dhash[i][partial_hash] = index
|
||||
}
|
||||
for i, partial_hash := range SplitHash(phash.GetHash()) {
|
||||
s.phash[i][partial_hash] = index
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) initHashes() {
|
||||
for i := range s.ahash {
|
||||
s.ahash[i] = make(map[uint8]uint32)
|
||||
}
|
||||
for i := range s.dhash {
|
||||
s.dhash[i] = make(map[uint8]uint32)
|
||||
}
|
||||
for i := range s.phash {
|
||||
s.phash[i] = make(map[uint8]uint32)
|
||||
}
|
||||
s.fAhash = make(map[uint64]uint32)
|
||||
s.fDhash = make(map[uint64]uint32)
|
||||
s.fPhash = make(map[uint64]uint32)
|
||||
s.IDToCover = make(map[string]uint32)
|
||||
}
|
||||
|
||||
func SplitHash(hash uint64) [8]uint8 {
|
||||
return [8]uint8{
|
||||
uint8((hash & h_8) >> shift_8),
|
||||
uint8((hash & h_7) >> shift_7),
|
||||
uint8((hash & h_6) >> shift_6),
|
||||
uint8((hash & h_5) >> shift_5),
|
||||
uint8((hash & h_4) >> shift_4),
|
||||
uint8((hash & h_3) >> shift_3),
|
||||
uint8((hash & h_2) >> shift_2),
|
||||
uint8((hash & h_1) >> shift_1),
|
||||
}
|
||||
}
|
||||
|
||||
// func (s *Server) CoverByID(id string) uint32 {
|
||||
// v,ok :=s.IDToCover[id]
|
||||
// return 0
|
||||
// }
|
||||
func (s *Server) FindHashes() {
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
mux := http.NewServeMux()
|
||||
server := Server{
|
||||
token: make(chan *oidc.Tokens),
|
||||
mux: mux,
|
||||
httpServer: &http.Server{
|
||||
Addr: ":8080",
|
||||
Handler: mux,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
},
|
||||
}
|
||||
server.initHashes()
|
||||
// server.setupOauthHandlers()
|
||||
server.setupAppHandlers()
|
||||
err := server.httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
82
privdrop.go
82
privdrop.go
@ -1,82 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type capHeader struct {
|
||||
version uint32
|
||||
pid int
|
||||
}
|
||||
|
||||
type capData struct {
|
||||
effective uint32
|
||||
permitted uint32
|
||||
inheritable uint32
|
||||
}
|
||||
|
||||
type caps struct {
|
||||
hdr capHeader
|
||||
data [2]capData
|
||||
}
|
||||
|
||||
func getCaps() (caps, error) {
|
||||
var c caps
|
||||
|
||||
// Get capability version
|
||||
if _, _, errno := syscall.Syscall(syscall.SYS_CAPGET, uintptr(unsafe.Pointer(&c.hdr)), uintptr(unsafe.Pointer(nil)), 0); errno != 0 {
|
||||
return c, fmt.Errorf("SYS_CAPGET: %v", errno)
|
||||
}
|
||||
|
||||
// Get current capabilities
|
||||
if _, _, errno := syscall.Syscall(syscall.SYS_CAPGET, uintptr(unsafe.Pointer(&c.hdr)), uintptr(unsafe.Pointer(&c.data[0])), 0); errno != 0 {
|
||||
return c, fmt.Errorf("SYS_CAPGET: %v", errno)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// mustDropPrivileges executes the program in a child process, dropping root
|
||||
// privileges, but retaining the CAP_SYS_TIME capability to change the system
|
||||
// clock.
|
||||
func mustDropPrivileges() {
|
||||
if os.Getenv("PRIVILEGES_DROPPED") == "1" {
|
||||
return
|
||||
}
|
||||
|
||||
// From include/uapi/linux/capability.h:
|
||||
// Allow setting the real-time clock
|
||||
const CAP_SYS_TIME = 25
|
||||
|
||||
caps, err := getCaps()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Add CAP_SYS_TIME to the permitted and inheritable capability mask,
|
||||
// otherwise we will not be able to add it to the ambient capability mask.
|
||||
caps.data[0].permitted |= 1 << uint(CAP_SYS_TIME)
|
||||
caps.data[0].inheritable |= 1 << uint(CAP_SYS_TIME)
|
||||
|
||||
if _, _, errno := syscall.Syscall(syscall.SYS_CAPSET, uintptr(unsafe.Pointer(&caps.hdr)), uintptr(unsafe.Pointer(&caps.data[0])), 0); errno != 0 {
|
||||
log.Fatalf("SYS_CAPSET: %v", errno)
|
||||
}
|
||||
|
||||
cmd := exec.Command(os.Args[0])
|
||||
cmd.Env = append(os.Environ(), "PRIVILEGES_DROPPED=1")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Credential: &syscall.Credential{
|
||||
Uid: 65534,
|
||||
Gid: 65534,
|
||||
},
|
||||
AmbientCaps: []uintptr{CAP_SYS_TIME},
|
||||
}
|
||||
log.Fatal(cmd.Run())
|
||||
}
|
6
pyproject.toml
Normal file
6
pyproject.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.setuptools_scm]
|
||||
local_scheme = "no-local-version"
|
62
setup.cfg
Normal file
62
setup.cfg
Normal file
@ -0,0 +1,62 @@
|
||||
[metadata]
|
||||
name = comic_hasher
|
||||
description = python tools to support comic-hasher
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://gitea.narnian.us/lordwelch/comic-hasher
|
||||
author = Timmy Welch
|
||||
author_email = timmy@narnian.us
|
||||
license = MIT
|
||||
license_files = LICENSE
|
||||
classifiers =
|
||||
License :: OSI Approved :: MIT License
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3 :: Only
|
||||
Programming Language :: Python :: Implementation :: CPython
|
||||
Programming Language :: Python :: Implementation :: PyPy
|
||||
|
||||
[options]
|
||||
py_modules = quick_tag
|
||||
install_requires =
|
||||
comictagger==1.6.0a20
|
||||
imagehash
|
||||
python_requires = >=3.9
|
||||
package_dir =
|
||||
=cmd
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts = quick-tag=quick_tag:main
|
||||
|
||||
[pep8]
|
||||
ignore = E265,E501
|
||||
max_line_length = 120
|
||||
|
||||
[flake8]
|
||||
extend-ignore = E501, A003
|
||||
max_line_length = 120
|
||||
per-file-ignores =
|
||||
*_test.py: LN001
|
||||
|
||||
[coverage:run]
|
||||
plugins = covdefaults
|
||||
|
||||
[coverage:report]
|
||||
fail_under = 95
|
||||
|
||||
[mypy]
|
||||
check_untyped_defs = true
|
||||
disallow_any_generics = true
|
||||
warn_return_any = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_untyped_defs = true
|
||||
no_implicit_optional = true
|
||||
warn_redundant_casts = true
|
||||
warn_unused_ignores = true
|
||||
|
||||
[mypy-testing.*]
|
||||
warn_return_any = false
|
||||
disallow_untyped_defs = false
|
||||
|
||||
[mypy-tests.*]
|
||||
warn_return_any = false
|
||||
disallow_untyped_defs = false
|
Loading…
x
Reference in New Issue
Block a user