Documentation
¶
Overview ¶
Package client is the public Go SDK for MusOak.
Everything the server does is an API call, so the CLI, a Discord bot or any other tool is a plain client: authenticate, search, prepare media, queue it in a room and follow the host's playback state. Nothing reaches into server internals.
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- type APIError
- type Album
- type AlbumVariant
- type Artist
- type ArtistVariant
- type Auth
- type Cache
- func (c *Cache) Dir() string
- func (c *Cache) Entries() []CacheEntry
- func (c *Cache) Fetch(ctx context.Context, api *Client, variantID string) (CacheEntry, error)
- func (c *Cache) Lookup(variantID string) (CacheEntry, bool)
- func (c *Cache) LookupTrack(trackID string) (CacheEntry, bool)
- func (c *Cache) Path(variantID string) string
- func (c *Cache) Put(entry CacheEntry) error
- type CacheEntry
- type Capabilities
- type Client
- func (c *Client) AddFavorite(ctx context.Context, trackID string, rating ...float64) error
- func (c *Client) AddPlaylistTracks(ctx context.Context, playlistID string, trackIDs ...string) (*PlaylistDetail, error)
- func (c *Client) Album(ctx context.Context, albumID string) (*Album, error)
- func (c *Client) Artist(ctx context.Context, artistID string) (*Artist, error)
- func (c *Client) BaseURL() string
- func (c *Client) Clock(ctx context.Context) (int64, error)
- func (c *Client) ClockOffset(ctx context.Context, samples int) (time.Duration, error)
- func (c *Client) CreatePlaylist(ctx context.Context, name string) (*Playlist, error)
- func (c *Client) CreateRoom(ctx context.Context, name, controls string) (*RoomClient, error)
- func (c *Client) DeletePlaylist(ctx context.Context, playlistID string) error
- func (c *Client) DownloadMedia(ctx context.Context, variantID string, w io.Writer) (int64, error)
- func (c *Client) Events(ctx context.Context, roomID string) (<-chan Event, error)
- func (c *Client) Favorites(ctx context.Context) ([]Track, error)
- func (c *Client) ImportDir(ctx context.Context, dir string) (*ImportResult, error)
- func (c *Client) ImportPath(ctx context.Context, path string) (*ImportResult, error)
- func (c *Client) JoinRoom(ctx context.Context, roomID string) (*RoomClient, error)
- func (c *Client) Login(ctx context.Context, username, password string) (*Auth, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Me(ctx context.Context) (*Me, error)
- func (c *Client) MediaStatus(ctx context.Context, variantID string) (*MediaStatus, error)
- func (c *Client) MediaURL(variantID string, startMs int64) string
- func (c *Client) MemberID() string
- func (c *Client) OpenMedia(ctx context.Context, variantID string) (io.ReadCloser, error)
- func (c *Client) Playlist(ctx context.Context, playlistID string) (*PlaylistDetail, error)
- func (c *Client) PlaylistByName(ctx context.Context, name string) (*Playlist, error)
- func (c *Client) PlaylistFromAlbum(ctx context.Context, albumID, name string) (*PlaylistDetail, error)
- func (c *Client) Playlists(ctx context.Context) ([]Playlist, error)
- func (c *Client) Providers(ctx context.Context) ([]Provider, error)
- func (c *Client) Radio(ctx context.Context, seedTrackID string, opts RadioOptions) (*RadioResult, error)
- func (c *Client) Ranking(ctx context.Context) (*Ranking, error)
- func (c *Client) Register(ctx context.Context, username, password string) (*Auth, error)
- func (c *Client) RemoveFavorite(ctx context.Context, trackID string) error
- func (c *Client) RemovePlaylistItem(ctx context.Context, playlistID string, position int) (*PlaylistDetail, error)
- func (c *Client) RenamePlaylist(ctx context.Context, playlistID, name string) (*Playlist, error)
- func (c *Client) ReorderPlaylist(ctx context.Context, playlistID string, order []int) (*PlaylistDetail, error)
- func (c *Client) ResolveTrack(ctx context.Context, trackID string) ([]Variant, bool, error)
- func (c *Client) Rooms(ctx context.Context) ([]Room, error)
- func (c *Client) Search(ctx context.Context, query string, limit int) (*SearchResult, error)
- func (c *Client) SearchAlbums(ctx context.Context, query string, limit int) ([]Album, []ProviderError, error)
- func (c *Client) SearchArtists(ctx context.Context, query string, limit int) ([]Artist, []ProviderError, error)
- func (c *Client) SetMemberID(memberID string)
- func (c *Client) SetRanking(ctx context.Context, providers []string) (*Ranking, error)
- func (c *Client) SetToken(token string)
- func (c *Client) StartDownload(ctx context.Context, variantID string) (*MediaStatus, error)
- func (c *Client) StartDownloadAndWait(ctx context.Context, variantID string) (*MediaStatus, error)
- func (c *Client) SyncAlbum(ctx context.Context, albumID string, opts SyncOptions) (*SyncResult, error)
- func (c *Client) SyncArtist(ctx context.Context, artistID string, opts SyncOptions) (*SyncResult, error)
- func (c *Client) Token() string
- func (c *Client) Track(ctx context.Context, trackID string) (*Track, error)
- func (c *Client) TrackVariants(ctx context.Context, trackID string) ([]Variant, error)
- func (c *Client) WaitForMedia(ctx context.Context, variantID string) (*MediaStatus, error)
- type ClockSample
- type Event
- type HostChangedEvent
- type ImportResult
- type Imported
- type Me
- type MediaStatus
- type Option
- type Participant
- func (p *Participant) ClockOffset() time.Duration
- func (p *Participant) LocalPosition(ctx context.Context) (int64, bool)
- func (p *Participant) MemberID() string
- func (p *Participant) Position() int64
- func (p *Participant) Room() *RoomClient
- func (p *Participant) Run(ctx context.Context) error
- func (p *Participant) SetDriftTolerance(ms int64)
- func (p *Participant) StopPlayback(ctx context.Context) error
- func (p *Participant) Vote(ctx context.Context, score float64, autoSkip ...bool) error
- type Pauser
- type PlaybackEvent
- type Playlist
- type PlaylistDetail
- type PlaylistItem
- type Positioner
- type Provider
- type ProviderError
- type QueueEvent
- type QueueItem
- type RadioOptions
- type RadioResult
- type Ranking
- type Room
- type RoomClient
- func (r *RoomClient) Client() *Client
- func (r *RoomClient) Events(ctx context.Context) (<-chan Event, error)
- func (r *RoomClient) Leave(ctx context.Context) error
- func (r *RoomClient) Pause(ctx context.Context) (*Room, error)
- func (r *RoomClient) Queue(ctx context.Context, trackID string) (*Room, error)
- func (r *RoomClient) QueueMany(ctx context.Context, trackIDs []string) (*Room, error)
- func (r *RoomClient) Remove(ctx context.Context, itemID string) (*Room, error)
- func (r *RoomClient) Reorder(ctx context.Context, itemIDs []string) (*Room, error)
- func (r *RoomClient) Resume(ctx context.Context) (*Room, error)
- func (r *RoomClient) Seek(ctx context.Context, positionMs int64) (*Room, error)
- func (r *RoomClient) Skip(ctx context.Context) (*Room, error)
- func (r *RoomClient) Snapshot(ctx context.Context) (*Room, error)
- func (r *RoomClient) Vote(ctx context.Context, score float64, autoSkip ...bool) (*Room, error)
- type RoomMember
- type RoomPlayback
- type RoomSkipRules
- type SearchGroup
- type SearchResult
- type Seeker
- type Sink
- type SinkTrack
- type SyncOptions
- type SyncResult
- type Track
- type User
- type Variant
Constants ¶
const ( MediaNone = "none" MediaDownloading = "downloading" MediaReady = "ready" MediaFailed = "failed" )
Media states.
const ( // MediaStageDownload means bytes are arriving from the provider. MediaStageDownload = "download" // MediaStageConvert means the fetched source is being written as the stored // rendition, so Bytes/TotalBytes are milliseconds there. MediaStageConvert = "convert" // MediaStageStore means the finished file is being probed and put in place. MediaStageStore = "store" )
Media stages: what a download is doing between "downloading" and "ready".
const ( EventMemberJoined = "member_joined" EventMemberLeft = "member_left" EventHostChanged = "host_changed" EventQueueUpdated = "queue_updated" EventPlayback = "playback" EventRoomClosed = "room_closed" )
Event types.
const DefaultTimeout = 30 * time.Second
DefaultTimeout bounds a single API request, not a media transfer.
const MaxQueueBatch = 500
MaxQueueBatch is how many tracks one add may carry. The server holds the room lock across a batch, so it refuses more; QueueMany splits longer runs.
Variables ¶
var ErrRoomClosed = errors.New("musoak: the room closed")
ErrRoomClosed is what Run returns when the room closed under it. It is distinct from a plain nil, which means the connection to the room dropped: the room is still there and following it again is worthwhile.
Functions ¶
func IsConflict ¶
IsConflict reports whether err is a 409 from the server.
func IsNotFound ¶
IsNotFound reports whether err is a 404 from the server.
func IsUnauthorized ¶
IsUnauthorized reports whether err is a 401 from the server.
Types ¶
type Album ¶
type Album struct {
ID string `json:"id"`
Title string `json:"title"`
Artists []string `json:"artists"`
Year string `json:"year,omitempty"`
TrackCount int `json:"trackCount"`
Providers []string `json:"providers"`
Variants []AlbumVariant `json:"variants,omitempty"`
Tracks []Track `json:"tracks,omitempty"`
}
Album is a canonical album; providers lists the sources that know it.
type AlbumVariant ¶
type AlbumVariant struct {
ID string `json:"id"`
Provider string `json:"provider"`
ProviderAlbumID string `json:"providerAlbumId"`
Title string `json:"title"`
Artists []string `json:"artists"`
Year string `json:"year,omitempty"`
TrackCount int `json:"trackCount,omitempty"`
}
AlbumVariant is one provider's release of a canonical album.
type Artist ¶
type Artist struct {
ID string `json:"id"`
Name string `json:"name"`
Providers []string `json:"providers"`
Variants []ArtistVariant `json:"variants,omitempty"`
Albums []Album `json:"albums,omitempty"`
}
Artist is a canonical artist.
type ArtistVariant ¶
type ArtistVariant struct {
ID string `json:"id"`
Provider string `json:"provider"`
ProviderArtistID string `json:"providerArtistId"`
Name string `json:"name"`
}
ArtistVariant is one provider's page for a canonical artist.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the client-side media cache. It keeps renditions on disk, remembers what it has in an index file, and never downloads the same variant twice. Each room member uses its own cached or downloaded rendition.
func (*Cache) Entries ¶
func (c *Cache) Entries() []CacheEntry
Entries lists everything the cache holds.
func (*Cache) Fetch ¶
Fetch makes sure a variant is on disk and returns its entry. Concurrent calls for the same variant share one download: two transfers of one rendition would otherwise race onto the same temp path and could rename a half-written file into place as if it were the whole thing.
func (*Cache) Lookup ¶
func (c *Cache) Lookup(variantID string) (CacheEntry, bool)
Lookup returns the entry for a variant if its file is still present.
func (*Cache) LookupTrack ¶
func (c *Cache) LookupTrack(trackID string) (CacheEntry, bool)
LookupTrack returns a cached rendition of a track, if there is one. The track index answers in one step, and the file is checked outside the lock so a stat cannot hold up a download or an index write.
func (*Cache) Put ¶
func (c *Cache) Put(entry CacheEntry) error
Put indexes a file the caller already has (for example after importing a local file), so it is never downloaded again.
type CacheEntry ¶
type CacheEntry struct {
VariantID string `json:"variantId"`
TrackID string `json:"trackId"`
Path string `json:"path"`
DurationMs int64 `json:"durationMs"`
SHA256 string `json:"sha256,omitempty"`
Bytes int64 `json:"bytes,omitempty"`
DownloadedAt time.Time `json:"downloadedAt"`
}
CacheEntry is one cached rendition.
type Capabilities ¶
Capabilities describes what a provider can do.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one MusOak server.
func New ¶
New returns a client for a server, e.g. "http://localhost:4420".
func (*Client) AddFavorite ¶
AddFavorite favorites a track with a decimal rating (0.1 to 5.0).
func (*Client) AddPlaylistTracks ¶
func (c *Client) AddPlaylistTracks(ctx context.Context, playlistID string, trackIDs ...string) (*PlaylistDetail, error)
AddPlaylistTracks appends tracks to a playlist.
func (*Client) ClockOffset ¶
ClockOffset estimates the offset between the server clock and this machine's clock: add it to a local millisecond timestamp to get server time.
It takes NTP-style samples over the event socket and keeps the one with the lowest round trip, because that is the sample with the least network noise.
func (*Client) CreatePlaylist ¶
CreatePlaylist makes an empty playlist.
func (*Client) CreateRoom ¶
CreateRoom opens a room; the caller becomes its host.
func (*Client) DeletePlaylist ¶
DeletePlaylist removes a playlist.
func (*Client) DownloadMedia ¶
DownloadMedia writes a ready variant's audio to w.
func (*Client) Events ¶
Events subscribes to room events; pass an empty roomID for every room. The channel closes when ctx ends or the connection drops.
func (*Client) ImportPath ¶
ImportPath adds one local file to the library.
func (*Client) MediaStatus ¶
MediaStatus reports a variant's download progress.
func (*Client) MediaURL ¶
MediaURL is the URL a variant's stored file is served from, the same URL the media GET uses. A player that speaks HTTP (mpv does) can be handed it directly. The server answers only for a rendition it has finished storing: for one it has not, the request is refused and the caller must download it first (Cache.Fetch does that).
startMs, when positive, asks the file to be served from that far into the track: a listener joining a song already under way hears the rest of it rather than its head. Zero is the whole file from the beginning.
func (*Client) PlaylistByName ¶
PlaylistByName resolves a playlist by name; it reports the candidates when the name is ambiguous.
func (*Client) PlaylistFromAlbum ¶
func (c *Client) PlaylistFromAlbum(ctx context.Context, albumID, name string) (*PlaylistDetail, error)
PlaylistFromAlbum stores an album's tracklist as a new playlist.
func (*Client) Radio ¶
func (c *Client) Radio(ctx context.Context, seedTrackID string, opts RadioOptions) (*RadioResult, error)
Radio starts a station from a seed track, mixing the providers it names.
func (*Client) RemoveFavorite ¶
RemoveFavorite removes a track from the caller's favorites.
func (*Client) RemovePlaylistItem ¶
func (c *Client) RemovePlaylistItem(ctx context.Context, playlistID string, position int) (*PlaylistDetail, error)
RemovePlaylistItem drops the entry at a position.
func (*Client) RenamePlaylist ¶
RenamePlaylist changes a playlist's name.
func (*Client) ReorderPlaylist ¶
func (c *Client) ReorderPlaylist(ctx context.Context, playlistID string, order []int) (*PlaylistDetail, error)
ReorderPlaylist applies a new order, given as the current positions.
func (*Client) ResolveTrack ¶
ResolveTrack makes sure a track has a downloadable variant, matching one from a downloadable provider when it only has metadata-only renditions. The bool reports whether the track is now playable.
func (*Client) SearchAlbums ¶
func (c *Client) SearchAlbums(ctx context.Context, query string, limit int) ([]Album, []ProviderError, error)
SearchAlbums searches every provider that can browse albums.
func (*Client) SearchArtists ¶
func (c *Client) SearchArtists(ctx context.Context, query string, limit int) ([]Artist, []ProviderError, error)
SearchArtists searches every provider that can browse artists.
func (*Client) SetMemberID ¶
SetMemberID replaces the guest room member id.
func (*Client) SetRanking ¶
SetRanking replaces the caller's provider order.
func (*Client) StartDownload ¶
StartDownload asks the server to prepare a variant. It returns immediately; call MediaStatus or WaitForMedia to follow progress.
func (*Client) StartDownloadAndWait ¶
StartDownloadAndWait asks the server to prepare a variant and blocks until it is ready, failed or ctx ends.
func (*Client) SyncAlbum ¶
func (c *Client) SyncAlbum(ctx context.Context, albumID string, opts SyncOptions) (*SyncResult, error)
SyncAlbum pulls an album's provider tracklists into the library.
func (*Client) SyncArtist ¶
func (c *Client) SyncArtist(ctx context.Context, artistID string, opts SyncOptions) (*SyncResult, error)
SyncArtist records an artist's provider pages and pulls their albums.
func (*Client) TrackVariants ¶
TrackVariants lists every rendition of a track.
func (*Client) WaitForMedia ¶
WaitForMedia polls until the variant is ready or failed.
type ClockSample ¶
ClockSample is one ping round trip.
type Event ¶
type Event struct {
Type string `json:"type"`
RoomID string `json:"roomId,omitempty"`
Seq int64 `json:"seq,omitempty"`
AtMs int64 `json:"atMs,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
Event is one message from the room event stream. Seq is per-room: a gap in it means events were missed, and the snapshot is the way back.
func (Event) DecodeData ¶
DecodeData decodes the event payload into v.
type HostChangedEvent ¶
HostChangedEvent is the payload of host_changed.
type ImportResult ¶
type ImportResult struct {
Imported []Imported `json:"imported"`
Failures []string `json:"failures,omitempty"`
}
ImportResult reports what a library import did.
type Me ¶
type Me struct {
Authenticated bool `json:"authenticated"`
Guest bool `json:"guest"`
User *User `json:"user,omitempty"`
RequireLogin bool `json:"requireLogin"`
RegistrationOpen bool `json:"registrationOpen"`
}
Me describes the caller.
type MediaStatus ¶
type MediaStatus struct {
VariantID string `json:"variantId"`
State string `json:"state"`
// Stage is what the download is doing right now, one of the Media stages,
// and empty when nothing is running.
Stage string `json:"stage,omitempty"`
// Progress is the fraction of the current stage that is done, and -1 when
// there is nothing to count: a length the provider never reported, or a
// stage with no bytes. A -1 is a caller's cue to show the stage's own
// numbers instead of a percentage.
Progress float64 `json:"progress"`
Error string `json:"error,omitempty"`
// DurationMs is the finished rendition's length, once it is known.
DurationMs int64 `json:"durationMs,omitempty"`
// Bytes and TotalBytes are the current stage's own numbers: bytes for the
// download stage, milliseconds for the conversion. TotalBytes <= 0 means
// unknown.
Bytes int64 `json:"bytes,omitempty"`
TotalBytes int64 `json:"totalBytes,omitempty"`
}
MediaStatus is a variant's download state.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient replaces the underlying HTTP client; media transfers need an http.Client without a short timeout.
func WithMemberID ¶
WithMemberID sets the room member id used as a guest.
type Participant ¶
type Participant struct {
OnEvent func(Event)
OnTrack func(SinkTrack)
// contains filtered or unexported fields
}
Participant follows a room on behalf of one member. The server is the room's clock: this client plays the room's current song, corrects itself to the room's position when it drifts more than two seconds, and advances to the next song on its own when its own file ends. It never reports a position; the server's once-a-second state is only ever a correction.
func NewParticipant ¶
func NewParticipant(room *RoomClient, cache *Cache, sink Sink, logger *slog.Logger) *Participant
NewParticipant returns a participant for a room.
func (*Participant) ClockOffset ¶
func (p *Participant) ClockOffset() time.Duration
ClockOffset is the current estimate of (server clock - local clock).
func (*Participant) LocalPosition ¶
func (p *Participant) LocalPosition(ctx context.Context) (int64, bool)
LocalPosition reports where this client's own player is in the song, when its sink can say so.
func (*Participant) MemberID ¶
func (p *Participant) MemberID() string
MemberID is who this participant is in the room.
func (*Participant) Position ¶
func (p *Participant) Position() int64
Position reports where the room should be right now, on the server clock.
func (*Participant) Room ¶
func (p *Participant) Room() *RoomClient
Room exposes the room client this participant follows.
func (*Participant) Run ¶
func (p *Participant) Run(ctx context.Context) error
Run follows the room until ctx ends, the room closes, or the connection to it drops.
func (*Participant) SetDriftTolerance ¶
func (p *Participant) SetDriftTolerance(ms int64)
SetDriftTolerance sets how far this client may sit from the room's position before it seeks back, in milliseconds.
It belongs to the caller's pipeline: a client that keeps a second of audio buffered ahead of the wire is a second behind by design, and correcting that is correcting the buffer, not the playback. A caller that buffers should set this past its buffer - otherwise every beat is a correction.
func (*Participant) StopPlayback ¶
func (p *Participant) StopPlayback(ctx context.Context) error
StopPlayback stops this client's audio without leaving the room.
type PlaybackEvent ¶
type PlaybackEvent struct {
Current *RoomPlayback `json:"current"`
}
PlaybackEvent is the payload of playback: the whole current state, or a null current when the room has nothing playing.
type Playlist ¶
type Playlist struct {
ID string `json:"id"`
Name string `json:"name"`
TrackCount int `json:"trackCount"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Playlist is one of the caller's playlists.
type PlaylistDetail ¶
type PlaylistDetail struct {
Playlist
Items []PlaylistItem `json:"items"`
}
PlaylistDetail is a playlist with its tracks.
type PlaylistItem ¶
PlaylistItem is one entry of a playlist.
type Positioner ¶
Positioner reports the local playhead for drift correction against the room's position.
type Provider ¶
type Provider struct {
Name string `json:"name"`
Capabilities Capabilities `json:"capabilities"`
MissingDeps []string `json:"missingDeps,omitempty"`
}
Provider is one configured music source.
type ProviderError ¶
ProviderError reports one provider's failure during a search.
type QueueEvent ¶
type QueueEvent struct {
MemberID string `json:"memberId"`
MemberQueue []QueueItem `json:"memberQueue"`
Gone bool `json:"gone"`
// Master is the room's play order after the change. The server is its only
// author, so a follower can take it as it comes; nil means an older server
// that leaves the order to be derived or refetched.
Master []QueueItem `json:"master,omitempty"`
}
QueueEvent is the payload of queue_updated: one member's queue, or notice that they left and their queue is gone.
type QueueItem ¶
type QueueItem struct {
ID string `json:"id"`
TrackID string `json:"trackId"`
Title string `json:"title"`
AddedBy string `json:"addedBy"`
AddedAtMs int64 `json:"addedAtMs"`
DurationMs int64 `json:"durationMs,omitempty"`
ArtworkURL string `json:"artworkUrl,omitempty"`
ArtistIDs []string `json:"artistIds,omitempty"`
// Artists is the names in credit order, the same "artists" a track
// response carries: the row shows them under the title.
Artists []string `json:"artists,omitempty"`
}
QueueItem is one entry of a room's queue.
type RadioOptions ¶
type RadioOptions struct {
// Providers selects what the station is made of; empty means every enabled
// provider that can build one.
Providers []string
// Length is how many tracks the station should hold; zero means the
// server's default.
Length int
// Save stores the station as a playlist. It is a pointer so that "unset"
// (the server default: save) is distinguishable from an explicit false.
Save *bool
// Name overrides the playlist name.
Name string
}
RadioOptions tunes a station.
type RadioResult ¶
type RadioResult struct {
Seed Track `json:"seed"`
Providers []string `json:"providers"`
Tracks []Track `json:"tracks"`
ProviderErrors []ProviderError `json:"providerErrors,omitempty"`
// Playlist is set when the station was saved.
Playlist *Playlist `json:"playlist,omitempty"`
}
RadioResult is a generated station.
type Ranking ¶
type Ranking struct {
Ranking []string `json:"ranking"`
Effective []string `json:"effective"`
Aggregate []string `json:"aggregate"`
Default []string `json:"default"`
}
Ranking is a user's provider order with the aggregate and default around it.
type Room ¶
type Room struct {
ID string `json:"id"`
Name string `json:"name"`
Host string `json:"host"`
Controls string `json:"controls"`
CreatedAtMs int64 `json:"createdAtMs"`
Members []RoomMember `json:"members"`
MemberCount int `json:"memberCount"`
Queues map[string][]QueueItem `json:"queues"`
MasterQueue []QueueItem `json:"masterQueue"`
Current *RoomPlayback `json:"current,omitempty"`
ServerNowMs int64 `json:"serverNowMs"`
Seq int64 `json:"seq"`
Skip RoomSkipRules `json:"skip"`
}
type RoomClient ¶
RoomClient is a room seen through this client's membership.
func (*RoomClient) Client ¶
func (r *RoomClient) Client() *Client
Client exposes the underlying client (for auth state and media helpers).
func (*RoomClient) Events ¶
func (r *RoomClient) Events(ctx context.Context) (<-chan Event, error)
Events subscribes to this room's event stream.
func (*RoomClient) Leave ¶
func (r *RoomClient) Leave(ctx context.Context) error
Leave removes this member from the room.
func (*RoomClient) Pause ¶
func (r *RoomClient) Pause(ctx context.Context) (*Room, error)
Pause freezes the room.
func (*RoomClient) QueueMany ¶
QueueMany appends a run of tracks as one edit: a playlist added to a room is one change, not one per song. Each song on its own is a round trip that answers with the whole room, so a run of them is a run of whole rooms.
func (*RoomClient) Resume ¶
func (r *RoomClient) Resume(ctx context.Context) (*Room, error)
Resume continues a paused room.
func (*RoomClient) Seek ¶
Seek moves the room position; clients correct their drift with small seeks.
func (*RoomClient) Skip ¶
func (r *RoomClient) Skip(ctx context.Context) (*Room, error)
Skip advances past the current track.
type RoomMember ¶
type RoomMember struct {
ID string `json:"id"`
UserID string `json:"userId,omitempty"`
Name string `json:"name"`
JoinedAtMs int64 `json:"joinedAtMs"`
IconURL string `json:"iconUrl,omitempty"`
IconVersion int `json:"iconVersion,omitempty"`
}
RoomMember is one participant in a room. UserID is empty for guests.
type RoomPlayback ¶
type RoomPlayback struct {
Item QueueItem `json:"item"`
PositionMs int64 `json:"positionMs"`
AtMs int64 `json:"atMs"`
Started bool `json:"started"`
Paused bool `json:"paused"`
DurationMs int64 `json:"durationMs"`
Votes map[string]float64 `json:"votes"`
MeanScore float64 `json:"meanScore"`
}
RoomPlayback is the room's current song and where the server says it is. PositionMs is at AtMs on the server clock, so a client can extrapolate between the once-a-second updates.
func (*RoomPlayback) PositionAt ¶
func (p *RoomPlayback) PositionAt(serverNowMs int64) int64
PositionAt is where the room should be at serverNowMs.
type RoomSkipRules ¶
type RoomSkipRules struct {
SkipThreshold float64 `json:"skipThreshold"`
MinVotersForSkip int `json:"minVotersForSkip"`
VoterFractionForSkip float64 `json:"voterFractionForSkip"`
}
RoomSkipRules are the tunables shown next to the vote buttons.
type SearchGroup ¶
SearchGroup is a canonical track with the variants that matched onto it.
type SearchResult ¶
type SearchResult struct {
Query string `json:"query"`
Groups []SearchGroup `json:"groups"`
ProviderErrors []ProviderError `json:"providerErrors,omitempty"`
}
SearchResult is a merged fan-out search.
type Sink ¶
type Sink interface {
// Play starts the file the track names and returns when it finishes or ctx
// ends. What is handed over is always a file on this machine: a rendition
// the server has not stored is fetched first, never played from the provider.
// The participant advances to the next song itself when Play returns.
Play(ctx context.Context, track SinkTrack) error
Stop(ctx context.Context) error
}
Sink plays a file. The CLI's sink drives a local player; a Discord bot's sink pushes the file into a voice channel. Nothing in this package cares which.
type SinkTrack ¶
type SinkTrack struct {
TrackID string
VariantID string
// Title is the song's name, for a sink that says what it is playing.
Title string
// Path is the file on disk to play.
Path string
// DurationMs is the song's length: the file's own once it is here, and the
// length the room reports when the file's own is still unknown.
DurationMs int64
// PositionMs is where in the song playback should begin; a sink seeks there.
PositionMs int64
}
SinkTrack is one rendition handed to a Sink: a file this client holds.
type SyncOptions ¶
type SyncOptions struct {
// Providers selects what to sync from; empty means every known release.
Providers []string
// Resolve also makes sure each track has something playable.
Resolve bool
// SyncAlbums (artist syncs) fetches each album's tracklist too.
SyncAlbums bool
}
SyncOptions tunes a collection sync.
type SyncResult ¶
type SyncResult struct {
AlbumID string `json:"albumId,omitempty"`
ArtistID string `json:"artistId,omitempty"`
Providers []string `json:"providers"`
Added int `json:"added"`
Tracks []Track `json:"tracks,omitempty"`
Albums []Album `json:"albums,omitempty"`
ProviderErrors []ProviderError `json:"providerErrors,omitempty"`
}
SyncResult reports what a sync added.
type Track ¶
type Track struct {
ID string `json:"id"`
Title string `json:"title"`
DurationMs int64 `json:"durationMs"`
Artists []string `json:"artists"`
Albums []string `json:"albums"`
CreatedAt time.Time `json:"createdAt"`
Rating float64 `json:"rating"`
}
Track is a canonical song.
type Variant ¶
type Variant struct {
ID string `json:"id"`
TrackID string `json:"trackId"`
Provider string `json:"provider"`
ProviderTrackID string `json:"providerTrackId"`
Title string `json:"title"`
Artists []string `json:"artists"`
Album string `json:"album"`
DurationMs int64 `json:"durationMs"`
Downloadable bool `json:"downloadable"`
ISRC string `json:"isrc,omitempty"`
// Slot is the account-order position this rendition fills when it is not a
// provider's own: "self" for the caller's upload, "uploaded" for somebody
// else's. Empty for a provider rendition, whose position is its provider.
Slot string `json:"slot,omitempty"`
Media MediaStatus `json:"media"`
}
Variant is one provider's rendition of a track.