allow specifying GUID and if no GUID is provided it remains relatively stable across runs

This commit is contained in:
Christopher Tarry 2021-12-21 12:31:54 -05:00
parent 2e7e935230
commit 11966a356b
6 changed files with 34 additions and 21 deletions

View File

@ -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

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

24
main.go
View File

@ -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()

View File

@ -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 {

View File

@ -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 (