added meta subcommand
this command parses and prints out the metadata. Also I've used an alternate spelling of "go wide" that I've been finding slightly more legible these days.
This commit is contained in:
parent
13cd30b46c
commit
0359f8c288
@ -7,9 +7,10 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const usage = "am <arr|clean|help> [flags]"
|
||||
const usage = "am <arr|clean|meta> [flags]"
|
||||
const arrUsage = "am arr [-h|-cores=N] <in> <out>"
|
||||
const cleanUsage = "am clean [-h|-cores=N] <directory>"
|
||||
const metaUsage = "am meta [-h|-cores=N] <file0> <file1> ... <fileN>"
|
||||
|
||||
type stats struct {
|
||||
total int
|
||||
@ -53,6 +54,13 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "problem cleaning: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "m", "meta":
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", metaUsage)
|
||||
os.Exit(1)
|
||||
}
|
||||
meta(args)
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
||||
os.Exit(1)
|
||||
|
42
cmd/am/meta.go
Normal file
42
cmd/am/meta.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"mcquay.me/arrange"
|
||||
)
|
||||
|
||||
func meta(files []string) {
|
||||
workers := runtime.NumCPU()
|
||||
if *cores != 0 {
|
||||
workers = *cores
|
||||
}
|
||||
fc := make(chan arrange.Media)
|
||||
|
||||
go func() {
|
||||
wg := &sync.WaitGroup{}
|
||||
s := make(chan bool, workers)
|
||||
for _, f := range files {
|
||||
wg.Add(1)
|
||||
go func(pth string) {
|
||||
s <- true
|
||||
pf, err := arrange.ParseFile(pth)
|
||||
if err != nil {
|
||||
log.Printf("%+v", err)
|
||||
}
|
||||
|
||||
fc <- pf
|
||||
<-s
|
||||
wg.Done()
|
||||
}(f)
|
||||
}
|
||||
wg.Wait()
|
||||
close(fc)
|
||||
}()
|
||||
for f := range fc {
|
||||
fmt.Printf("%+v: %v\n", f.Time, f.Path)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user