This commit is contained in:
sfigato 2021-08-02 19:03:33 +02:00
commit bcb6c0f388
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

102
main.go Normal file
View File

@ -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")
}