File size: 6,921 Bytes
63e5f15
aa81892
63e5f15
 
aa81892
63e5f15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa81892
63e5f15
aa81892
63e5f15
 
aa81892
63e5f15
4fc4471
63e5f15
 
4fc4471
63e5f15
 
 
 
 
 
 
 
 
 
 
 
 
 
4fc4471
63e5f15
4fc4471
63e5f15
 
aa81892
63e5f15
aa81892
63e5f15
2aa2abc
63e5f15
2aa2abc
63e5f15
 
2aa2abc
63e5f15
4fc4471
63e5f15
4fc4471
63e5f15
4fc4471
63e5f15
 
4fc4471
63e5f15
4fc4471
09c48f9
63e5f15
 
4fc4471
63e5f15
4fc4471
63e5f15
 
4fc4471
63e5f15
4fc4471
63e5f15
2aa2abc
63e5f15
2aa2abc
63e5f15
 
2aa2abc
63e5f15
aa81892
09c48f9
63e5f15
 
 
 
aa81892
63e5f15
aa81892
63e5f15
 
aa81892
63e5f15
aa81892
63e5f15
 
129aefa
63e5f15
 
290b9b9
63e5f15
 
aa81892
 
63e5f15
aa81892
63e5f15
aa81892
63e5f15
aa81892
63e5f15
aa81892
63e5f15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba0f8da
 
 
145258e
ba0f8da
63e5f15
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# API endpoints

<details>
    <summary><h2><code>/_/info</code></h2></summary>

Get details about instance's configuration. Some instances may hide this information, but it's enabled by default. Example response:
```json
{
  "DefaultPreferences": {
    "Player": "restream",
    "ProxyStreams": true,
    "FullyPreloadTrack": false,
    "ProxyImages": true,
    "ParseDescriptions": true,
    "AutoplayNextTrack": false,
    "AutoplayNextRelatedTrack": false,
    "DefaultAutoplayMode": "normal",
    "HLSAudio": "aac",
    "RestreamAudio": "mpeg",
    "DownloadAudio": "mpeg",
    "ShowAudio": false,
    "SearchSuggestions": false,
    "DynamicLoadComments": false,
    "KeepPlayerFocus": false,
    "Waveform": false
  },
  "Commit": "910261d",
  "Repo": "https://git.maid.zone/stuff/soundcloak",
  "ProxyImages": true,
  "ProxyStreams": true,
  "Restream": true,
  "GetWebProfiles": true,
  "EnableAPI": true
}
```

</details>

<details>
    <summary><h2><code>/_/searchSuggestions</code></h2></summary>

Get search suggestions. Query parameters:

* `q`: query to look up
* `format`: set to opensearch if you want it in opensearch JSON format

Example response for `/_/searchSuggestions?q=music`:
```json
[
  "music sounds better with you",
  "music is the answer",
  "musica para dormir",
  "music for soul 6",
  "musica cristiana",
  "musica de amor nunca mais",
  "music for soul 4 -pn ft tdat",
  "musica",
  "music on"
]
```

</details>

<details>
    <summary><h2><code>/_/rss/:user</code></h2></summary>

