From 4ca5bd6cebbe8f0cc24b16514b019a5d44e24905 Mon Sep 17 00:00:00 2001 From: duarch <@users.noreply.github.com> Date: Thu, 25 Nov 2021 16:34:02 -0300 Subject: [PATCH] Upload golang --- go.mod | 9 +++++++ go.sum | 27 +++++++++++++++++++ wall.go | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 wall.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e3e0b92 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module wall.go + +go 1.16 + +require ( + github.com/Navid2zp/dups v0.2.1 + github.com/cespare/xxhash v1.1.0 // indirect + github.com/cheggaaa/pb/v3 v3.0.8 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d0839af --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +github.com/Navid2zp/dups v0.2.1 h1:mcOfu3VEdYPMQ2JWHOHCSjJqgSlR31XTSK00lCXJ5SI= +github.com/Navid2zp/dups v0.2.1/go.mod h1:76JLahNf9qRVGA2iGoSi02lSrIGJg9FvHL681zOQQTc= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= +github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA= +github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA= +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= +github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/wall.go b/wall.go new file mode 100644 index 0000000..a53de0e --- /dev/null +++ b/wall.go @@ -0,0 +1,84 @@ +package main + +import ( + "fmt" + "github.com/Navid2zp/dups" + "image/jpeg" + "io" + "io/ioutil" + "os" + "path/filepath" + "strconv" + "time" +) + +func main() { + var dir = os.Getenv("USERPROFILE") + "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets" + var dirWallpapers = os.Getenv("USERPROFILE") + "\\Pictures\\WallSpot" + if _, err := os.Stat(dir); os.IsNotExist(err) { + fmt.Println("Diretório não existe") + os.Exit(1) + } + if _, err := os.Stat(dirWallpapers); os.IsNotExist(err) { + os.Mkdir(dirWallpapers, 0777) + } + files, err := ioutil.ReadDir(dir) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + i := 1 + for _, file := range files { + if file.IsDir() { + continue + } + item := filepath.Join(dir, file.Name()) + src := dir + "\\" + file.Name() + f, _ := os.Open(item) + img, _ := jpeg.Decode(f) + if img != nil { + if img.Bounds().Dx() == 1920 && img.Bounds().Dy() == 1080 { + newName := "w" + time.Now().Format("020106") + "_" + strconv.Itoa(i) + ".jpg" + dst := dirWallpapers + "\\" + newName + copyFile(src, dst) + i++ + } + } + } + clean(dirWallpapers) +} + +func copyFile(src, dst string) error { + in, err := os.Open(src) + if err != nil { + return err + } + defer in.Close() + + out, err := os.Create(dst) + if err != nil { + return err + } + defer out.Close() + + _, err = io.Copy(out, in) + if err != nil { + return err + } + return out.Close() +} + +//Based on README example from "github.com/Navid2zp/dups" +func clean(dir string) { + files, err := dups.GetFiles(dir, true) + if err != nil { + panic(err) + } + minSize := 1 + hashes := dups.CollectHashes(files, false, minSize, dups.XXHash, true) + duplicates, _, _ := dups.GetDuplicates(hashes) + _, _, error := dups.RemoveDuplicates(duplicates) + if error != nil { + panic(error) + } +}