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)
|
out := make(chan Media)
|
||||||
go func() {
|
go func() {
|
||||||
for path := range in {
|
for path := range in {
|
||||||
f, err := ParseFile(path)
|
f, err := _parse(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case NotMedia:
|
case NotMedia:
|
||||||
|
@ -149,8 +149,7 @@ func Move(in <-chan Media, root string) <-chan error {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseFile extracts metadata from single file.
|
func _parse(path string) (Media, error) {
|
||||||
func ParseFile(path string) (Media, error) {
|
|
||||||
ext := strings.ToLower(filepath.Ext(path))
|
ext := strings.ToLower(filepath.Ext(path))
|
||||||
var r Media
|
var r Media
|
||||||
hash := md5.New()
|
hash := md5.New()
|
||||||
|
|
|
@ -7,10 +7,9 @@ import (
|
||||||
"os"
|
"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 arrUsage = "am arr [-h|-cores=N] <in> <out>"
|
||||||
const cleanUsage = "am clean [-h|-cores=N] <directory>"
|
const cleanUsage = "am clean [-h|-cores=N] <directory>"
|
||||||
const metaUsage = "am meta [-h|-cores=N] <file0> <file1> ... <fileN>"
|
|
||||||
|
|
||||||
type stats struct {
|
type stats struct {
|
||||||
total int
|
total int
|
||||||
|
@ -54,13 +53,6 @@ func main() {
|
||||||
fmt.Fprintf(os.Stderr, "problem cleaning: %v\n", err)
|
fmt.Fprintf(os.Stderr, "problem cleaning: %v\n", err)
|
||||||
os.Exit(1)
|
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:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
fmt.Fprintf(os.Stderr, "%s\n", usage)
|
||||||
os.Exit(1)
|
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