yoink-go initial commit

This commit is contained in:
Bryan Bailey
2024-08-26 22:49:26 -04:00
commit e8bd6e4179
11 changed files with 708 additions and 0 deletions

31
comic/cleanup.go Normal file
View File

@@ -0,0 +1,31 @@
package comic
import (
"os"
"path/filepath"
"strings"
)
func (c *Comic) Cleanup() error {
filepath.Walk(
filepath.Join(c.LibraryPath, c.Title),
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
for _, ext := range []string{".jpg", ".jpeg", ".png"} {
edited := strings.Replace(info.Name(), c.Title, "", 1)
edited = strings.Trim(edited, " ")
if !strings.HasPrefix(strings.ToLower(edited), "001") && strings.HasSuffix(info.Name(), ext) {
return os.Remove(path)
}
}
return nil
})
return nil
}