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.
c3bbd3beb2
...
2e7e935230
@ -9,13 +9,12 @@ 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 (
|
||||||
@ -31,15 +30,24 @@ 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, 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}
|
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, huluGUID string) Client {
|
func NewDefaultClient(huluSession string) Client {
|
||||||
return NewClient(&http.Client{
|
return NewClient(&http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}, huluSession, huluGUID)
|
}, huluSession)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,7 +4,6 @@ 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,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/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=
|
||||||
|
28
main.go
28
main.go
@ -2,21 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"text/tabwriter"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
|
|
||||||
hulu "github.com/chris124567/hulu/client"
|
hulu "github.com/chris124567/hulu/client"
|
||||||
"github.com/chris124567/hulu/widevine"
|
"github.com/chris124567/hulu/widevine"
|
||||||
|
"io"
|
||||||
"lukechampine.com/flagg"
|
"lukechampine.com/flagg"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"text/tabwriter"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
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, huluGUID)
|
client := hulu.NewDefaultClient(huluSession)
|
||||||
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,12 +10,11 @@ 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 {
|
||||||
@ -37,10 +36,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 != "PRIVATE KEY" {
|
if block == nil || block.Type != "RSA 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.ParsePKCS8PrivateKey(block.Bytes)
|
keyParsed, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CDM{}, err
|
return CDM{}, err
|
||||||
}
|
}
|
||||||
@ -67,7 +66,7 @@ func NewCDM(privateKey string, clientID []byte, initData []byte) (CDM, error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
return CDM{
|
return CDM{
|
||||||
privateKey: keyParsed.(*rsa.PrivateKey),
|
privateKey: keyParsed,
|
||||||
clientID: clientID,
|
clientID: clientID,
|
||||||
|
|
||||||
widevineCencHeader: widevineCencHeader,
|
widevineCencHeader: widevineCencHeader,
|
||||||
|
File diff suppressed because one or more lines are too long
@ -7,11 +7,10 @@
|
|||||||
package widevine
|
package widevine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user