Skip to content

zackradisic/soundcloud-api

Repository files navigation

soundcloud-api

GoDoc

SoundCloud's v2 API reverse engineered for Go.

Notice

The SoundCloud api-v2 is an undocumented, internal API used by the web app at https://soundcloud.com.

SoundCloud is currently not allowing developers to register for applications, and using undocumented APIs is apparently breaking SoundCloud's ToS, use this at your own risk.

Quick Start

// You can specify certain options here if you want
sc, err := soundcloudapi.New(soundcloudapi.APIOptions{}) 

if err != nil {
    log.Fatal(err.Error())
}

track, err := sc.GetTrackInfo(soundcloudapi.GetTrackInfoOptions{
    URL: "https://soundcloud.com/track/infsdfo",
})

See the docs for more reference.

Error Handling

If an error is returned from SoundCloud's API, it will take the form of the FailedRequestError struct. You can use type assertions to access the status code or JSON error msg for your use case. Ex:

tracks, err := sc.GetTrackInfo(soundcloudapi.GetTrackInfoOptions{
    URL: "https://soundcloud.com/asdkfjhalsdhfl",
})

if failedRequest, ok := err.(*soundcloudapi.FailedRequestError); ok {
    if failedRequest.Status == 404 {
        fmt.Println("Could not find that track")
    }
    return
}

Paginated Queries

Functions like sc.Search() or sc.GetLikes() return a PaginatedQuery. PaginatedQuery.Collection contains the JSON of the items that matched the query, represented as a map[string]interface{}. You can use the provided functions to get the items in the form you want:

paginatedQuery, _ := sc.Search(soundcloudapi.SearchOptions{
    Query: "childish gambino"
})

tracks, _ := paginatedQuery.GetTracks() // Get the tracks of the response
playlists, _ := paginatedQuery.GetPlaylists() // Get the playlists of the response
likes, _ := paginatedQuery.GetLikes() // Get the likes of the response