[soundcloud] Always add streaming formats

This commit is contained in:
Philipp Hagemeister 2014-03-24 02:21:17 +01:00
parent 83622b6d2f
commit 5e114e4bfe

View file

@ -124,45 +124,46 @@ class SoundcloudIE(InfoExtractor):
'description': info['description'], 'description': info['description'],
'thumbnail': thumbnail, 'thumbnail': thumbnail,
} }
formats = []
if info.get('downloadable', False): if info.get('downloadable', False):
# We can build a direct link to the song # We can build a direct link to the song
format_url = ( format_url = (
'https://api.soundcloud.com/tracks/{0}/download?client_id={1}'.format( 'https://api.soundcloud.com/tracks/{0}/download?client_id={1}'.format(
track_id, self._CLIENT_ID)) track_id, self._CLIENT_ID))
result['formats'] = [{ formats.append({
'format_id': 'download', 'format_id': 'download',
'ext': info.get('original_format', 'mp3'), 'ext': info.get('original_format', 'mp3'),
'url': format_url, 'url': format_url,
'vcodec': 'none', 'vcodec': 'none',
}] 'preference': 10,
else: })
# 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))
stream_json = self._download_webpage(
streams_url,
track_id, 'Downloading track url')
formats = [] # We have to retrieve the url
format_dict = json.loads(stream_json) streams_url = ('http://api.soundcloud.com/i1/tracks/{0}/streams?'
for key, stream_url in format_dict.items(): 'client_id={1}&secret_token={2}'.format(track_id, self._IPHONE_CLIENT_ID, secret_token))
if key.startswith('http'): stream_json = self._download_webpage(
formats.append({ streams_url,
'format_id': key, track_id, 'Downloading track url')
'ext': ext,
'url': stream_url, format_dict = json.loads(stream_json)
'vcodec': 'none', for key, stream_url in format_dict.items():
}) if key.startswith('http'):
elif key.startswith('rtmp'): formats.append({
# The url doesn't have an rtmp app, we have to extract the playpath 'format_id': key,
url, path = stream_url.split('mp3:', 1) 'ext': ext,
formats.append({ 'url': stream_url,
'format_id': key, 'vcodec': 'none',
'url': url, })
'play_path': 'mp3:' + path, elif key.startswith('rtmp'):
'ext': ext, # The url doesn't have an rtmp app, we have to extract the playpath
'vcodec': 'none', 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: if not formats:
# We fallback to the stream_url in the original info, this # We fallback to the stream_url in the original info, this