This commit is contained in:
Joren 2025-04-02 21:04:03 +02:00
parent 103ec07f92
commit 9b9920b5ed
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55

35
main.go
View File

@ -4,10 +4,10 @@ import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
"io"
"path/filepath"
"regexp"
"strconv"
@ -16,10 +16,10 @@ import (
)
type FileQuality struct {
Path string
Bitrate int
Bitdepth int
Size int64
Path string
Bitrate int
Bitdepth int
Size int64
}
var (
@ -149,6 +149,19 @@ func findDuplicateFiles(rootDir string) (map[string][]FileQuality, error) {
return fileGroups, nil
}
func bytesToHumanReadable(bytes int64) string {
const unit = 1024
if bytes < unit {
return fmt.Sprintf("%d B", bytes)
}
div, exp := int64(unit), 0
for n := bytes / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp])
}
func processFileGroup(baseFile string, files []FileQuality) {
writeLog(fmt.Sprintf("Processing group for: %s", baseFile))
@ -212,11 +225,11 @@ func processFileGroup(baseFile string, files []FileQuality) {
continue
}
}
writeLog(fmt.Sprintf(" * %s: %s (Recovering %d bytes)", action, file.Path, file.Size))
writeLog(fmt.Sprintf(" * %s: %s (Recovering %s)", action, file.Path, bytesToHumanReadable(file.Size)))
}
}
writeLog(fmt.Sprintf(" Total recoverable space: %d bytes", totalSize-bestFile.Size))
writeLog(fmt.Sprintf(" Total recoverable space: %s", bytesToHumanReadable(totalSize-bestFile.Size)))
}
func main() {
@ -271,11 +284,19 @@ func main() {
writeLog("")
}
var totalRecoverableSpace int64
for baseFile, group := range fileGroups {
processFileGroup(baseFile, group)
for _, file := range group {
if file.Path != baseFile {
totalRecoverableSpace += file.Size
}
}
writeLog("")
}
writeLog(fmt.Sprintf("Total recoverable space: %s", bytesToHumanReadable(totalRecoverableSpace)))
writeLog(fmt.Sprintf("Cleanup completed at %s", getCurrentTime()))
writeLog("===============================")
}