mirror of
https://github.com/chris124567/hulu
synced 2024-11-24 00:57:29 +00:00
Compare commits
2 Commits
2e7e935230
...
c3bbd3beb2
Author | SHA1 | Date | |
---|---|---|---|
|
c3bbd3beb2 | ||
|
11966a356b |
@ -9,12 +9,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"lukechampine.com/frand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"lukechampine.com/frand"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -30,24 +31,15 @@ type Client struct {
|
|||||||
|
|
||||||
// Returns a Client object that will use the provided Hulu session cookie to
|
// Returns a Client object that will use the provided Hulu session cookie to
|
||||||
// interact with the Hulu API.
|
// interact with the Hulu API.
|
||||||
func NewClient(c *http.Client, huluSession string) Client {
|
func NewClient(c *http.Client, huluSession, huluGUID 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}
|
return Client{c, huluSession, huluGUID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a Client object using a default HTTP client with a timeout of 10s.
|
// 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{
|
return NewClient(&http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}, huluSession)
|
}, huluSession, huluGUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes an HTTP request to a Hulu API endpoint. The only cookie Hulu validates is
|
// Makes an HTTP request to a Hulu API endpoint. The only cookie Hulu validates is
|
||||||
|
1
go.mod
1
go.mod
@ -4,6 +4,7 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1
|
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
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
|
||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
lukechampine.com/flagg v1.1.1
|
lukechampine.com/flagg v1.1.1
|
||||||
|
2
go.sum
2
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/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 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
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-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 h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
24
main.go
24
main.go
@ -2,16 +2,21 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
hulu "github.com/chris124567/hulu/client"
|
|
||||||
"github.com/chris124567/hulu/widevine"
|
|
||||||
"io"
|
"io"
|
||||||
"lukechampine.com/flagg"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
hulu "github.com/chris124567/hulu/client"
|
||||||
|
"github.com/chris124567/hulu/widevine"
|
||||||
|
"lukechampine.com/flagg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
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")
|
huluSession := os.Getenv("HULU_SESSION")
|
||||||
if huluSession == "" {
|
if huluSession == "" {
|
||||||
rootCmd.Usage()
|
rootCmd.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client := hulu.NewDefaultClient(huluSession)
|
client := hulu.NewDefaultClient(huluSession, huluGUID)
|
||||||
w := tabwriter.NewWriter(os.Stdout, 8, 8, 0, '\t', 0)
|
w := tabwriter.NewWriter(os.Stdout, 8, 8, 0, '\t', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
|
@ -10,11 +10,12 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aead/cmac"
|
"github.com/aead/cmac"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"lukechampine.com/frand"
|
"lukechampine.com/frand"
|
||||||
"math"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CDM struct {
|
type CDM struct {
|
||||||
@ -36,10 +37,10 @@ type Key struct {
|
|||||||
// Creates a new CDM object with the specified device information.
|
// Creates a new CDM object with the specified device information.
|
||||||
func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
|
func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
|
||||||
block, _ := pem.Decode([]byte(privateKey))
|
block, _ := pem.Decode([]byte(privateKey))
|
||||||
if block == nil || block.Type != "RSA PRIVATE KEY" {
|
if block == nil || block.Type != "PRIVATE KEY" {
|
||||||
return CDM{}, errors.New("failed to decode device private key")
|
return CDM{}, errors.New("failed to decode device private key")
|
||||||
}
|
}
|
||||||
keyParsed, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
keyParsed, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CDM{}, err
|
return CDM{}, err
|
||||||
}
|
}
|
||||||
@ -66,7 +67,7 @@ func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
return CDM{
|
return CDM{
|
||||||
privateKey: keyParsed,
|
privateKey: keyParsed.(*rsa.PrivateKey),
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
|
|
||||||
widevineCencHeader: widevineCencHeader,
|
widevineCencHeader: widevineCencHeader,
|
||||||
|
File diff suppressed because one or more lines are too long
@ -7,10 +7,11 @@
|
|||||||
package widevine
|
package widevine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
|
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user