mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-05-18 06:01:56 +02:00
Add untracked files
This commit is contained in:
parent
c667707704
commit
43d2ced820
46
clustering.go
Normal file
46
clustering.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"github.com/steakknife/hamming"
|
||||||
|
)
|
||||||
|
|
||||||
|
type imageCluster struct {
|
||||||
|
images []similarImage
|
||||||
|
}
|
||||||
|
|
||||||
|
type similarImage struct {
|
||||||
|
path string
|
||||||
|
distance int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fm *FilesMap) getImageClusters() []imageCluster {
|
||||||
|
var clusters []imageCluster
|
||||||
|
|
||||||
|
for len(fm.Images) > 0 {
|
||||||
|
file := fm.Images[0]
|
||||||
|
fm.Images = slices.Delete(fm.Images, 0, 1)
|
||||||
|
|
||||||
|
var currentCluster []similarImage
|
||||||
|
currentCluster = append(currentCluster, similarImage{path: file.path})
|
||||||
|
for otherIndex := len(fm.Images) - 1; otherIndex >= 0; otherIndex-- {
|
||||||
|
otherFile := fm.Images[otherIndex]
|
||||||
|
var distance = hamming.Uint64(file.imageHash, otherFile.imageHash)
|
||||||
|
if distance > 5 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.Images = slices.Delete(fm.Images, otherIndex, otherIndex+1)
|
||||||
|
currentCluster = append(currentCluster, similarImage{path: otherFile.path, distance: distance})
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(currentCluster) > 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
clusters = append(clusters, imageCluster{images: currentCluster})
|
||||||
|
}
|
||||||
|
|
||||||
|
return clusters
|
||||||
|
}
|
49
ui.go
Normal file
49
ui.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func promptForDeletion(reader *bufio.Reader, files []string) {
|
||||||
|
fmt.Print("\033[H\033[2J")
|
||||||
|
for i, file := range files {
|
||||||
|
fmt.Println(i+1, file)
|
||||||
|
}
|
||||||
|
fmt.Println(0, "Keep all")
|
||||||
|
|
||||||
|
fmt.Printf("Which file to keep? ")
|
||||||
|
input, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Invalid input")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
input = strings.TrimRight(input, "\n\r")
|
||||||
|
intInput, err := strconv.Atoi(input)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Invalid input")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if intInput == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if intInput > len(files) || intInput < 1 {
|
||||||
|
fmt.Println("Invalid input")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, file := range files {
|
||||||
|
if i+1 == intInput {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if *force {
|
||||||
|
remove(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user