Documentation
¶
Index ¶
- func ConvertFirebaseLink(u string) (string, error)
- func ExtractIDFromPersonalizedTrackURL(url string) int64
- func FetchClientID() (string, error)
- func IsFirebaseURL(u string) bool
- func IsMobileURL(u string) bool
- func IsPersonalizedTrackURL(url string) bool
- func IsPlaylistURL(u string) bool
- func IsSearchURL(url string) bool
- func IsURL(url string, testMobile, testFirebase bool) bool
- func StripMobilePrefix(u string) string
- type API
- func (sc *API) ClientID() string
- func (sc *API) DownloadTrack(transcoding Transcoding, dst io.Writer) error
- func (sc *API) GetDownloadURL(url string, streamType string) (string, error)
- func (sc *API) GetTrackInfo(options GetTrackInfoOptions) ([]Track, error)
- func (sc *API) IsURL(url string) bool
- func (sc *API) Search(options SearchOptions) (*PaginatedQuery, error)
- func (sc *API) SetClientID(clientID string)
- type APIOptions
- type DownloadURLResponse
- type FailedRequestError
- type GetLikesOptions
- type GetTrackInfoOptions
- type GetUserOptions
- type Kind
- type Like
- type Media
- type MediaURLResponse
- type PaginatedQuery
- type Playlist
- type SearchOptions
- type Track
- type Transcoding
- type TranscodingFormat
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertFirebaseLink ¶
ConvertFirebaseLink converts a link of the form (https://soundcloud.app.goo.gl/xxxxxxxx) to a regular SoundCloud link.
func ExtractIDFromPersonalizedTrackURL ¶
ExtractIDFromPersonalizedTrackURL extracts the track ID from a personalized track URL, returns -1 if no track ID can be extracted
func FetchClientID ¶
FetchClientID fetches a SoundCloud client ID. This algorithm is adapted from:
https://www.npmjs.com/package/soundcloud-key-fetch
func IsFirebaseURL ¶
IsFirebaseURL returns true if the url is a SoundCloud Firebase url (has the following form: https://soundcloud.app.goo.gl/xxxxxxxx)
func IsMobileURL ¶
IsMobileURL returns true if the url is a SoundCloud Firebase url (has the following form: https://m.soundcloud.com/xxxxxx)
func IsPersonalizedTrackURL ¶
IsPersonalizedTrackURL returns true if the provided url is a valid personalized track url. Ex/ https://soundcloud.com/discover/sets/personalized-tracks::sam:335899198
func IsPlaylistURL ¶
IsPlaylistURL retuns true if the provided url is a valid SoundCloud playlist URL
func IsSearchURL ¶
IsSearchURL returns true if the provided url is a valid search url
func StripMobilePrefix ¶
StripMobilePrefix removes the prefix for mobile urls. Returns the same string if an error parsing the URL occurs
Types ¶
type API ¶
type API struct {
StripMobilePrefix bool
ConvertFirebaseURLs bool
// contains filtered or unexported fields
}
API is a wrapper for the SoundCloud private API used internally for soundcloud.com
func New ¶
func New(options APIOptions) (*API, error)
New returns a pointer to a new SoundCloud API struct.
func (*API) DownloadTrack ¶
func (sc *API) DownloadTrack(transcoding Transcoding, dst io.Writer) error
DownloadTrack downloads the track specified by the given Transcoding's URL to dst
func (*API) GetDownloadURL ¶
GetDownloadURL retuns the URL to download a track. This is useful if you want to implement your own downloading algorithm. If the track has a publicly available download link, that link will be preferred and the streamType parameter will be ignored. streamType can be either "hls" or "progressive", defaults to "progressive"
func (*API) GetTrackInfo ¶
func (sc *API) GetTrackInfo(options GetTrackInfoOptions) ([]Track, error)
GetTrackInfo returns the info for the track given tracks
If URL is supplied, it will return the info for a single track given by that url. If an array of ids is supplied, it will return an array of track info.
WARNING: Private tracks will not be fetched unless options.PlaylistID and options.PlaylistSecretToken are provided.
func (*API) IsURL ¶
IsURL is a shorthand for IsURL(url, sc.StripMobilePrefix, sc.ConvertFirebaseURLs)
func (*API) Search ¶
func (sc *API) Search(options SearchOptions) (*PaginatedQuery, error)
Search returns a PaginatedQuery for searching a specific query
func (*API) SetClientID ¶
SetClientID sets the client ID
type APIOptions ¶
type APIOptions struct {
ClientID string // optional and a new one will be fetched if not provided
HTTPClient *http.Client // the HTTP client to make requests with
StripMobilePrefix bool // whether or not to convert mobile URLs to regular URLs
ConvertFirebaseURLs bool // whether or not to convert SoundCloud firebase URLs to regular URLs
}
APIOptions are the options for creating an API struct
type DownloadURLResponse ¶
type DownloadURLResponse struct {
URL string `json:"redirectUri"`
}
DownloadURLResponse is the JSON respose of retrieving media information of a publicly downloadable track
type FailedRequestError ¶
FailedRequestError is an error response from the SoundCloud API
func (*FailedRequestError) Error ¶
func (f *FailedRequestError) Error() string
type GetLikesOptions ¶
type GetLikesOptions struct {
ProfileURL string // URL to the user's profile (will use this or ID to choose user)
ID int64 // User's ID if you have it
Limit int // How many tracks to return (defaults to 10)
Offset int // How many tracks to offset by (used for pagination; defaults to 0)
Type string // What type of resource to return. One of ["track", "playlist", "all"]. Defaults to "all"
}
GetLikesOptions are the options for getting a user's likes.
type GetTrackInfoOptions ¶
type GetTrackInfoOptions struct {
URL string
ID []int64
PlaylistID int64
PlaylistSecretToken string
}
GetTrackInfoOptions can contain the URL of the track or the ID of the track. PlaylistID and PlaylistSecretToken are necessary to retrieve private tracks in private playlists.
type GetUserOptions ¶
GetUserOptions contains either the profile url of the user or the ID of the user
type Kind ¶
type Kind string
Kind is a string
const KindAlbum Kind = "albums"
KindAlbum is the kind for an album
const KindPlaylist Kind = "playlist"
KindPlaylist is the kind for a playlist
const KindTrack Kind = "tracks"
KindTrack is the kind for a Track
const KindUser Kind = "users"
KindUser is the kind for a user
type Like ¶
type Like struct {
CreatedAt string `json:"created_at"`
Kind string `json:"kind"`
Track Track `json:"track"`
Playlist Playlist `json:"playlist"`
}
Like is the JSON response for a like
type Media ¶
type Media struct {
Transcodings []Transcoding `json:"transcodings"`
}
Media contains an array of transcoding for a track
type MediaURLResponse ¶
type MediaURLResponse struct {
URL string `json:"url"`
}
MediaURLResponse is the JSON response of retrieving media information of a track
type PaginatedQuery ¶
type PaginatedQuery struct {
Collection []map[string]interface{} `json:"collection"`
TotalResults int `json:"total_results"`
NextHref string `json:"next_href"`
QueryURN string `json:"query_urn"`
}
PaginatedQuery is the JSON response for a paginated query
type Playlist ¶
type Playlist struct {
ArtworkURL string `json:"artwork_url"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
DurationMS int64 `json:"duration"`
EmbeddeableBy string `json:"embeddable_by"`
Genre string `json:"genre"`
ID int64 `json:"id"`
Kind string `json:"kind"`
LabelName string `json:"label_name"`
LastModified string `json:"last_modified"`
License string `json:"license"`
LikesCount int `json:"likes_count"`
ManagedByFeeds bool `json:"managed_by_feeds"`
Permalink string `json:"permalink"`
PermalinkURL string `json:"permalink_url"`
Public bool `json:"public"`
SecretToken string `json:"secret_token"`
Sharing string `json:"private"`
TagList string `json:"tag_list"`
Title string `json:"title"`
URI string `json:"uri"`
UserID int64 `json:"user_id"`
SetType string `json:"set_type"`
IsAlbum bool `json:"is_album"`
PublishedAt string `json:"published_at"`
DisplayDate string `json:"display_date"`
User User `json:"user"`
Tracks []Track `json:"tracks"`
TrackCount int `json:"track_count"`
}
Playlist represents the JSON response of a playlist
type SearchOptions ¶
type SearchOptions struct {
// This is the NextHref property of PaginatedQuery structs
QueryURL string
Query string
// Number of items to return
Limit int
// Number of items to offset by (for pagination)
Offset int
// The type of item to return
Kind Kind
}
SearchOptions are the parameters for executing a search
type Track ¶
type Track struct {
ArtworkURL string `json:"artwork_url"`
CommentCount int64 `json:"comment_count"`
Commentable bool `json:"commentable"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
DisplayDate string `json:"display_date"`
DownloadCount int64 `json:"download_count"`
Downloadable bool `json:"downloadable"`
DurationMS int64 `json:"duration"`
FullDurationMS int64 `json:"full_duration"`
Genre string `json:"genre"`
HasDownloadsLeft bool `json:"has_downloads_left"`
ID int64 `json:"id"`
Kind string `json:"kind"`
LabelName string `json:"label_name"`
LastModified string `json:"last_modified"`
LikesCount int64 `json:"likes_count"`
Media Media `json:"media"`
MonetizationModel string `json:"monetization_model"`
Permalink string `json:"permalink"`
PermalinkURL string `json:"permalink_url"`
PlaybackCount int64 `json:"playback_count"`
Policy string `json:"polic"`
Public bool `json:"public"`
RepostsCount int64 `json:"reposts_count"`
SecretToken string `json:"secret_token"`
Streamable bool `json:"streamable"`
TagList string `json:"tag_list"`
Title string `json:"title"`
URI string `json:"uri"`
User User `json:"user"`
UserID int64 `json:"user_id"`
WaveformURL string `json:"waveform_url"`
}
Track represents the JSON response of a track's info
type Transcoding ¶
type Transcoding struct {
URL string `json:"url"`
Preset string `json:"preset"`
Snipped bool `json:"snipped"`
Format TranscodingFormat `json:"format"`
}
Transcoding contains information about the transcoding of a track
type TranscodingFormat ¶
type TranscodingFormat struct {
Protocol string `json:"protocol"`
MimeType string `json:"mime_type"`
}
TranscodingFormat contains the protocol by which the track is delivered ("progressive" or "HLS"), and the mime type of the track
type User ¶
type User struct {
ID int64 `json:"id"`
AvatarURL string `json:"avatar_url"`
City string `json:"city"`
CommentsCount int64 `json:"comments_count"`
CountryCode string `json:"country_code"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
FollowersCount int64 `json:"followers_count"`
FollowingsCount int64 `json:"followings_count"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
PermalinkURL string `json:"permalink_url"`
URI string `json:"uri"`
Username string `json:"username"`
Kind string `json:"kind"`
Likes int `json:"likes_count"`
PlaylistLikes int `json:"playlist_likes_count"`
Verified bool `json:"verified"`
}
User represents the JSON payload for user data