radiko

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2016 License: MIT Imports: 21 Imported by: 0

README

Go Radiko

godoc build codecov go report

The unofficial radiko.jp APIs Client Library for Go

Installation

  • Go 1.7 or newer
$ go get github.com/yyoshiki41/go-radiko

Usage

■ Default
// authentication token is not necessary.
client, err := radiko.New("")
if err != nil {
	panic(err)
}
// Get programs data
stations, err := client.GetNowPrograms(context.Background())
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%v", stations)
■ Get & Set authentication token
  • swftools is required.
// 1. Download a swf player.
swfPath := path.Join(dir, "myplayer.swf")
if err := radiko.DownloadPlayer(swfPath); err != nil {
	log.Fatalf("Failed to download swf player. %s", err)
}

// 2. Using swfextract, create an authkey file from a swf player.
cmdPath, err := exec.LookPath("swfextract")
if err != nil {
	log.Fatal(err)
}
authKeyPath := path.Join(dir, "authkey.png")
if c := exec.Command(cmdPath, "-b", "12", swfPath, "-o", authKeyPath); err != c.Run() {
	log.Fatalf("Failed to execute swfextract. %s", err)
}

// 3. Create a new Client.
client, err := radiko.New("")
if err != nil {
	panic(err)
}

// 4. Enables and sets the auth_token.
// After client.AuthorizeToken() has succeeded,
// the client has the enabled auth_token internally.
authToken, err := client.AuthorizeToken(context.Background(), authKeyPath)
if err != nil {
	log.Fatal(err)
}
Premium member (Enable to use the area free.)

Step 1,2 are the same as above.

// 3. Create a new Client.
client, err := radiko.New("")
if err != nil {
	panic(err)
}

// 4. Login as the premium member
// After client.Login() has succeeded,
// the client has the valid cookie internally.
ctx := context.Background()
login, err := client.Login(ctx, "example@mail.com", "example_password")
if err != nil {
	log.Fatal(err)
}
if login.StatusCode() != 200 {
	log.Fatalf("Failed to login premium member.\nInvalid status code: %d",
		login.StatusCode())
}

// 5. Enables and sets the auth_token.
// After client.AuthorizeToken() has succeeded,
// the client has the enabled auth_token internally.
authToken, err := client.AuthorizeToken(context.Background(), authKeyPath)
if err != nil {
	log.Fatal(err)
}
■ Use your authentication token
// If the auth_token is cached, set your token in HTTP Header like below.
client, err = radiko.New("auth_token")
if err != nil {
	panic(err)
}

Examples

It is possible to try examples.

# Get programs data
$ go run ./examples/main.go
# Get & Set auth_token
$ go run ./examples/auth/main.go

Projects using go-radiko

  • radigo - Record a radiko program.

License


The MIT License

Author

Yoshiki Nakagawa

Documentation

Overview

Package radiko manages the radiko.jp APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreaID

func AreaID() (string, error)

AreaID returns areaID.

func DownloadPlayer

func DownloadPlayer(path string) error

DownloadPlayer downloads a swf player file.

func GetChunklistFromM3U8 added in v0.1.3

func GetChunklistFromM3U8(uri string) ([]string, error)

GetChunklistFromM3U8 returns a slice of url.

func GetLiveURL added in v0.3.2

func GetLiveURL(stationID string) string

GetLiveURL returns a live url for web browser.

func GetTimeshiftURL added in v0.3.2

func GetTimeshiftURL(stationID string, start time.Time) string

GetTimeshiftURL returns a timeshift url for web browser.

func SetHTTPClient

func SetHTTPClient(client *http.Client)

SetHTTPClient overrides the default HTTP client.

Types

type Client

type Client struct {
	URL *url.URL
	// contains filtered or unexported fields
}

Client represents a single connection to radiko API endpoint.

func New

func New(authToken string) (*Client, error)

New returns a new Client struct.

func (*Client) AreaID added in v0.3.0

func (c *Client) AreaID() string

AreaID returns the areaID.

func (*Client) Auth1Fms

func (c *Client) Auth1Fms(ctx context.Context) (string, int64, int64, error)

Auth1Fms returns authToken, keyLength, keyOffset and error.

func (*Client) Auth2Fms

func (c *Client) Auth2Fms(ctx context.Context, authToken, partialKey string) ([]string, error)

Auth2Fms enables the given authToken.

func (*Client) AuthToken added in v0.3.1

func (c *Client) AuthToken() string

