diff --git a/.fuse_hidden000024c600000004 b/.fuse_hidden000024c600000004 deleted file mode 100755 index e0116b2..0000000 Binary files a/.fuse_hidden000024c600000004 and /dev/null differ diff --git a/organizer b/.fuse_hidden000024c900000005 similarity index 100% rename from organizer rename to .fuse_hidden000024c900000005 diff --git a/go.mod b/go.mod index 42aea90..f95c905 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( git.milar.in/nyaanime/logic v0.0.0-20230113102709-a719289ef360 git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3 git.milar.in/nyaanime/parsers v0.0.0-20230113101942-2c9bc6925201 + github.com/fatih/color v1.13.0 github.com/fsnotify/fsnotify v1.5.4 ) @@ -16,6 +17,8 @@ require ( git.milar.in/milarin/channel v0.0.14 // indirect git.milar.in/milarin/gmath v0.0.3 // indirect git.milar.in/milarin/slices v0.0.6 // indirect + github.com/mattn/go-colorable v0.1.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect gopkg.in/vansante/go-ffprobe.v2 v2.1.1 // indirect ) diff --git a/go.sum b/go.sum index cbd2ae6..91b7246 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,18 @@ git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3 h1:mXcEA47FQQzeSD git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg= git.milar.in/nyaanime/parsers v0.0.0-20230113101942-2c9bc6925201 h1:glTG4IeuIvD4mVwJyCF5SYMawCRcZZ01pz4AUyWTEP8= git.milar.in/nyaanime/parsers v0.0.0-20230113101942-2c9bc6925201/go.mod h1:GG4vtUIfxopZc/+Y8OAa//vWJw/m6aeoGN7fw6SLiEM= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +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-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/vansante/go-ffprobe.v2 v2.1.1 h1:DIh5fMn+tlBvG7pXyUZdemVmLdERnf2xX6XOFF+0BBU= diff --git a/handle_file.go b/handle_file.go index 45d430d..fc6e779 100644 --- a/handle_file.go +++ b/handle_file.go @@ -1,37 +1,37 @@ package main import ( - "errors" "fmt" - "io" "log" - "os" "path/filepath" - "git.milar.in/milarin/adverr" "git.milar.in/nyaanime/logic" "git.milar.in/nyaanime/model" "git.milar.in/nyaanime/parsers" + "github.com/fatih/color" ) -func HandleFile(path string) bool { +func HandleFile(path string) { + color.Magenta("\nfile found: %s\n", filepath.Base(path)) for _, parser := range parsers.Parsers { parsedFile, ok := parser.FileParser(&parser, path) if !ok { + color.Red("\tnot parsable with parser '%s'\n", parser.Identity) continue } + color.Green("\tparsable with parser '%s'\n", parser.Identity) + anime, err := logic.SearchAnimeByTitle(parsedFile.OriginalAnimeTitle) if err != nil { + color.Red("\tanime not found: '%s'\n", parsedFile.OriginalAnimeTitle) continue } parsedFile.Anime = anime HandleParsedFile(parsedFile) - return true + return } - - return false } func HandleParsedFile(parsedFile *model.ParsedFile) { @@ -39,62 +39,63 @@ func HandleParsedFile(parsedFile *model.ParsedFile) { oldFilePrio, animeEpNotExistLocally := logic.GetAnimeEpProps(parsedFile.AnimeEpisode()) if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority { - go func(parsedFile *model.ParsedFile) { - if err := OrganizeAnimeEpisode(parsedFile); err != nil { - adverr.Println(err) - } - }(parsedFile) + fmt.Println("\tmove file") + // go func(parsedFile *model.ParsedFile) { + // if err := OrganizeAnimeEpisode(parsedFile); err != nil { + // adverr.Println(err) + // } + // }(parsedFile) } } func OrganizeAnimeEpisode(parsedFile *model.ParsedFile) error { oldFile := filepath.Join(DownloadPath, parsedFile.File) newFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), filepath.Ext(parsedFile.File)) - lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock") + //lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock") log.Printf("move file '%s' to '%s'\n", oldFile, newFile) - if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil { - return err - } + // if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil { + // return err + // } - if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil { - return err - } + // if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil { + // return err + // } - if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) { - fmt.Fprintln(os.Stderr, "file already exists:", newFile) - return err - } + // if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) { + // fmt.Fprintln(os.Stderr, "file already exists:", newFile) + // return err + // } - inputFile, err := os.Open(oldFile) - if err != nil { - return err - } - defer inputFile.Close() + // inputFile, err := os.Open(oldFile) + // if err != nil { + // return err + // } + // defer inputFile.Close() - outputFile, err := os.Create(newFile) - if err != nil { - return err - } - defer outputFile.Close() + // outputFile, err := os.Create(newFile) + // if err != nil { + // return err + // } + // defer outputFile.Close() - if err := os.Chown(newFile, Uid, Gid); err != nil { - return err - } + // if err := os.Chown(newFile, Uid, Gid); err != nil { + // return err + // } - _, err = io.Copy(outputFile, inputFile) - if err != nil { - return err - } + // _, err = io.Copy(outputFile, inputFile) + // if err != nil { + // return err + // } - if err = os.Remove(oldFile); err != nil { - return err - } + // if err = os.Remove(oldFile); err != nil { + // return err + // } - if err = os.Remove(lockFile); err != nil { - return err - } + // if err = os.Remove(lockFile); err != nil { + // return err + // } log.Printf("file '%s' moved\n", newFile) diff --git a/main.go b/main.go index b55fc0d..2430264 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,6 @@ package main import ( - "log" - "git.milar.in/nyaanime/logic" "github.com/fsnotify/fsnotify" ) @@ -19,12 +17,6 @@ func main() { } for file := range fsChan { - fileHandled := HandleFile(file) - - if fileHandled { - log.Println("file handled:", file) - } else { - log.Println("file ignored:", file) - } + HandleFile(file) } }