commit bcb6c0f3886d59c4f333560bd72857cdae0b54cc Author: Blallo Date: Mon Aug 2 19:03:33 2021 +0200 Init diff --git a/main.go b/main.go new file mode 100644 index 0000000..2f4645c --- /dev/null +++ b/main.go @@ -0,0 +1,102 @@ +package main + +import ( + "errors" + "fmt" + "io/fs" + "io/ioutil" + "log" + "os" + "path/filepath" + "regexp" + "strings" +) + +const ( + absBasePath = "/opt/synapse/download" + seriesPath = absBasePath + "/series" + filmPath = absBasePath + "/film" + musicPath = absBasePath + "/music" + programsPath = absBasePath + "/programs" +) +const ( + series = iota + film + music + program +) + +var maybeSeries, maybeFilm, maybeMusic, maybeProgram *regexp.Regexp +var errYetPresent = errors.New("element yet present") + +type classification map[string]int + +func (c classification) add(element string, kind int) error { + if _, ok := c[element]; ok { + return errYetPresent + } + c[element] = kind + return nil +} + +func (c classification) get(element string) (string, bool) { + kind, ok := c[element] + if !ok { + return "", false + } + switch kind { + case series: + return "series", true + case film: + return "film", true + case music: + return "music", true + case program: + return "program", true + default: + panic(fmt.Sprintf("kind value now allowed: %d\n", kind)) + } +} + +var cls classification + +func init() { + maybeSeries = regexp.MustCompile(`(?i)^.*(((s|S)(\d+)((e|E)(\d+))?)|((season)(\ )?(\d+)?)).*\.(mkv|mp4|avi)$`) + maybeFilm = regexp.MustCompile(`(?i)^.*\.(mkv|mp4|avi)$`) + maybeMusic = regexp.MustCompile(`(?i)^.*\.(mp3|ogg|flac)$`) + maybeProgram = regexp.MustCompile(`(?i)^.*\.(zip|tar|tar\.gz|exe|msi|rar)$`) + cls = make(classification) +} + +func isInSpecialDir(dir string) bool { + if strings.Contains(dir, seriesPath) { + return true + } + if strings.Contains(dir, filmPath) { + return true + } + if strings.Contains(dir, musicPath) { + return true + } + if strings.Contains(dir, programsPath) { + return true + } + + return false +} + +func find(name string, info fs.FileInfo, err error) error { + // skip directories + if info.IsDir() { + return nil + } + // skip special directories + if isInSpecialDir(name) { + return nil + } + return nil +} + +func main() { + fmt.Println("vim-go") +}