1
0
mirror of https://github.com/FloatTech/zbpwife.git synced 2024-09-29 17:46:29 +09:00
zbpwife/main.go
2023-03-25 17:09:22 +08:00

60 lines
934 B
Go

package main
import (
"encoding/json"
"os"
"strings"
"github.com/fumiama/imgsz"
)
//go:generate go run main.go
const wifvesdir = "./wives/"
const jsonfile = "wife.json"
func main() {
ent, err := os.ReadDir(wifvesdir)
if err != nil {
panic(err)
}
cards := make([]string, 0, len(ent))
for _, en := range ent {
if en.IsDir() {
continue
}
name := en.Name()
fn := wifvesdir + name
f, err := os.Open(fn)
if err != nil {
continue
}
_, format, err := imgsz.DecodeSize(f)
_ = f.Close()
if err != nil {
continue
}
i := strings.LastIndex(name, ".")
if i <= 0 {
continue
}
name = name[:i] + "." + format
nfn := wifvesdir + name
if fn != nfn {
err = os.Rename(fn, nfn)
if err != nil {
continue
}
}
cards = append(cards, name)
}
f, err := os.Create(jsonfile)
if err != nil {
panic(err)
}
err = json.NewEncoder(f).Encode(cards)
if err != nil {
panic(err)
}
}