Documentation
¶
Overview ¶
Package api provides the FC2 API client.
Index ¶
- Variables
- type Channel
- type ChannelData
- type ChannelDataGiftList
- type Client
- func (c *Client) FindRestrictedStream(ctx context.Context) (string, error)
- func (c *Client) FindUnrestrictedStream(ctx context.Context) (string, error)
- func (c *Client) GetMeta(ctx context.Context, channelID string) (GetMetaData, error)
- func (c *Client) GetWebSocketURL(ctx context.Context, meta GetMetaData) (wsURL string, controlToken ControlToken, err error)
- func (c *Client) Login(ctx context.Context) error
- type Comment
- type CommentArguments
- type ControlDisconnectionArguments
- type ControlToken
- type GetChannelListChannel
- type GetChannelListResponse
- type GetControlServerResponse
- type GetMetaData
- type GetMetaResponse
- type HLSInformation
- type Latency
- type Playlist
- type ProfileData
- type Quality
- type UserData
- type WSResponse
- type WebSocket
- func (w *WebSocket) Dial(ctx context.Context) (*websocket.Conn, error)
- func (w *WebSocket) FetchPlaylist(ctx context.Context, conn *websocket.Conn, msgChan chan *WSResponse, ...) (playlist Playlist, availables []Playlist, err error)
- func (w *WebSocket) GetHLSInformation(ctx context.Context, conn *websocket.Conn, msgChan <-chan *WSResponse) (HLSInformation, error)
- func (w *WebSocket) HeartbeatLoop(ctx context.Context, conn *websocket.Conn, msgChan <-chan *WSResponse) error
- func (w *WebSocket) Listen(ctx context.Context, conn *websocket.Conn, msgChan chan<- *WSResponse, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWebSocketServerDisconnection is returned when the server disconnects. ErrWebSocketServerDisconnection = errors.New("server disconnected") // ErrWebSocketPaidProgram is returned when the server returns a paid program error. ErrWebSocketPaidProgram = errors.New("paid program") // ErrWebSocketLoginRequired is returned when the server returns a login required error. ErrWebSocketLoginRequired = errors.New("login required") // ErrWebSocketMultipleConnection is returned when the server returns a multiple connection error. ErrWebSocketMultipleConnection = errors.New("multiple connection error") // ErrWebSocketStreamEnded is returned when the server ends the stream. ErrWebSocketStreamEnded = errors.New("stream ended") // ErrWebSocketEmptyPlaylist is returned when the server does not return a valid playlist. ErrWebSocketEmptyPlaylist = errors.New("server did not return a valid playlist") // ErrQualityNotAvailable is returned when the quality is not available. ErrQualityNotAvailable = errors.New("requested quality is not available") // ErrNoResponse is returned when there is no response. ErrNoResponse = errors.New("no response") )
var ( // ErrRateLimit is returned when the API is rate limited. ErrRateLimit = errors.New("API rate limited") )
var ErrUnknownLatency = errors.New("unknown latency")
ErrUnknownLatency is returned when the latency is unknown.
var ErrUnknownQuality = errors.New("unknown quality")
ErrUnknownQuality is returned when the quality is unknown.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
Result json.Number `json:"result"`
UserID json.Number `json:"userid"`
Fc2ID json.Number `json:"fc2id"`
Adult json.Number `json:"adult"`
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
Images []interface{} `json:"images"`
}
Channel describes the FC2 channel.
type ChannelData ¶
type ChannelData struct {
ChannelID string `json:"channelid"`
UserID string `json:"userid"`
Adult json.Number `json:"adult"`
Twoshot json.Number `json:"twoshot"`
Title string `json:"title"`
Info string `json:"info"`
Image string `json:"image"`
LoginOnly json.Number `json:"login_only"`
GiftLimit json.Number `json:"gift_limit"`
GiftList []ChannelDataGiftList `json:"gift_list"`
CommentLimit string `json:"comment_limit"`
Tfollow json.Number `json:"tfollow"`
Tname string `json:"tname"`
Fee json.Number `json:"fee"`
Amount json.Number `json:"amount"`
Interval json.Number `json:"interval"`
Category json.Number `json:"category"`
CategoryName string `json:"category_name"`
IsOfficial json.Number `json:"is_official"`
IsPremiumPublisher json.Number `json:"is_premium_publisher"`
Ticketid json.Number `json:"ticketid"`
IsPremium json.Number `json:"is_premium"`
TicketPrice json.Number `json:"ticket_price"`
TicketOnly json.Number `json:"ticket_only"`
IsApp json.Number `json:"is_app"`
IsVideo json.Number `json:"is_video"`
IsREST json.Number `json:"is_rest"`
Count json.Number `json:"count"`
IsPublish int64 `json:"is_publish"`
IsLimited json.Number `json:"is_limited"`
Start json.Number `json:"start"`
Version string `json:"version"`
FC2Channel Channel `json:"fc2_channel"`
ControlTag string `json:"control_tag"`
PublishMethod string `json:"publish_method"`
VideoStereo3D interface{} `json:"video_stereo3d"`
VideoMapping interface{} `json:"video_mapping"`
VideoHorizontalView interface{} `json:"video_horizontal_view"`
}
ChannelData describes the FC2 channel and stream.
type ChannelDataGiftList ¶
type ChannelDataGiftList struct {
ID json.Number `json:"id"`
Type json.Number `json:"type"`
URL []string `json:"url"`
Name string `json:"name"`
}
ChannelDataGiftList describes the gifts that can be sent to the FC2 user.
type Client ¶
Client is the FC2 API client.
func (*Client) FindRestrictedStream ¶
FindRestrictedStream finds the first restricted stream.
func (*Client) FindUnrestrictedStream ¶
FindUnrestrictedStream finds the first unrestricted stream.
func (*Client) GetWebSocketURL ¶
func (c *Client) GetWebSocketURL( ctx context.Context, meta GetMetaData, ) (wsURL string, controlToken ControlToken, err error)
GetWebSocketURL gets the WebSocket URL for the live stream.
type Comment ¶
type Comment struct {
UserName string `json:"user_name"`
Comment string `json:"comment"`
Timestamp json.Number `json:"timestamp"`
EncryptedUserID string `json:"encrypted_user_id"`
OrzToken string `json:"orz_token"`
Hash string `json:"hash"`
Color string `json:"color"`
Size string `json:"size"`
Lang string `json:"lang"`
Anonymous json.Number `json:"anonymous"`
History json.Number `json:"history"`
}
Comment is the response from the websocket.
type CommentArguments ¶
type CommentArguments struct {
Comments []Comment `json:"comments"`
}
CommentArguments is the type of response corresponding to the "comment" event.
type ControlDisconnectionArguments ¶
type ControlDisconnectionArguments struct {
Code int `json:"code"`
}
ControlDisconnectionArguments is the type of response corresponding to the "control_disconnection" event.
type ControlToken ¶
type ControlToken struct {
ID string `json:"id"`
ChannelListChannelID string `json:"ChannelListchannel_id"`
UserID string `json:"user_id"`
ServiceID json.Number `json:"service_id"`
OrzToken string `json:"orz_token"`
Premium json.Number `json:"premium"`
Mode string `json:"mode"`
Language string `json:"language"`
ClientType string `json:"client_type"`
ClientApp string `json:"client_app"`
ClientVersion string `json:"client_version"`
AppInstallKey string `json:"app_install_key"`
ChannelListChannelVersion string `json:"ChannelListchannel_version"`
IP string `json:"ip"`
Ipv6 string `json:"ipv6"`
Commentable json.Number `json:"commentable"`
UserName string `json:"user_name"`
AdultAccess json.Number `json:"adult_access"`
AgentID json.Number `json:"agent_id"`
CountryCode string `json:"country_code"`
PayMode json.Number `json:"pay_mode"`
Exp json.Number `json:"exp"`
jwt.RegisteredClaims
}
ControlToken is the token used to authenticate with the FC2 API.
type GetChannelListChannel ¶
type GetChannelListChannel struct {
ID string `json:"id"`
Bid string `json:"bid"`
Video json.Number `json:"video"`
App json.Number `json:"app"`
Category json.Number `json:"category"`
Type json.Number `json:"type"`
Fc2ID json.Number `json:"fc2id"`
Name string `json:"name"`
Title string `json:"title"`
Image string `json:"image"`
Start string `json:"start"`
StartTime json.Number `json:"start_time"`
Sex string `json:"sex"`
Pay json.Number `json:"pay"`
Interval json.Number `json:"interval"`
Amount json.Number `json:"amount"`
Lang string `json:"lang"`
Total json.Number `json:"total"`
Count json.Number `json:"count"`
Login json.Number `json:"login"`
CommentL json.Number `json:"comment_l"`
Tid json.Number `json:"tid"`
Price json.Number `json:"price"`
Official json.Number `json:"official"`
CommentScore json.Number `json:"comment_score"`
DenyCountryFlg string `json:"deny_country_flg"`
Panorama json.Number `json:"panorama"`
}
GetChannelListChannel describes the FC2 channel.
type GetChannelListResponse ¶
type GetChannelListResponse struct {
Link string `json:"link"`
IsAdult int64 `json:"is_adult"`
Time int64 `json:"time"`
Channel []GetChannelListChannel `json:"channel"`
}
GetChannelListResponse is the response from the get_channel_list endpoint.
type GetControlServerResponse ¶
type GetControlServerResponse struct {
URL string `json:"url"`
Orz string `json:"orz"`
OrzRaw string `json:"orz_raw"`
ControlToken string `json:"control_token"`
Status json.Number `json:"status"`
}
GetControlServerResponse is the response from the get_control_server endpoint.
type GetMetaData ¶
type GetMetaData struct {
ChannelData ChannelData `json:"channel_data"`
ProfileData ProfileData `json:"profile_data"`
UserData UserData `json:"user_data"`
}
GetMetaData is the data of the response from the get_meta endpoint.
type GetMetaResponse ¶
type GetMetaResponse struct {
Status json.Number `json:"status"`
Data GetMetaData `json:"data"`
}
GetMetaResponse is the response from the get_meta endpoint.
type HLSInformation ¶
type HLSInformation struct {
Status json.Number `json:"status"`
Playlists []Playlist `json:"playlists"`
PlaylistsHighLatency []Playlist `json:"playlists_high_latency"`
PlaylistsMiddleLatency []Playlist `json:"playlists_middle_latency"`
}
HLSInformation is the response from the get_hls_information endpoint.
type Latency ¶
type Latency int
Latency represents the latency of the live stream.
func LatencyFromMode ¶
LatencyFromMode returns a Latency from a mode.
func LatencyParseString ¶
LatencyParseString parses a string into a Latency.
func (*Latency) UnmarshalText ¶
UnmarshalText unmarshals a string into a Latency.
type Playlist ¶
type Playlist struct {
Mode int `json:"mode"`
Status json.Number `json:"status"`
URL string `json:"url"`
}
Playlist describes a m3u8 playlist and its specifications.
func ExtractAndMergePlaylists ¶
func ExtractAndMergePlaylists(hlsInfo HLSInformation) []Playlist
ExtractAndMergePlaylists extracts and merges the playlists.
func GetPlaylistOrBest ¶
GetPlaylistOrBest returns the playlist that matches the mode or the best.
func SortPlaylists ¶
SortPlaylists sorts the playlists by mode.
type ProfileData ¶
type ProfileData struct {
UserID string `json:"userid"`
Fc2ID string `json:"fc2id"`
Name string `json:"name"`
Info string `json:"info"`
Icon string `json:"icon"`
Image string `json:"image"`
Sex string `json:"sex"`
Age string `json:"age"`
}
ProfileData describes the FC2 user's profile.
type Quality ¶
type Quality int
Quality represents the quality of the live stream.
const ( // QualityUnknown represents an unknown quality. QualityUnknown Quality = 0 // Quality150KBps represents a 150Kbps bitrate. Quality150KBps Quality = 10 // Quality400KBps represents a 400Kbps bitrate. Quality400KBps Quality = 20 // Quality1_2MBps represents a 1.2Mbps bitrate. Quality1_2MBps Quality = 30 // Quality2MBps represents a 2Mbps bitrate. Quality2MBps Quality = 40 // Quality3MBps represents a 3Mbps bitrate. Quality3MBps Quality = 50 // QualitySound represents a sound only stream. QualitySound Quality = 90 )
func QualityFromMode ¶
QualityFromMode returns a Quality from a live stream mode.
func QualityParseString ¶
QualityParseString parses a string into a Quality.
func (*Quality) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type UserData ¶
type UserData struct {
IsLogin json.Number `json:"is_login"`
UserID json.Number `json:"userid"`
Fc2ID json.Number `json:"fc2id"`
Icon string `json:"icon"`
Name string `json:"name"`
Point interface{} `json:"point"`
AdultAccess interface{} `json:"adult_access"`
Recauth interface{} `json:"recauth"`
IsPremiumUser interface{} `json:"is_premium_user"`
GiftList interface{} `json:"gift_list"`
Stamina interface{} `json:"stamina"`
}
UserData describes the FC2 user.
type WSResponse ¶
type WSResponse struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
WSResponse is the response from the websocket.
func (WSResponse) String ¶
func (r WSResponse) String() string
type WebSocket ¶
WebSocket is used to interact with the FC2 WebSocket.
func NewWebSocket ¶
NewWebSocket creates a new WebSocket.
func (*WebSocket) FetchPlaylist ¶
func (w *WebSocket) FetchPlaylist( ctx context.Context, conn *websocket.Conn, msgChan chan *WSResponse, expectedMode int, ) (playlist Playlist, availables []Playlist, err error)
FetchPlaylist fetches the playlist.
func (*WebSocket) GetHLSInformation ¶
func (w *WebSocket) GetHLSInformation( ctx context.Context, conn *websocket.Conn, msgChan <-chan *WSResponse, ) (HLSInformation, error)
GetHLSInformation returns the HLS information.
func (*WebSocket) HeartbeatLoop ¶
func (w *WebSocket) HeartbeatLoop( ctx context.Context, conn *websocket.Conn, msgChan <-chan *WSResponse, ) error
HeartbeatLoop sends a heartbeat to keep the ws alive.
The only way to exit the heartbeat loop is to have the WS socket closed or to cancel the context.