diff options
| author | Philipp Hagemeister <phihag@phihag.de> | 2014-03-24 02:21:17 +0100 | 
|---|---|---|
| committer | Philipp Hagemeister <phihag@phihag.de> | 2014-03-24 02:21:17 +0100 | 
| commit | 5e114e4bfe4ea0a15462e1c10ce46e20792e81b8 (patch) | |
| tree | aaf3b40d113780fc17b37df7f7b17b52e64a2508 | |
| parent | 83622b6d2fcc265be8427580412581fe64390bb0 (diff) | |
[soundcloud] Always add streaming formats
| -rw-r--r-- | youtube_dl/extractor/soundcloud.py | 61 | 
1 files changed, 31 insertions, 30 deletions
diff --git a/youtube_dl/extractor/soundcloud.py b/youtube_dl/extractor/soundcloud.py index 36655b51e..8893699aa 100644 --- a/youtube_dl/extractor/soundcloud.py +++ b/youtube_dl/extractor/soundcloud.py @@ -124,45 +124,46 @@ class SoundcloudIE(InfoExtractor):              'description': info['description'],              'thumbnail': thumbnail,          } +        formats = []          if info.get('downloadable', False):              # We can build a direct link to the song              format_url = (                  'https://api.soundcloud.com/tracks/{0}/download?client_id={1}'.format(                      track_id, self._CLIENT_ID)) -            result['formats'] = [{ +            formats.append({                  'format_id': 'download',                  'ext': info.get('original_format', 'mp3'),                  'url': format_url,                  'vcodec': 'none', -            }] -        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 = [] -            format_dict = json.loads(stream_json) -            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', -                    }) +                'preference': 10, +            }) + +        # 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') + +        format_dict = json.loads(stream_json) +        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  | 
