有一个属性" streamable"如果" false",我无法获得该曲目的stream_url。
但是我看到很少有下载者能够获得同一首歌曲的流媒体&然后得到该曲目的cdn链接。
我甚至对我的应用进行了身份验证,但没有找到stream_url的运气。这就是我所做的。
import soundcloud
# create client object with app credentials
client = soundcloud.Client(client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
redirect_uri='REDIRECT_URL')
# exchange authorization code for access token
code = params['code']
access_token = client.exchange_token(code)
#'YOUR_ACCESS_TOKEN' is access_token which I got in above step.
client = soundcloud.Client(access_token='YOUR_ACCESS_TOKEN')
track = client.get('/tracks/161730338')
以下是跟踪对象
>track.__dict__
{'obj': {u'attachments_uri': u'https://api.soundcloud.com/tracks/161730338/attachments', u'video_url': None, u'track_type': None, u'release_month': None, u'original_format': u'wav', u'label_name': None, u'duration': 198443, u'id': 161730338, u'streamable': False, u'user_id': 14090772, u'user_favorite': False, u'title': u'Jessie J + Ariana Grande + Nicki Minaj - Bang Bang', u'favoritings_count': 94563, u'commentable': True, u'label_id': None, u'state': u'finished', u'downloadable': False, u'policy': u'ALLOW', u'waveform_url': u'https://w1.sndcdn.com/EDiPRlpWkJ2V_m.png', u'sharing': u'public', u'description': u'', u'release_day': None, u'purchase_url': None, u'permalink': u'jessie-j-ariana-grande-nicki-minaj-bang-bang', u'comment_count': 957, u'purchase_title': None, u'last_modified': u'2015/03/25 04:05:16 +0000', u'user': {u'username': u'RepublicRecords', u'permalink': u'universalrepublic', u'avatar_url': u'https://i1.sndcdn.com/avatars-000025014448-peqymq-large.jpg', u'kind': u'user', u'uri': u'https://api.soundcloud.com/users/14090772', u'last_modified': u'2014/11/10 20:57:55 +0000', u'permalink_url': u'http://soundcloud.com/universalrepublic', u'id': 14090772}, u'genre': u'playbook', u'isrc': None, u'download_count': 0, u'permalink_url': u'http://soundcloud.com/universalrepublic/jessie-j-ariana-grande-nicki-minaj-bang-bang', u'playback_count': 4883398, u'kind': u'track', u'release_year': None, u'license': u'all-rights-reserved', u'artwork_url': None, u'created_at': u'2014/08/05 00:19:41 +0000', u'bpm': None, u'uri': u'https://api.soundcloud.com/tracks/161730338', u'original_content_size': 34992416, u'key_signature': None, u'user_playback_count': 1, u'release': None, u'tag_list': u'', u'embeddable_by': u'all'}, 'encoding': 'utf-8', 'url': u'https://api.soundcloud.com/tracks/161730338.json?oauth_token=1-124233-146384181-db7bf19453bd8', 'raw_data': u'{"kind":"track","id":161730338,"created_at":"2014/08/05 00:19:41 +0000","user_id":14090772,"duration":198443,"commentable":true,"state":"finished","original_content_size":34992416,"last_modified":"2015/03/25 04:05:16 +0000","sharing":"public","tag_list":"","permalink":"jessie-j-ariana-grande-nicki-minaj-bang-bang","streamable":false,"embeddable_by":"all","downloadable":false,"purchase_url":null,"label_id":null,"purchase_title":null,"genre":"playbook","title":"Jessie J + Ariana Grande + Nicki Minaj - Bang Bang","description":"","label_name":null,"release":null,"track_type":null,"key_signature":null,"isrc":null,"video_url":null,"bpm":null,"release_year":null,"release_month":null,"release_day":null,"original_format":"wav","license":"all-rights-reserved","uri":"https://api.soundcloud.com/tracks/161730338","user":{"id":14090772,"kind":"user","permalink":"universalrepublic","username":"RepublicRecords","last_modified":"2014/11/10 20:57:55 +0000","uri":"https://api.soundcloud.com/users/14090772","permalink_url":"http://soundcloud.com/universalrepublic","avatar_url":"https://i1.sndcdn.com/avatars-000025014448-peqymq-large.jpg"},"user_playback_count":1,"user_favorite":false,"permalink_url":"http://soundcloud.com/universalrepublic/jessie-j-ariana-grande-nicki-minaj-bang-bang","artwork_url":null,"waveform_url":"https://w1.sndcdn.com/EDiPRlpWkJ2V_m.png","playback_count":4883398,"download_count":0,"favoritings_count":94563,"comment_count":957,"attachments_uri":"https://api.soundcloud.com/tracks/161730338/attachments","policy":"ALLOW"}', 'reason': 'OK', 'status_code': 200}
根据文档,我应该从
获取stream_url# get the tracks streaming URL
stream_url = client.get(track.stream_url, allow_redirects=False)
# print the tracks stream URL
print stream_url.location
我从4天开始就被困在这里。有没有办法获得MP3曲目的最终cdn链接或这些soundclouddownlaoder如何做到这一点。
答案 0 :(得分:0)
如果stream_url
键返回空值,我发现streams
端点将返回有效的网址。
HTTP GET: https://api.soundcloud.com/tracks/[TRACK_ID]/streams?client_id=[YOUR_CLIENT_ID]
免责声明:这是一个未记录的端点,可随时由SoundCloud进行更改。
HTTP GET: https://api.soundcloud.com/tracks/161730338/streams?client_id=[YOUR_CLIENT_ID]
响应:
{
"hls_mp3_128_url": "https://ec-hls-media.soundcloud.com/playlist/EDiPRlpWkJ2V.128.mp3/playlist.m3u8?f10880d39085a94a0418a7e062b03d52bbdc0e179b82bde1d76ce6ad1a416907458c1576abbf27bccb1984bf2890809c25cb2c95f826eba5858b2322a2cc08c48f3664ebef63724f43e9baa7d819586e497b7175430826823cbebd16",
"rtmp_mp3_128_url": "rtmp://ec-rtmp-media.soundcloud.com/mp3:EDiPRlpWkJ2V.128?9527d18f1063a01f059bf10590159adb10dea0996b8c0cdb674f9d20261b8798a306771c4e0fd691edd62d0b7db08ebc6cc0c5a4837c348c5d07f977a600bc6e3847081fc6ea55a327f8ef9f5f635a99c5921392ed3ec8030f3e",
"preview_mp3_128_url": "https://ec-preview-media.sndcdn.com/preview/0/90/EDiPRlpWkJ2V.128.mp3?f10880d39085a94a0418a7e162b03d52e21adf826af17a391e1b7510312a99f96d1a7322537c26fabab56b86080be7194bc01c2056f9c615253e34d8b61dd76b963654b4c4c58c44dcb70f1176081fc49e3f"
}
preview_mp3_128_url
键值对具有您想要的128kbps流式mp3。
如果preview_mp3_128_url
不是完整曲目,则您需要使用ffmpeg等工具下载HLS传输流
ffmpeg -i "https://ec-hls-media.soundcloud.com/playlist/EDiPRlpWkJ2V.128.mp3/playlist.m3u8?f10880d39085a94a0418a7e062b03d52bbdc0e179b82bde1d76ce6ad1a416907458c1576abbf27bccb1984bf2890809c25cb2c95f826eba5858b2322a2cc08c48f3664ebef63724f43e9baa7d819586e497b7175430826823cbebd16" -c copy test.ts
这将为您提供该曲目的完整mp3文件。
此问题还可以找到其他信息:Get HTTP MP3 stream from every song