Documentation ¶
Overview ¶
Package api provide a client for the withny API.
Index ¶
- Variables
- func FindGraphQLEndpointAndStreamUUID(r io.Reader) (endpoint, suuid string, err error)
- type AgencySecret
- type Cast
- type CastSocialMediaAccount
- type Claims
- type Client
- func (c *Client) GetPlaylists(ctx context.Context, playbackURL string) ([]Playlist, error)
- func (c *Client) GetStreamPlaybackURL(ctx context.Context, streamID string) (string, error)
- func (c *Client) GetStreams(ctx context.Context, channelID string) (GetStreamsResponse, error)
- func (c *Client) GetUser(ctx context.Context, channelID string) (GetUserResponse, error)
- func (c *Client) Login(ctx context.Context) (err error)
- func (c *Client) LoginLoop(ctx context.Context) error
- func (c *Client) LoginWithRefreshToken(ctx context.Context, refreshToken string) (Credentials, error)
- func (c *Client) LoginWithUserPassword(ctx context.Context, username, password string) (Credentials, error)
- func (c *Client) NewAuthRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
- func (c *Client) SetCredentials(creds Credentials)
- type Comment
- type Credentials
- type CredentialsCache
- type CredentialsReader
- type ErrorResponse
- type GetPlaybackURLError
- type GetStreamsResponse
- type GetStreamsResponseElement
- type GetUserResponse
- type LoginResponse
- type MetaData
- type Playlist
- type PlaylistConstraint
- type SavedCredentials
- type Scraper
- type ServerError
- type UnauthorizedError
- type WSCommentResponse
- type WSResponse
- type WebSocket
- func (w *WebSocket) ConnectionInit(ctx context.Context, conn *websocket.Conn) error
- func (w *WebSocket) Dial(ctx context.Context) (*websocket.Conn, error)
- func (w *WebSocket) Subscribe(ctx context.Context, conn *websocket.Conn, streamID string) error
- func (w *WebSocket) WatchComments(ctx context.Context, conn *websocket.Conn, streamID string, ...) error
Constants ¶
This section is empty.
Variables ¶
var ErrStreamNotFound = errors.New("stream not found")
ErrStreamNotFound is when no stream is found when looking for the playback URL.
Functions ¶
Types ¶
type AgencySecret ¶
type AgencySecret struct { ID int64 `json:"id"` UUID string `json:"uuid"` ChannelName string `json:"username"` Name string `json:"name"` }
AgencySecret is the agency secret of the cast.
type Cast ¶
type Cast struct { ID json.Number `json:"id"` UUID string `json:"uuid"` Coupon string `json:"coupon"` ProfileImageURL string `json:"profileImageUrl"` HeaderImageURL string `json:"headerImageUrl"` IsFavorite bool `json:"isFavorite"` CastSocialMediaAccounts []CastSocialMediaAccount `json:"castSocialMediaAccounts"` AgencySecret AgencySecret `json:"agencySecret"` }
Cast is the cast of the user.
type CastSocialMediaAccount ¶
type CastSocialMediaAccount struct { Platform string `json:"platform"` ChannelName string `json:"username"` }
CastSocialMediaAccount is the social media account of the cast.
type Claims ¶
type Claims struct { jwt.RegisteredClaims UserUUID string `json:"userUuid"` TokenUUID string `json:"tokenUuid"` Scope string `json:"scope"` }
Claims is the JWT claims for the withny API.
type Client ¶
Client is a withny API client.
func NewClient ¶
func NewClient(client *http.Client, reader CredentialsReader, cache CredentialsCache) *Client
NewClient creates a new withny API client.
func (*Client) GetPlaylists ¶
GetPlaylists will fetch the playlists from the given playbackURL.
func (*Client) GetStreamPlaybackURL ¶
GetStreamPlaybackURL will fetch the playback URL for the given streamID.
func (*Client) GetStreams ¶
GetStreams will fetch the streams for the given channelID.
func (*Client) LoginWithRefreshToken ¶
func (c *Client) LoginWithRefreshToken( ctx context.Context, refreshToken string, ) (Credentials, error)
LoginWithRefreshToken will login with the given refreshToken.
func (*Client) LoginWithUserPassword ¶
func (c *Client) LoginWithUserPassword( ctx context.Context, username, password string, ) (Credentials, error)
LoginWithUserPassword will login with the given email and password.
func (*Client) NewAuthRequestWithContext ¶
func (c *Client) NewAuthRequestWithContext( ctx context.Context, method, url string, body io.Reader, ) (*http.Request, error)
NewAuthRequestWithContext creates a new authenticated request with the given context.
func (*Client) SetCredentials ¶
func (c *Client) SetCredentials(creds Credentials)
SetCredentials sets the credentials for the client.
type Comment ¶ added in v0.2.0
type Comment struct { StreamUUID string `json:"streamUUID"` CommentUUID string `json:"commentUUID"` UserUUID string `json:"userUUID"` Username string `json:"username"` Name string `json:"name"` ContentType string `json:"contentType"` Content string `json:"content"` TipAmount json.Number `json:"tipAmount"` ItemID string `json:"itemID"` ItemName string `json:"itemName"` ItemURI string `json:"itemURI"` AnimationURI string `json:"animationURI"` ItemPower json.Number `json:"itemPower"` ItemLifetime json.Number `json:"itemLifetime"` CreatedAt *string `json:"createdAt"` UpdatedAt *string `json:"updatedAt"` DeletedAt *string `json:"deletedAt"` }
Comment is the comment of the stream.
type Credentials ¶
type Credentials struct { Claims LoginResponse }
Credentials is the credentials for the withny API.
type CredentialsCache ¶ added in v1.2.2
type CredentialsCache interface { Set(creds Credentials) error Get() (Credentials, error) Invalidate() error }
CredentialsCache is an interface for caching credentials.
type CredentialsReader ¶
type CredentialsReader interface {
Read() (SavedCredentials, error)
}
CredentialsReader is an interface for reading saved credentials.
type ErrorResponse ¶ added in v0.2.10
ErrorResponse is the error response of the API.
type GetPlaybackURLError ¶ added in v0.2.10
GetPlaybackURLError is an error given by the GetStreamPlaybackURL API.
func (GetPlaybackURLError) Error ¶ added in v0.2.10
func (e GetPlaybackURLError) Error() string
Error returns the error message.
type GetStreamsResponse ¶
type GetStreamsResponse []GetStreamsResponseElement
GetStreamsResponse is the response of the get streams request.
type GetStreamsResponseElement ¶
type GetStreamsResponseElement struct { UUID string `json:"uuid"` Title string `json:"title"` About string `json:"about"` ThumbnailURL string `json:"thumbnailUrl"` BillingMode string `json:"billingMode"` Price json.Number `json:"price"` StreamingMethod string `json:"streamingMethod"` StartedAt time.Time `json:"startedAt"` ClosedAt interface{} `json:"closedAt"` DeviceID json.Number `json:"deviceId"` Cast Cast `json:"cast"` HasTicket bool `json:"hasTicket"` }
GetStreamsResponseElement is the element of the get streams response.
type GetUserResponse ¶
type GetUserResponse struct { ID json.Number `json:"id"` UUID string `json:"uuid"` Username string `json:"username"` Name string `json:"name"` ProfileText string `json:"profileText"` ProfileImageURL string `json:"profileImageUrl"` HeaderImageURL string `json:"headerImageUrl"` Cast Cast `json:"cast"` CreateRoomNotificationEnabled bool `json:"createRoomNotificationEnabled"` ProfileTextPlain string `json:"profileTextPlain"` }
GetUserResponse is the response of the get user request.
type LoginResponse ¶
type LoginResponse struct { Token string `json:"token"` RefreshToken string `json:"refreshToken"` TokenType string `json:"tokenType"` }
LoginResponse is the response of the login request.
type MetaData ¶
type MetaData struct { User GetUserResponse Stream GetStreamsResponseElement }
MetaData is the metadata of the stream.
type Playlist ¶
type Playlist struct { Bandwidth int64 Resolution string Codecs string Video string FrameRate float64 URL string }
Playlist represents a stream in an M3U8 playlist.
func GetBestPlaylist ¶
func GetBestPlaylist( streams []Playlist, constraints ...PlaylistConstraint, ) (best Playlist, found bool)
GetBestPlaylist returns the best playlist based on the constraints.
type PlaylistConstraint ¶
type PlaylistConstraint struct { MinBandwidth int64 `yaml:"minBandwidth"` MaxBandwidth int64 `yaml:"maxBandwidth"` MinHeight int64 `yaml:"minHeight"` MaxHeight int64 `yaml:"maxHeight"` MinWidth int64 `yaml:"minWidth"` MaxWidth int64 `yaml:"maxWidth"` MinFrameRate float64 `yaml:"minFrameRate"` MaxFrameRate float64 `yaml:"maxFrameRate"` AudioOnly bool `yaml:"audioOnly"` Ignored []string `yaml:"ignored"` }
PlaylistConstraint is used to filter playlists based on their attributes.
type SavedCredentials ¶
type SavedCredentials struct { Username string `yaml:"username" json:"username"` Password string `yaml:"password" json:"password"` Token string `yaml:"token" json:"token"` RefreshToken string `yaml:"refreshToken" json:"refreshToken"` }
SavedCredentials is the saved credentials given by the user for the withny API.
type Scraper ¶ added in v0.2.0
type Scraper struct {
*Client
}
Scraper is used to scrape the withny website.
func NewScraper ¶ added in v0.2.0
NewScraper creates a new Scraper.
A scraper is needed since Withny is using SSR.
func (*Scraper) FindGraphQLAndStreamUUID ¶ added in v0.2.0
func (s *Scraper) FindGraphQLAndStreamUUID( ctx context.Context, channelID string, ) (endpoint, suuid string, err error)
FindGraphQLAndStreamUUID finds the GraphQL endpoint.
The GraphQL endpoint is hard-coded on the website and uses AWS AppSync. Technically, we could just hard-code it too, but to avoid any "unexpected" changes, we'll just scrape it.
type ServerError ¶ added in v1.1.1
ServerError is an error given by the withny server.
func (ServerError) Error ¶ added in v1.1.1
func (e ServerError) Error() string
Error returns the error message.
type UnauthorizedError ¶ added in v0.2.6
type UnauthorizedError struct {
}UnauthorizedError is when the request is unauthorized.
func (UnauthorizedError) Error ¶ added in v0.2.6
func (e UnauthorizedError) Error() string
Error returns the error message.
type WSCommentResponse ¶ added in v0.2.0
type WSCommentResponse struct { Data struct { OnPostComment Comment `json:"onPostComment"` } `json:"data"` }
WSCommentResponse is the response of the WebSocket GraphQL Comments API.
type WSResponse ¶ added in v0.2.0
type WSResponse struct { Type string `json:"type"` ID string `json:"id"` Payload json.RawMessage `json:"payload"` }
WSResponse is the response from the WebSocket.
type WebSocket ¶ added in v0.2.0
type WebSocket struct { *Client // contains filtered or unexported fields }
WebSocket is used to interact with the withny WebSocket.
func NewWebSocket ¶ added in v0.2.0
NewWebSocket creates a new WebSocket.
func (*WebSocket) ConnectionInit ¶ added in v0.2.0
ConnectionInit initializes the connection to the WebSocket.