Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Stephen McQuay | 0359f8c288 | |
Stephen McQuay | 13cd30b46c |
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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