Files
arrange/cmd/am/arrange.go
T
smandClaude Opus 5.5 f63b855179 choose what to arrange: -kinds, -exclude, am survey
-kinds picks any of image, raw, video (default all). -exclude skips
files and whole directories by name glob, and can be repeated. am
survey stats media per directory (counts by kind, videos over 1G,
sizes) so things like ripped DVDs stand out before arranging. It
never opens files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 15:57:23 -07:00

70 lines
1.3 KiB
Go

package main
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"mcquay.me/arrange"
)
func arr(indir, outdir string, f arrange.Filter) error {
if !*dryRun {
if err := arrange.PrepOutput(outdir); err != nil {
return fmt.Errorf("problem creating directory structure: %v", err)
}
}
work := arrange.SourceFiltered(indir, f)
streams := []<-chan arrange.Media{}
workers := runtime.NumCPU()
if *cores != 0 {
workers = *cores
}
for w := 0; w < workers; w++ {
streams = append(streams, arrange.Parse(work))
}
st := newStats()
// in a dry run nothing lands in the store, so remember what would have
seen := map[string]bool{}
for m := range arrange.Merge(streams) {
if *dryRun {
content := m.Content(outdir)
_, err := os.Stat(content)
dup := seen[m.Hash] || err == nil
seen[m.Hash] = true
action := "new"
if dup {
action = "dup"
}
date := filepath.Join(outdir, "date", fmt.Sprintf("%04d", m.Time.Year()), fmt.Sprintf("%02d", m.Time.Month()))
fmt.Printf("%s\t%s\t%s\t%s\n", action, m.Path, content, date)
st.add(m, dup)
continue
}
err := m.Move(outdir)
switch err.(type) {
case nil:
st.add(m, false)
case arrange.Dup:
st.add(m, true)
default:
st.errors++
log.Printf("%+v", err)
}
}
verb := "moved"
if *dryRun {
verb = "would move"
}
st.write(os.Stderr, verb)
return nil
}