73 lines
1.3 KiB
Go
Raw Normal View History

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