Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Stephen McQuay | ab9d45e3ea |
|
@ -92,7 +92,7 @@ func Parse(in <-chan string) <-chan Media {
|
|||
out := make(chan Media)
|
||||
go func() {
|
||||
for path := range in {
|
||||
f, err := ParseFile(path)
|
||||
f, err := _parse(path)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case NotMedia:
|
||||
|
@ -149,8 +149,7 @@ func Move(in <-chan Media, root string) <-chan error {
|
|||
return out
|
||||
}
|
||||
|
||||
// ParseFile extracts metadata from single file.
|
||||
func ParseFile(path string) (Media, error) {
|
||||
func _parse(path string) (Media, error) {
|
||||
ext := strings.ToLower(filepath.Ext(path))
|
||||
var r Media
|
||||
hash := md5.New()
|
||||
|
|
|
@ -7,10 +7,9 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
const usage = "am <arr|clean|meta> [flags]"
|
||||
const usage = "am <arr|clean|help> [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
|
||||
|
@ -54,13 +53,6 @@ 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)
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
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)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"mcquay.me/mov"
|
||||
)
|
||||
|
||||
const usage = "usage: mov <.mov file>"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", usage)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, path := range os.Args[1:] {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
f.Close()
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
continue
|
||||
}
|
||||
s, _ := f.Stat()
|
||||
c, cerr := mov.Created(f)
|
||||
f.Seek(0, 0)
|
||||
m, merr := mov.Created(f)
|
||||
f.Close()
|
||||
if cerr != nil || merr != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to find time: %v, %v\n", cerr, merr)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("%s: from stat: %+v\n", path, s.ModTime())
|
||||
fmt.Printf("%s: created on: %+v\n", path, c)
|
||||
fmt.Printf("%s: modified on: %+v\n\n", path, m)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue