69 lines
1.2 KiB
Go
Raw Normal View History

2018-03-08 23:07:48 +00:00
package main
import (
2018-11-13 10:04:31 +00:00
"fmt"
2018-03-08 23:07:48 +00:00
"os"
2018-04-12 17:05:05 +00:00
"path"
2018-03-08 23:07:48 +00:00
"path/filepath"
"strings"
2018-03-09 03:32:31 +00:00
"github.com/animenotifier/arn"
2018-03-16 23:28:36 +00:00
"github.com/fatih/color"
2018-03-08 23:07:48 +00:00
)
func main() {
2018-04-12 11:39:58 +00:00
color.Yellow("Parsing MAL files")
2018-03-16 23:28:36 +00:00
defer color.Green("Finished.")
2018-03-21 04:15:03 +00:00
defer arn.Node.Close()
2018-03-08 23:07:48 +00:00
2018-04-12 17:05:05 +00:00
// Invoke via parameters
if InvokeShellArgs() {
return
}
2018-03-08 23:07:48 +00:00
2018-10-31 09:13:18 +00:00
if objectType == "all" || objectType == "anime" {
2018-10-31 09:57:28 +00:00
readFiles(path.Join(arn.Root, "jobs", "mal-download", "anime"), readAnimeFile)
2018-10-31 09:13:18 +00:00
}
2018-10-31 09:57:28 +00:00
if objectType == "all" || objectType == "character" {
readFiles(path.Join(arn.Root, "jobs", "mal-download", "character"), readCharacterFile)
}
}
2018-10-31 23:23:41 +00:00
// Read files in a given directory and apply a function on them
2018-10-31 09:57:28 +00:00
func readFiles(root string, onFile func(string) error) {
count := 0
2018-10-31 09:57:28 +00:00
filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
if err != nil {
color.Red(err.Error())
2018-10-31 09:57:28 +00:00
return err
}
if info.IsDir() {
return nil
}
if !strings.HasSuffix(name, ".html.gz") {
return nil
}
count++
2018-11-13 10:04:31 +00:00
fmt.Printf("\r\033[2K[%d] %s ", count, name)
err = onFile(name)
if err != nil {
color.Red(err.Error())
}
// Always continue traversing the directory
return nil
2018-10-31 09:57:28 +00:00
})
2018-11-13 10:04:31 +00:00
// Erase line
print("\r\033[2K")
color.Cyan("%d files found", count)
2018-03-08 23:07:48 +00:00
}