blob: 6007cdc6791201c648623e28584be275a976d085 (
plain)
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
|
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())
}
}
|