Skip to content

Commit

Permalink
Merge pull request #19 from cabbagekobe/feature/FlashAbolitionSupport
Browse files Browse the repository at this point in the history
Flash player removal support
  • Loading branch information
yyoshiki41 authored Dec 5, 2020
2 parents 62b3561 + bab1c8f commit 602ce31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
45 changes: 15 additions & 30 deletions auth.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,44 @@
package radiko

import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
)

// AuthorizeToken returns an enables auth_token and error,
// and sets auth_token in Client.
// Is is a alias function that wraps Auth1Fms and Auth2Fms.
// Is is a alias function that wraps Auth1 and Auth2.
func (c *Client) AuthorizeToken(ctx context.Context) (string, error) {
bin, err := downloadBinary()
authToken, length, offset, err := c.Auth1(ctx)
if err != nil {
return "", err
}

f := bytes.NewReader(bin)
b := radikoAuthkeyValue[offset : offset+length]
partialKey := base64.StdEncoding.EncodeToString([]byte(b))

authToken, length, offset, err := c.Auth1Fms(ctx)
slc, err := c.Auth2(ctx, authToken, partialKey)
if err != nil {
return "", err
}

b := make([]byte, length)
io.CopyN(ioutil.Discard, f, offset)
if _, err = f.Read(b); err != nil {
return "", err
}
partialKey := base64.StdEncoding.EncodeToString(b)

slc, err := c.Auth2Fms(ctx, authToken, partialKey)
if err != nil {
return "", err
}
if err := verifyAuth2FmsResponse(slc); err != nil {
if err := verifyAuth2Response(slc); err != nil {
return "", err
}

c.setAuthTokenHeader(authToken)
return authToken, nil
}

// Auth1Fms returns authToken, keyLength, keyOffset and error.
func (c *Client) Auth1Fms(ctx context.Context) (string, int64, int64, error) {
apiEndpoint := apiPath(apiV2, "auth1_fms")
// Auth1 returns authToken, keyLength, keyOffset and error.
func (c *Client) Auth1(ctx context.Context) (string, int64, int64, error) {
apiEndpoint := apiPath(apiV2, "auth1")

req, err := c.newRequest(ctx, "POST", apiEndpoint, &Params{
req, err := c.newRequest(ctx, "GET", apiEndpoint, &Params{
header: map[string]string{
radikoAppHeader: radikoApp,
radikoAppVersionHeader: radikoAppVersion,
Expand Down Expand Up @@ -85,14 +72,12 @@ func (c *Client) Auth1Fms(ctx context.Context) (string, int64, int64, error) {
return authToken, length, offset, err
}

// Auth2Fms enables the given authToken.
func (c *Client) Auth2Fms(ctx context.Context, authToken, partialKey string) ([]string, error) {
apiEndpoint := apiPath(apiV2, "auth2_fms")
// Auth2 enables the given authToken.
func (c *Client) Auth2(ctx context.Context, authToken, partialKey string) ([]string, error) {
apiEndpoint := apiPath(apiV2, "auth2")

req, err := c.newRequest(ctx, "POST", apiEndpoint, &Params{
req, err := c.newRequest(ctx, "GET", apiEndpoint, &Params{
header: map[string]string{
radikoAppHeader: radikoApp,
radikoAppVersionHeader: radikoAppVersion,
radikoUserHeader: radikoUser,
radikoDeviceHeader: radikoDevice,
radikoAuthTokenHeader: authToken,
Expand All @@ -118,7 +103,7 @@ func (c *Client) Auth2Fms(ctx context.Context, authToken, partialKey string) ([]
return s, nil
}

func verifyAuth2FmsResponse(slc []string) error {
func verifyAuth2Response(slc []string) error {
if len(slc) == 0 {
return errors.New("missing token")
}
Expand Down
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const (
radikoKeyOffsetHeader = "X-Radiko-KeyOffset"
radikoPartialKeyHeader = "X-Radiko-Partialkey"

radikoApp = "pc_ts"
radikoAppVersion = "4.0.0"
radikoAuthkeyValue = "bcd151073c03b352e1ef2fd66c32209da9ca0afa"

radikoApp = "pc_html5"
radikoAppVersion = "0.0.1"
radikoUser = "test-stream"
radikoDevice = "pc"
)
Expand Down

0 comments on commit 602ce31

Please sign in to comment.