+
+ # We have to retrieve the url
+ streams_url = ('http://api.soundcloud.com/i1/tracks/{0}/streams?'
+ 'client_id={1}&secret_token={2}'.format(track_id, self._IPHONE_CLIENT_ID, secret_token))
+ format_dict = self._download_json(
+ streams_url,
+ track_id, 'Downloading track url')
+
+ for key, stream_url in format_dict.items():
+ if key.startswith('http'):
+ formats.append({
+ 'format_id': key,
+ 'ext': ext,
+ 'url': stream_url,
+ 'vcodec': 'none',
+ })
+ elif key.startswith('rtmp'):
+ # The url doesn't have an rtmp app, we have to extract the playpath
+ url, path = stream_url.split('mp3:', 1)
+ formats.append({
+ 'format_id': key,
+ 'url': url,
+ 'play_path': 'mp3:' + path,
+ 'ext': ext,
+ 'vcodec': 'none',
+ })
+
+ if not formats:
+ # We fallback to the stream_url in the original info, this
+ # cannot be always used, sometimes it can give an HTTP 404 error
+ formats.append({
+ 'format_id': 'fallback',
+ 'url': info['stream_url'] + '?client_id=' + self._CLIENT_ID,
+ 'ext': ext,
+ 'vcodec': 'none',
+ })
+
+ for f in formats:
+ if f['format_id'].startswith('http'):
+ f['protocol'] = 'http'
+ if f['format_id'].startswith('rtmp'):
+ f['protocol'] = 'rtmp'
+
+ self._sort_formats(formats)
+ result['formats'] = formats
+