Generates an [RSS](https://en.wikipedia.org/wiki/RSS) feed for user tracks. Put a username instead of `:user`. Query parameters:

* `proxy_images`: if images should be proxied through instance. Instance must have `ProxyImages` enabled. By default, uses value from preferences

</details>

<details>
    <summary><h2><code>/_/proxy/images</code></h2></summary>

Proxy an image through this instance. Instance must have `ProxyImages` enabled. Query parameters:

* `url`: image URL. Only accepting images from `*.sndcdn.com`

</details>

<details>
    <summary><h2><code>/_/api/hls/:author/:track</code></h2></summary>

Get an [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming) playlist for streaming the track. Query parameters:

* `audio`: force the audio. Can be `aac_hq`, `aac`, `mpeg` or `aac_lq`. By default, uses value from preferences
* `redirect`: if should redirect to playlist on soundcloud's CDN. By default `false`
* `redirect_parts`: if should redirect to the track parts on soundcloud's CDN. If `ProxyStreams` is disabled on server, will be `true` by default, otherwise `false`

</details>

<details>
    <summary><h2><code>/_/api/progressive/:author/:track</code></h2></summary>

Get an MP3 file of the track. Query parameters:

* `redirect`: if should redirect to the MP3 on soundcloud's CDN. If `ProxyStreams` is disabled on server, will be `true` by default, otherwise `false`

</details>

<details>
    <summary><h2><code>/_/api/restream/:author/:track</code></h2></summary>

Get an MP3 or Fragmented M4A file of the track, with metadata injected if needed. Instance must have `Restream` enabled for this to work. Query parameters:

* `audio`: force the audio. Can be `aac_hq`, `aac`, `mpeg` or `aac_lq`. By default, uses value from preferences
* `metadata`: if should inject metadata. By default `false`. Metadata values are taken from track on soundcloud
* `title`: override title in metadata
* `genre`: override genre in metadata
* `author`: override author in metadata

</details>

<details>
    <summary><h2><code>/_/api/v2/...</code></h2></summary>

Proxy for soundcloud's `api-v2.soundcloud.com`. Instance must have `EnableAPI` enabled. Automatically adds latest `client_id` value to your requests, so you don't need to. Only GET requests are allowed, your supplied headers and body get ignored. List of allowed endpoints:

* `/resolve?url=...` (for getting info from url like `https://soundcloud.com/:user/:track`)
* `/charts/selections`
* `/mixed-selections`
* `/users/...`
* `/tracks/...`
* `/search/...`
* `/playlists/...`
* `/featured_tracks/...`


So, for example, request like `https://api-v2.soundcloud.com/users/420953284?client_id=tkIWLs4MIowq7bCXP80TOwx6DnDa7UPc` will be turned into `<instance>/_/api/v2/users/420953284`. For more information about what endpoints there are, you can look at soundcloud's official frontend using devtools or read soundcloak/other tools source code. [Here is a big list of endpoints, extracted from the official frontend code](https://fs.maid.zone/sc_endpoints.json). Also keep in mind that there is no caching on this proxy, please cache things on your own

</details>

# Notes about API

Keep in mind that this is unofficial, using reversed not-public API, probably not compliant with any terms of service that soundcloud have. Soundcloud likes to break things like this once in a while, but I try to keep it working. If you wanna use this for your application, it would be great to host your own soundcloak server, or to spread traffic across the [public](https://maid.zone/soundcloak/instances.html) ones *(maybe you could also support the people running them)*

## Audio streaming

Soundcloud offers [two audio presets](docs/AUDIO_PRESETS.md). There is multiple methods available for streaming audio, each with it's own behavior:

* HLS (`/_/api/hls/:author/:track`)

[HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming) breaks down an audio into multiple smaller files. This let's you load audio parts on demand, instead of start to finish. You can stream both MP3 and AAC audio with this, but you usually need some program/library to handle the streaming. For web, there is [hls.js](https://github.com/video-dev/hls.js). If you use `?redirect=true` option, keep in mind that this playlist link and parts inside it will automatically expire after track duration + 105s. Otherwise, soundcloak automatically handles renewing the audio playlist.

* Progressive (`/_/api/progressive/:author/:track`)

This only lets you stream tracks as mp3 128kb/s file. If you use `?redirect=true` option, keep in mind that this file link will automatically expire after track duration + 105s. Otherwise, soundcloak automatically handles renewing the audio file

* Restream (`/_/api/restream/:author/:track`)

This combines both HLS (automatically converting to regular audio file) and Progressive methods, and also adds metadata injection on the fly.

## Other applications using the API

* [@sndcldbot](https://git.maid.zone/laptop/sndcldbot) - simple inline telegram bot, search for tracks, paste track/playlist/user link to download
* [cloudscape](https://github.com/tijnjh/cloudscape) - minimal ad-free soundcloud client/frontend

## Old API

Currently, it's still all working, but I plan to remove it sometime later, so please migrate everything to the new methods. Also `/_/restream/...` has been redirected to `/_/api/restream/...`