From e8c1fc39eccf977c702b1932252075cdc3eeed95 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 30 Jul 2023 19:42:41 +0800 Subject: Add Danmaku decode CLI tool --- cli/main.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cli/main.go (limited to 'cli') diff --git a/cli/main.go b/cli/main.go new file mode 100644 index 0000000..6007cdc --- /dev/null +++ b/cli/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "bufio" + "encoding/base64" + "encoding/hex" + "fmt" + "github.com/keuin/slbr/danmaku/dmpkg" + "log" + "os" +) + +func main() { + r := bufio.NewReader(os.Stdin) + for { + line, _, err := r.ReadLine() + if err != nil { + panic(err) + } + var data []byte + err = func() error { + data, err = hex.DecodeString(string(line)) + if err == nil { + return nil + } + data, err = base64.StdEncoding.DecodeString(string(line)) + if err != nil { + log.Println("Failed to decode as Hex or Base64 string") + } + return err + }() + if err != nil { + continue + } + ex, err := dmpkg.DecodeExchange(data) + if err != nil { + log.Println("Failed to decode Danmaku exchange: ", err) + continue + } + ex, err = ex.Inflate() + if err != nil { + log.Println("Failed to decompress Danmaku exchange: ", err) + continue + } + fmt.Println(ex.PrettyString()) + } +} -- cgit v1.2.3