AuthToken returns the authtoken.

func (*Client) AuthorizeToken

func (c *Client) AuthorizeToken(ctx context.Context, pngFile string) (string, error)

AuthorizeToken returns an enables auth_token and error, and sets auth_token in Client. Is is a alias function that wraps Auth1Fms and Auth2Fms.

func (*Client) Do added in v0.2.0

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do executes an API request.

func (*Client) GetNowPrograms

func (c *Client) GetNowPrograms(ctx context.Context) (Stations, error)

GetNowPrograms returns the program's meta-info which are currently on the air.

func (*Client) GetProgramByStartTime

func (c *Client) GetProgramByStartTime(ctx context.Context, stationID string, start time.Time) (*Prog, error)

GetProgramByStartTime returns a specified program. This API wraps GetStations.

func (*Client) GetStations

func (c *Client) GetStations(ctx context.Context, date time.Time) (Stations, error)

GetStations returns the program's meta-info.

func (*Client) GetWeeklyPrograms added in v0.2.0

func (c *Client) GetWeeklyPrograms(ctx context.Context, stationID string) (Stations, error)

GetWeeklyPrograms returns the weekly programs.

func (*Client) Jar added in v0.2.0

func (c *Client) Jar() http.CookieJar

Jar returns the cookieJar.

func (*Client) Login added in v0.2.0

func (c *Client) Login(ctx context.Context, mail, password string) (Statuser, error)

Login returns the Statuser that has StatusCode method.

func (*Client) SetAreaID added in v0.3.0

func (c *Client) SetAreaID(areaID string)

SetAreaID sets the areaID.

func (*Client) SetJar added in v0.2.0

func (c *Client) SetJar(jar *cookiejar.Jar)

SetJar sets the cookieJar in httpClient.

func (*Client) TimeshiftPlaylistM3U8

func (c *Client) TimeshiftPlaylistM3U8(ctx context.Context, stationID string, start time.Time) (string, error)

TimeshiftPlaylistM3U8 returns uri.

type LoginNG added in v0.2.0

type LoginNG struct {
	*LoginStatus
	Message string `json:"message"`
	Cause   string `json:"cause"`
}

LoginNG represents login failed.

type LoginOK added in v0.2.0

type LoginOK struct {
	*LoginStatus
	UserKey    string `json:"user_key"`
	PaidMember string `json:"paid_member"`
	Areafree   string `json:"areafree"`
}

LoginOK represents login is successful.

type LoginStatus added in v0.2.0

type LoginStatus struct {
	Status string `json:"status"`
}

LoginStatus is a base struct that has a Status field.

func (*LoginStatus) StatusCode added in v0.2.0

func (l *LoginStatus) StatusCode() int

StatusCode returns StatusCode that is type int.

type Params

type Params struct {
	// contains filtered or unexported fields
}

Params is the list of options to pass to the request.

type Prog

type Prog struct {
	Ft       string `xml:"ft,attr"`
	To       string `xml:"to,attr"`
	Ftl      string `xml:"ftl,attr"`
	Tol      string `xml:"tol,attr"`
	Dur      string `xml:"dur,attr"`
	Title    string `xml:"title"`
	SubTitle string `xml:"sub_title"`
	Desc     string `xml:"desc"`
	Pfm      string `xml:"pfm"`
	Info     string `xml:"info"`
	URL      string `xml:"url"`
}

Prog is a struct.

type Progs

type Progs struct {
	Date  string `xml:"date"`
	Progs []Prog `xml:"prog"`
}

Progs is a slice of Prog.

type Scd

type Scd struct {
	Progs Progs `xml:"progs"`
}

Scd is a struct.

type Station

type Station struct {
	ID    string `xml:"id,attr"`
	Name  string `xml:"name"`
	Scd   Scd    `xml:"scd,omitempty"`
	Progs Progs  `xml:"progs,omitempty"`
}

Station is a struct.

type Stations

type Stations []Station

Stations is a slice of Station.

type Statuser added in v0.2.0

type Statuser interface {
	StatusCode() int
}

Statuser is the interface that wraps StatusCode method.

type URLItem added in v0.2.1

type URLItem struct {
	Areafree bool   `xml:"areafree,attr"`
	Item     string `xml:",chardata"`
}

URLItem represents a stream url.

func GetStreamMultiURL added in v0.2.1

func GetStreamMultiURL(stationID string) ([]URLItem, error)

GetStreamMultiURL returns a slice of the stream url.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL