Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

json - Get HTTP MP3 stream from every song

I need to get the direct URL from a SoundCloud MP3 file.

I normally used the following method: Resolve the track URL to get the track id, e.g. using https://soundcloud.com/linkin_park/burn-it-down with

http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/your/link/to/the/track&client_id=client_id

Then go for the stream_urls with

http://api.sndcdn.com/i1/tracks/track_id_here/streams?client_id=client_id

In most cases, the "http_128_mp3_url", the URL I need, is returned, which links directly to the MP3 of the song.

But in some cases, e.g. when you use https://soundcloud.com/dada-life/dada-life-september-2014-mix, only the rtmp or hls stream is returned, which I cannot convert to a file with PHP or JavaScript.

As seen on http://sounddrain.com/, there is a way to get the link for the MP3 file in this case too.

Sounddrain gives me this URL:

https://ec-media.sndcdn.com/KZ5qiLqZ0OSk.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522029c6df9ba3f0cf21c0c0d9baf9fe2d9aa920d344c36db47817ce450103d44677da7d832da82ef7609816e

Has someone an idea how to get the following URL?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think this specifically has to do with the type of client_id you pass into the API request.

HTTP GET: http://api.soundcloud.com/i1/tracks/167132129/streams?client_id=[CLIENT_ID]

Using a standard application client_id, I don't see the http link:

Response:

{
  "hls_mp3_128_url": "https://ec-hls-media.soundcloud.com/playlist/KZ5qiLqZ0OSk.128.mp3/playlist.m3u8?f10880d39085a94a0418a7e062b03d52bbdc0e179b82bde1d76ce7a51e4e690d4aa9adbb8e264aa259bfba6e1a3d52e8f8020eeb45fac9d9fbb175e4c35dbd26bdf59ac00d0f2cd80b7e7a685e9cd57c89622a7cc8b7266f4b7317b4",
  "rtmp_mp3_128_url": "rtmp://ec-rtmp-media.soundcloud.com/mp3:KZ5qiLqZ0OSk.128?9527d18f1063a01f059bf10590159adb10dea0996b8c0cdb674f9c282214839d8263f0608a1a3bbe02e4a0ffc5cf5bef80087ca63aa316e338f6cbba24b1493d8355aea84dc2e529757f72273e1fdfc9f88437c992e92845b3e3",
  "preview_mp3_128_url": "https://ec-preview-media.sndcdn.com/preview/0/90/KZ5qiLqZ0OSk.128.mp3?f10880d39085a94a0418a7e162b03d52e21adf826af17a391e1b741835259dfd645b4f9f979acc1e4d50dd281c2b93dca58d9e3bd086be0aed9c5ae0ae369364f50bd63ee4f1b167cc29b19cf3462f735b8f"
}

However, using the youtube-dl iPhone client_id, the http url is returned:

Response:

{
    "http_mp3_128_url": "https://ec-media.sndcdn.com/KZ5qiLqZ0OSk.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522029c69f0bd356988380857d739f55360e9ce802160a1ecf506cfa53f249070d96b19de5ac3234cdbd4201d",
    "hls_mp3_128_url": "https://ec-hls-media.soundcloud.com/playlist/KZ5qiLqZ0OSk.128.mp3/playlist.m3u8?f10880d39085a94a0418a7e062b03d52bbdc0e179b82bde1d76ce7a51e4e6e074a18d603fc2146725c4f70a8844d81268632e8339ce8b52aab8fcfbfd450330b409e8614da1996b8e4cd371f07c9eb0d5cc65ffbf60230336388b323",
    "rtmp_mp3_128_url": "rtmp://ec-rtmp-media.soundcloud.com/mp3:KZ5qiLqZ0OSk.128?9527d18f1063a01f059bf10590159adb10dea0996b8c0cdb674f9c28221b8a972788cc587dee254b285c2a0c9e5b57a79b4bd174401f92b31df0cf4260d9f3f6fe542e181d30b4e9314ac36e70737095ddb2b215bd98884660cb",
    "preview_mp3_128_url": "https://ec-preview-media.sndcdn.com/preview/0/90/KZ5qiLqZ0OSk.128.mp3?f10880d39085a94a0418a7e162b03d52e21adf826af17a391e1b7418352a94f7cbd4ec4b06d76ae6caf6f3cc29aed3f7b0922885d994c71a503c307cf86b653b3f6108990bebaae5a15efc74075285b13f23"
}

More information can be found in this commit and this issue on the youtube-dl page. I don't know exactly what the difference is between a regular client_id and an iPhone client_id, but I can clearly see the difference in what is returned by the API request. It would appear that the iPhone client_id is the API key used by the SoundCloud iOS client to stream tracks in the app.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...