javascript soundcloud 如何隐藏流媒体音频的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17892702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How has soundcloud hidden the URL of streaming audio
提问by Jacob Windsor
I am trying to hide the URL of my audio streams for my HTML5 player and was really struggling to think of a way to do so and then I realised, soundcloud must hide the URL's of their streams. So i went onto soundcloud, opened up the console and played a track but I couldn't see any obvious way that the URL is hidden. After this I took a look at the DOM tree to see if there was any kind of audio information in there but I found nothing! There's not even an ID for the player/audio so i'm very confused as to how soundcloud have done it.
我试图为我的 HTML5 播放器隐藏我的音频流的 URL,并且真的很难想出一种方法来这样做,然后我意识到,soundcloud 必须隐藏他们的流的 URL。所以我进入了 soundcloud,打开了控制台并播放了一首曲目,但我看不到任何明显的隐藏 URL 的方式。在此之后,我查看了 DOM 树,看看那里是否有任何类型的音频信息,但我什么也没找到!甚至没有播放器/音频的 ID,所以我对 soundcloud 是如何做到的感到非常困惑。
Now I have done as best as I can so far with hiding the audio URL. I have put an ID in the DOM for the track, got that ID when the play button is clicked and retrieved the URL for that ID from the database. The obvious problem with that is that anyone willing enough can just go to the console and get the URL from the network events.
现在我已经尽我所能隐藏音频 URL。我已经在 DOM 中为曲目放置了一个 ID,在单击播放按钮时获取了该 ID,并从数据库中检索了该 ID 的 URL。这样做的明显问题是,任何愿意的人都可以进入控制台并从网络事件中获取 URL。
I am not trying to break past soundcloud's security to download tracks I shouldn't be. I'm just curious as to how they've hidden the URL. Now i'm also curious as to how each track is distinguished as there's nothing in the DOM distinguishing them (not that I found on my brief look anyway).
我不是想突破 soundcloud 的安全性来下载我不应该这样做的曲目。我只是好奇他们是如何隐藏 URL 的。现在我也很好奇每个轨道是如何区分的,因为 DOM 中没有任何东西可以区分它们(无论如何我都没有在我的简短观察中发现)。
So, in short, does anyone have any ideas on how soundcloud has achieved this or how this could be achieved?
因此,简而言之,有没有人对 soundcloud 如何实现这一目标或如何实现这一目标有任何想法?
回答by scandinavian_
Soundcloud is pretty much a pure JS site.
Soundcloud 几乎是一个纯 JS 站点。
As you said, there is no ID of the song loaded with the HTML. The way songs are recognized is by the page URL. The is done via. this url (example):
正如您所说,加载了 HTML 的歌曲没有 ID。识别歌曲的方式是通过页面 URL。是通过完成的。这个网址(示例):
https://api.sndcdn.com/resolve?url=https%3A//soundcloud.com/hoodinternet/joywave-tongues-hood-internet-remix&_status_code_map%5B302%5D=200&_status_format=json&client_id=YOUR_CLIENT_ID
https://api.sndcdn.com/resolve?url=https%3A//soundcloud.com/hoodinternet/joywave-tongues-hood-internet-remix&_status_code_map%5B302%5D=200&_status_format=json&client_id=YOUR_CLIENT_ID
This returns something like this:
这将返回如下内容:
{"status":"302 - Found","location":"https://api.soundcloud.com/tracks/100270342?client_id=YOUR_CLIENT_ID"}
{"status":"302 - Found","location":"https://api.soundcloud.com/tracks/100270342?client_id=YOUR_CLIENT_ID"}
Next up it loads the location URL, from the JSON above. This returns a bunch of information about the track, including:
接下来,它从上面的 JSON 加载位置 URL。这将返回一堆关于轨道的信息,包括:
stream_url: "https://api.soundcloud.com/tracks/100270342/stream"
stream_url: "https://api.soundcloud.com/tracks/100270342/stream"
Then it loads this URL:
然后它加载这个 URL:
https://api.sndcdn.com/i1/tracks/100270342/streams?client_id=YOUR_CLIENT_IT
https://api.sndcdn.com/i1/tracks/100270342/streams?client_id=YOUR_CLIENT_IT
Which returns a response like this:
它返回这样的响应:
{"http_mp3_128_url":"https://ec-media.soundcloud.com/2gNVBYiZ06bU.128.mp3?ff61182e3c2ecefa438cd021sdf02d0e385713f0c1faf3b0339595664fe070de810d30a8e3a1186eda958909e9ed97799adfeceabc135efac83aee4271217a108450591db3b88\u0026AWSAccessKeyId=AKIAsdfJ4IAZE5EOIdsf7PA7VQ\u0026Expires=1374883403\u0026Signature=%2B1%2B7dfdfLN4NWP3C3bNF3gizSEVIU%3D"}
{"http_mp3_128_url":"https://ec-media.soundcloud.com/2gNVBYiZ06bU.128.mp3?ff61182e3c2ecefa438cd021sdf02d0e385713f0c1faf3b0339595664fe070de810d30a8e3a1186eda958909e9ed97799adfeceabc135efac83aee4271217a108450591db3b88\u0026AWSAccessKeyId=AKIAsdfJ4IAZE5EOIdsf7PA7VQ\u0026Expires=1374883403\u0026Signature=%2B1%2B7dfdfLN4NWP3C3bNF3gizSEVIU%3D"}
So that's how they hide their stream URL's. The only non obvious part is that they find the song ID, by hitting an API with the URL as a parameter. Same can be done with download URL's on tracks that support it.
这就是他们隐藏流 URL 的方式。唯一不明显的部分是他们通过以 URL 作为参数点击 API 来找到歌曲 ID。同样可以使用支持它的轨道上的下载 URL 来完成。
回答by Trendy
If you goto SoundCloud.com and open up your debugger (Chrome is what I'm using). Look at the "Network" tab and you'll see a script calling audio?anonymous_id#########.
如果您转到 SoundCloud.com 并打开调试器(我使用的是 Chrome)。查看“网络”选项卡,您会看到一个脚本调用 audio?anonymous_id#########。
This is structured like a REST call, meaning they pass an id to a service on their backend, and that returns the audio output anonymously.
它的结构类似于 REST 调用,这意味着它们将 id 传递给后端的服务,并匿名返回音频输出。
回答by Shahab A
They Changed the Media center address and now they are streaming from the link like below.But the access to this url is restricted.
他们更改了媒体中心地址,现在他们正在通过如下链接进行流式传输。但是对该 url 的访问受到限制。