arrange/cmd/am/main.go

68 lines
1.1 KiB
Go
Raw Normal View History

2016-05-17 23:03:37 -07:00
package main
import (
2016-05-18 00:19:39 -07:00
"flag"
2016-05-17 23:03:37 -07:00
"fmt"
"log"
"os"
2016-05-18 00:19:39 -07:00
"runtime"
2016-05-17 23:03:37 -07:00
"mcquay.me/arrange"
)
const usage = "aj <indir> <outdir>"
type stats struct {
total int
dupes int
moved int
}
2016-05-18 00:19:39 -07:00
var cores = flag.Int("cores", 0, "how many threads to use")
2016-05-17 23:03:37 -07:00
func main() {
2016-05-18 00:19:39 -07:00
flag.Parse()
2016-05-17 23:03:37 -07:00
log.SetFlags(log.Lshortfile)
2016-05-18 00:19:39 -07:00
if len(flag.Args()) != 2 {
2016-05-17 23:03:37 -07:00
fmt.Fprintf(os.Stderr, "%s\n", usage)
os.Exit(1)
}
2016-05-18 00:19:39 -07:00
in, out := flag.Args()[0], flag.Args()[1]
2016-05-17 23:03:37 -07:00
if err := arrange.PrepOutput(out); err != nil {
fmt.Fprintf(os.Stderr, "problem creating directory structure: %v", err)
os.Exit(1)
}
2016-05-18 00:19:39 -07:00
work := arrange.Source(in)
streams := []<-chan arrange.Media{}
2016-05-17 23:03:37 -07:00
2016-05-18 00:19:39 -07:00
workers := runtime.NumCPU()
if *cores != 0 {
workers = *cores
2016-05-17 23:03:37 -07:00
}
2016-05-18 00:19:39 -07:00
for w := 0; w < workers; w++ {
2016-05-17 23:03:37 -07:00
streams = append(streams, arrange.Parse(work))
}
st := stats{}
for err := range arrange.Move(arrange.Merge(streams), out) {
st.total++
if err != nil {
switch err.(type) {
case arrange.Dup:
st.dupes++
default:
log.Printf("%+v", err)
}
} else {
st.moved++
}
}
log.Printf("dupes: %+v", st.dupes)
log.Printf("moved: %+v", st.moved)
log.Printf("total: %+v", st.total)
}