@@ -4,13 +4,64 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7+ "log/slog"
78 "os"
89
910 "github.com/google/uuid"
1011 widevine "github.com/iyear/gowidevine"
12+ wvpb "github.com/iyear/gowidevine/widevinepb"
13+ "google.golang.org/protobuf/encoding/protojson"
14+ "google.golang.org/protobuf/proto"
1115)
1216
1317func decodeWidevine (b []byte ) error {
18+ slog .Debug ("trying to parse widevine protobuf" )
19+
20+ indent := ""
21+ if prettyPrint {
22+ indent = " "
23+ }
24+
25+ signedMsg := & wvpb.SignedMessage {}
26+ if err := proto .Unmarshal (tryBase64 (b ), signedMsg ); err != nil {
27+ slog .Debug ("failed to unmarshal signed widevinelicense message" , "err" , err .Error ())
28+ } else {
29+ out , err := protojson.MarshalOptions {
30+ EmitUnpopulated : false ,
31+ UseEnumNumbers : false ,
32+ Indent : indent ,
33+ }.Marshal (signedMsg )
34+ if err != nil {
35+ slog .Debug ("failed to marshal signed widevine license message as json" , "err" , err .Error ())
36+ } else {
37+ fmt .Fprintln (os .Stderr , "Widevine License Response:" )
38+ fmt .Fprintln (os .Stderr , "----------------" )
39+ fmt .Fprintln (os .Stdout , string (out ))
40+ fmt .Println ()
41+
42+ licenseMsg := & wvpb.License {}
43+ if err = proto .Unmarshal (signedMsg .Msg , licenseMsg ); err != nil {
44+ return fmt .Errorf ("failed to unmarshal license message: %w" , err )
45+ } else {
46+ out , err := protojson.MarshalOptions {
47+ EmitUnpopulated : false ,
48+ UseEnumNumbers : false ,
49+ Indent : indent ,
50+ }.Marshal (licenseMsg )
51+ if err != nil {
52+ slog .Debug ("failed to marshal license message as json" , "err" , err .Error ())
53+ } else {
54+ fmt .Fprintln (os .Stderr , "Widevine License Message:" )
55+ fmt .Fprintln (os .Stderr , "----------------" )
56+ fmt .Fprintln (os .Stdout , string (out ))
57+
58+ return nil
59+ }
60+ }
61+ }
62+ }
63+
64+ slog .Debug ("trying to parse widevine protobuf" )
1465 o , err := widevine .NewPSSH (b )
1566 if err != nil {
1667 return fmt .Errorf ("failed to parse widevine pssh: %w" , err )
0 commit comments