radiko

package module
Version: v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: GPL-3.0 Imports: 23 Imported by: 7

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
// 1. Create a new Client.
client, err := radiko.New("")
if err != nil {
	panic(err)
}

// 2. 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.)
// 1. Create a new Client.
client, err := radiko.New("")
if err != nil {
	panic(err)
}

// 2. 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())
}

// 3. 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

License


Licensed under the GPLv3 license for all open source applications.

Please do not use this project for commercial use.

Author

Yoshiki Nakagawa

Documentation

Overview

Package radiko manages the radiko.jp APIs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProgramNotFound is returned when a program not found
	ErrProgramNotFound = errors.New("program not found")
)

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.

func SetUserAgent added in v0.4.0

func SetUserAgent(ua string)

SetUserAgent overrides the default User-Agent header.

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) Auth1 added in v0.7.0

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

Auth1 returns authToken, keyLength, keyOffset and error.

func (*Client) Auth2 added in v0.7.0

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

Auth2 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) (string, error)

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

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 SmhURLItem added in v0.8.0

type SmhURLItem struct {
	Text              string `xml:",chardata"`
	Areafree          bool   `xml:"areafree,attr"`
	MediaURLPath      string `xml:"media_url_path"`
	PlaylistCreateURL string `xml:"playlist_create_url"`
	PlaylistURLPath   string `xml:"playlist_url_path"`
}

URLItem represents a stream url.

func GetStreamSmhMultiURL added in v0.8.0

func GetStreamSmhMultiURL(stationID string) ([]SmhURLItem, error)

GetStreamSmhMultiURL returns a slice of the stream smh url.

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