api

package
v0.0.0-...-1c5219f Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: BSD-2-Clause Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// APIBaseURL is the base URL for the AudioAddict v1 API's
	APIBaseURL = `https://api.audioaddict.com/v1`
)

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrCantAuthenticate   = errors.New("can't authenticate to server")
)
View Source
var (
	// ErrChannelRequiresPremium is returned by (*Channel).StreamURLs() when the channel is only for premium accounts and given account is not a premium account.
	ErrChannelRequiresPremium = errors.New("channel requires a premium account")

	// ErrNoTracklist is returned when the API returns a valid result, but the tracklist is empty (or only contains ads)
	ErrNoTracklist = errors.New("no tracklist found")
)
View Source
var (
	EncodingAAC = Encoding("AAC")
	EncodingMP3 = Encoding("MP3")
	EncodingWMA = Encoding("WMA")
)
View Source
var (
	// ErrStreamlistNotAvailable is returned by (*Network).StreamlistByKey() when there is no streamlist with given key
	ErrStreamlistNotAvailable = errors.New("streamlist not available")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID        int
	APIKey    string
	ListenKey string
	Firstname string
	Lastname  string
	Premium   bool
	Favorites []int
}

func (*Account) IsFavoriteChannel

func (a *Account) IsFavoriteChannel(id int) bool

IsFavoriteChannel returns whether the channel (provided by id) is favorited in the account.

type Channel

type Channel struct {
	// Network on which the channel resides
	Network *Network
	// Streamlist to which the channel belongs (audio quality)
	Streamlist *Streamlist
	// ID is the numerical reference to this channel. It seems to be unique per channel (quality-agnostic)
	ID int `json:"id"`
	// Key is the lowercase name for this channel
	Key string `json:"key"`
	// Name is the human readable name for this channel
	Name string `json:"name"`
	// Playlist is the playlist URL that can be used by the media player.
	Playlist string `json:"playlist"`
}

Channel contains information about a AudioAddict channel

func (*Channel) CurrentTrack

func (c *Channel) CurrentTrack() (*Track, error)

func (*Channel) StreamURLs

func (c *Channel) StreamURLs(acc *Account) ([]string, error)

StreamURLs returns a list of stream URL's

func (*Channel) Tracklist

func (c *Channel) Tracklist() (Tracklist, error)

type Encoding

type Encoding string

Encoding defines the type of audio encoding/compression that is used

type Network

type Network struct {
	// Name is the human readable name for the network, e.g.: "RadioTunes"
	Name string

	// ListenURLBase is the base URL string to be used with certain API calls
	//++ TODO: unexport?
	ListenURLBase string

	// Key is to be used with certain API calls
	//++ TODO: unexport?
	Key string

	// streamlists is a slice of Streamlist's available on this network
	Streamlists []*Streamlist
	// contains filtered or unexported fields
}

Network defines the parameters for an AudioAddict network such as di.fm It provides API methods to get channels and stream information

var (
	// NetworkDI defines the network parameters for DI.fm radio.
	NetworkDI *Network

	// NetworkRadioTunes contains the network parameters for RadioTunes.com radio.
	NetworkRadioTunes *Network

	// NetworkList contains all networks defined by this package, it is possible to add/remove items from this list.
	NetworkList = []*Network{NetworkDI, NetworkRadioTunes}
)

func (*Network) AuthenticateAPIKey

func (n *Network) AuthenticateAPIKey(apikey string) (*Account, error)

func (*Network) AuthenticateUserPass

func (n *Network) AuthenticateUserPass(username, password string) (*Account, error)

func (*Network) BestStreamlist

func (n *Network) BestStreamlist(premium bool) *Streamlist

BestStreamlist returns the best quality Streamlist for the network. When premium is available (true), it will return the best premium Streamlist

func (*Network) StreamlistByKey

func (n *Network) StreamlistByKey(key string) (*Streamlist, error)

StreamlistByKey looks up the correct streamlist for given key. When none is found, ErrStreamlistNotAvailable is returned.

func (*Network) TrackHistory

func (n *Network) TrackHistory() (map[string]*Track, error)

type PingInfo

type PingInfo struct {
	APIVersion float64
	Time       time.Time // NOTE: server time is converted to a time.Time value in the UTC timezone.
	IP         string
	Country    string
}

PingInfo holds the information that is sent back by the audioaddict api server on a ping request.

func Ping

func Ping() (*PingInfo, error)

Ping pings the server, this returns some information about the location of this client, and provides the client with the current servertime.

type Streamlist

type Streamlist struct {
	// Network is a reference to the network on which this streamlist resides.
	Network *Network

	// Key is the identifier to be used with API calls.
	Key string

	// Premium indicates wether this streamlist can only be used by premium accounts.
	Premium bool

	// Bitrate is the stream bitrate in kbit/s.
	Bitrate int

	// Encoding is the stream encoding.
	Encoding Encoding
}

Streamlist defines

func (*Streamlist) Channels

func (sl *Streamlist) Channels() ([]*Channel, error)

Channels returns a list of channels available on this Streamlist

func (*Streamlist) Name

func (sl *Streamlist) Name() string

Name returns the human-readable name for this streamlist

type Track

type Track struct {
	Name          string            `json:"track"`
	Type          string            `json:"type"`
	Duration      int               `json:"duration"`
	Started       int               `json:"started"`
	ArtURL        string            `json:"art_url"`
	Artist        string            `json:"artist"`
	ChannelID     int               `json:"channel_id"`
	DisplayArtist string            `json:"display_artist"`
	DisplayTitle  string            `json:"display_title"`
	Images        map[string]string `json:"images"`
	Length        int               `json:"length"`
	NetworkID     int               `json:"network_id"`
	Release       string            `json:"release"`
	Title         string            `json:"title"`
	TrackID       int               `json:"track_id"`
}

func (*Track) ArtURLHTTPS

func (t *Track) ArtURLHTTPS() string

type Tracklist

type Tracklist []*Track

Jump to

Keyboard shortcuts

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