Compare commits

...

2 Commits
mov ... master

Author SHA1 Message Date
Stephen McQuay 0359f8c288
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.
2017-07-23 14:07:12 -07:00
Stephen McQuay 13cd30b46c
expose the ParseFile function. 2017-07-23 14:06:28 -07:00
3 changed files with 54 additions and 3 deletions

View File

@ -92,7 +92,7 @@ func Parse(in <-chan string) <-chan Media {
out := make(chan Media)
go func() {
for path := range in {
f, err := _parse(path)
f, err := ParseFile(path)
if err != nil {
switch err.(type) {
case NotMedia:
@ -149,7 +149,8 @@ func Move(in <-chan Media, root string) <-chan error {
return out
}
func _parse(path string) (Media, error) {
// ParseFile extracts metadata from single file.
func ParseFile(path string) (Media, error) {
ext := strings.ToLower(filepath.Ext(path))
var r Media
hash := md5.New()

View File

@ -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
View 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)
}
}