From 11966a356bf6a0d52a3f1a43c33985d89e9b0965 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Tue, 21 Dec 2021 12:31:54 -0500 Subject: [PATCH] allow specifying GUID and if no GUID is provided it remains relatively stable across runs --- client/client.go | 18 +++++------------- go.mod | 1 + go.sum | 2 ++ main.go | 24 ++++++++++++++++++++---- widevine/cdm.go | 5 +++-- widevine/wv_proto2.pb.go | 5 +++-- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/client/client.go b/client/client.go index dfd1c40..97e63de 100644 --- a/client/client.go +++ b/client/client.go @@ -9,12 +9,13 @@ import ( "encoding/json" "fmt" "io" - "lukechampine.com/frand" "net/http" "net/url" "strconv" "strings" "time" + + "lukechampine.com/frand" ) const ( @@ -30,24 +31,15 @@ type Client struct { // Returns a Client object that will use the provided Hulu session cookie to // interact with the Hulu API. -func NewClient(c *http.Client, huluSession string) Client { - // they look something like 5E95F69687FDD039CD0388A39FC01E5A - huluGUID := func() (s string) { - c := []byte("ABCDEF0123456789") - for i := 0; i < 32; i++ { - s += string(c[frand.Intn(len(c))]) - } - return - }() - +func NewClient(c *http.Client, huluSession, huluGUID string) Client { return Client{c, huluSession, huluGUID} } // Returns a Client object using a default HTTP client with a timeout of 10s. -func NewDefaultClient(huluSession string) Client { +func NewDefaultClient(huluSession, huluGUID string) Client { return NewClient(&http.Client{ Timeout: 10 * time.Second, - }, huluSession) + }, huluSession, huluGUID) } // Makes an HTTP request to a Hulu API endpoint. The only cookie Hulu validates is diff --git a/go.mod b/go.mod index 83c537a..087cb61 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 + github.com/google/uuid v1.3.0 golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect google.golang.org/protobuf v1.27.1 lukechampine.com/flagg v1.1.1 diff --git a/go.sum b/go.sum index f866122..e2df567 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1/go.mod h1:nuudZmJhzWtx22 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go index 45af6ea..2cfedc0 100644 --- a/main.go +++ b/main.go @@ -2,16 +2,21 @@ package main import ( "bytes" + "crypto/md5" "encoding/hex" "fmt" - hulu "github.com/chris124567/hulu/client" - "github.com/chris124567/hulu/widevine" "io" - "lukechampine.com/flagg" "net/http" "os" + "strings" "text/tabwriter" "time" + + "github.com/google/uuid" + + hulu "github.com/chris124567/hulu/client" + "github.com/chris124567/hulu/widevine" + "lukechampine.com/flagg" ) func main() { @@ -45,13 +50,24 @@ download [id] - prints the MPD url the video is available at and returns the mp4 } cmd := flagg.Parse(tree) + huluGUID := os.Getenv("HULU_GUID") + // if GUID is not provided, use hash of hostname instead + if huluGUID == "" { + hostname, err := os.Hostname() + if err != nil { + panic(err) + } + uuid := uuid.UUID(md5.Sum([]byte(hostname))) + huluGUID = strings.ReplaceAll(strings.ToUpper(uuid.String()), "-", "") + } + huluSession := os.Getenv("HULU_SESSION") if huluSession == "" { rootCmd.Usage() return } - client := hulu.NewDefaultClient(huluSession) + client := hulu.NewDefaultClient(huluSession, huluGUID) w := tabwriter.NewWriter(os.Stdout, 8, 8, 0, '\t', 0) defer w.Flush() diff --git a/widevine/cdm.go b/widevine/cdm.go index b084ef3..3b1d53b 100644 --- a/widevine/cdm.go +++ b/widevine/cdm.go @@ -10,11 +10,12 @@ import ( "crypto/x509" "encoding/pem" "errors" + "math" + "time" + "github.com/aead/cmac" "google.golang.org/protobuf/proto" "lukechampine.com/frand" - "math" - "time" ) type CDM struct { diff --git a/widevine/wv_proto2.pb.go b/widevine/wv_proto2.pb.go index ccaccfa..c37d876 100644 --- a/widevine/wv_proto2.pb.go +++ b/widevine/wv_proto2.pb.go @@ -7,10 +7,11 @@ package widevine import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const (