diff options
author | Keuin <[email protected]> | 2023-07-30 19:42:41 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-30 19:42:41 +0800 |
commit | e8c1fc39eccf977c702b1932252075cdc3eeed95 (patch) | |
tree | 0da932e7f144544c7e6c5b834da4a52e46d80d93 /cli | |
parent | 3fad4189646cca5d6db99ccfe79be695ef765d03 (diff) |
Diffstat (limited to 'cli')
-rw-r--r-- | cli/main.go | 47 |
1 files changed, 47 insertions, 0 deletions
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()) + } +} |