lifecam/lifecam.go

73 lines
1.4 KiB
Go
Raw Normal View History

2022-02-23 05:14:47 +00:00
package main
import (
"flag"
"log"
"os"
"path/filepath"
"git.sr.ht/~kisom/goutils/config"
"git.sr.ht/~kisom/goutils/die"
"git.wntrmute.dev/kyle/lifecam/lifecam"
)
var defaultConfigFile = config.DefaultConfigPath("lifecam", "lifecam.conf")
func main() {
var err error
var minio *lifecam.Server
clean := flag.Bool("c", false, "remove files after zipping")
cfgFile := flag.String("f", defaultConfigFile, "path to config file")
upload := flag.Bool("u", false, "upload zipfile to S3")
flag.Parse()
if *cfgFile != "" {
err := config.LoadFile(*cfgFile)
if err != nil {
if !os.IsNotExist(err) {
die.If(err)
}
} else {
log.Println("read config file", *cfgFile)
}
}
if *upload {
minio, err = lifecam.NewMinio()
die.If(err)
}
paths := flag.Args()
if len(paths) == 0 {
if defaultPath := config.Get("DEFAULT_IMAGE_DIR"); defaultPath != "" {
paths = append(paths, defaultPath)
} else {
log.Println("nothing to do")
}
}
var frameMap map[int]lifecam.FrameList
for _, path := range paths {
log.Println("loading all frames in", path)
path = filepath.Clean(path)
frameMap, err = lifecam.LoadDir(path, frameMap)
die.If(err)
}
for _, fl := range frameMap {
pkg, err := fl.Package()
die.If(err)
2022-02-23 07:53:55 +00:00
path, err := lifecam.PackageZip(pkg, *clean)
2022-02-23 05:14:47 +00:00
die.If(err)
if *upload {
n, err := minio.Upload(path, lifecam.MimeZip)
die.If(err)
log.Printf("uploaded %s [%d bytes]", path, n)
}
}
log.Println("complete")
}