-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (54 loc) · 1.37 KB
/
main.go
File metadata and controls
67 lines (54 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// A command-line tool to extract image generation parameters
// from an image file or sidecar file.
package main
import (
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
_ "github.com/fkleon/fooocus-metadata/fooocus"
_ "github.com/fkleon/fooocus-metadata/fooocusplus"
_ "github.com/fkleon/fooocus-metadata/ruinedfooocus"
_ "github.com/fkleon/fooocus-metadata/stablediffusion"
fooocusmeta "github.com/fkleon/fooocus-metadata"
)
func main() {
var debug, verbose bool
flag.BoolVar(&verbose, "verbose", false, "enable verbose logging")
flag.BoolVar(&debug, "debug", false, "enable debug logging")
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "usage: [flags] <path>")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "path: The file to read metadata from (required)\n")
}
flag.Parse()
setLogLevel(debug, verbose)
path := flag.Arg(0)
if path == "" {
flag.Usage()
os.Exit(1)
}
extract(path)
}
func extract(path string) {
metadata, err := fooocusmeta.ExtractFromFile(path)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(2)
}
out, err := json.MarshalIndent(metadata.Params.Raw(), "", " ")
if err == nil {
fmt.Print(string(out))
}
}
func setLogLevel(debug bool, verbose bool) {
switch {
case debug:
slog.SetLogLoggerLevel(slog.LevelDebug)
case verbose:
slog.SetLogLoggerLevel(slog.LevelInfo)
default:
slog.SetLogLoggerLevel(slog.LevelWarn)
}
}