1
0
mirror of https://github.com/chris124567/hulu synced 2024-11-27 18:47:30 +00:00

Compare commits

..

No commits in common. "c3bbd3beb25cab6fe629a112475904d5e91c05bb" and "2e7e935230af27c6ba53182c30074eeab6298633" have entirely different histories.

7 changed files with 59 additions and 68 deletions

View File

@ -9,13 +9,12 @@ import (
"encoding/json"
"fmt"
"io"
"lukechampine.com/frand"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"lukechampine.com/frand"
)
const (
@ -31,15 +30,24 @@ 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, huluGUID string) Client {
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
}()
return Client{c, huluSession, huluGUID}
}
// Returns a Client object using a default HTTP client with a timeout of 10s.
func NewDefaultClient(huluSession, huluGUID string) Client {
func NewDefaultClient(huluSession string) Client {
return NewClient(&http.Client{
Timeout: 10 * time.Second,
}, huluSession, huluGUID)
}, huluSession)
}
// Makes an HTTP request to a Hulu API endpoint. The only cookie Hulu validates is

1
go.mod
View File

@ -4,7 +4,6 @@ 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,8 +5,6 @@ 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=

28
main.go
View File

@ -2,21 +2,16 @@ package main
import (
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"net/http"
"os"
"strings"
"text/tabwriter"
"time"
"github.com/google/uuid"
hulu "github.com/chris124567/hulu/client"
"github.com/chris124567/hulu/widevine"
"io"
"lukechampine.com/flagg"
"net/http"
"os"
"text/tabwriter"
"time"
)
func main() {
@ -50,24 +45,13 @@ 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, huluGUID)
client := hulu.NewDefaultClient(huluSession)
w := tabwriter.NewWriter(os.Stdout, 8, 8, 0, '\t', 0)
defer w.Flush()

View File

@ -10,12 +10,11 @@ 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 {
@ -37,10 +36,10 @@ type Key struct {
// Creates a new CDM object with the specified device information.
func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
block, _ := pem.Decode([]byte(privateKey))
if block == nil || block.Type != "PRIVATE KEY" {
if block == nil || block.Type != "RSA PRIVATE KEY" {
return CDM{}, errors.New("failed to decode device private key")
}
keyParsed, err := x509.ParsePKCS8PrivateKey(block.Bytes)
keyParsed, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return CDM{}, err
}
@ -67,7 +66,7 @@ func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
}()
return CDM{
privateKey: keyParsed.(*rsa.PrivateKey),
privateKey: keyParsed,
clientID: clientID,
widevineCencHeader: widevineCencHeader,

File diff suppressed because one or more lines are too long

View File

@ -7,11 +7,10 @@
package widevine
import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (