- if not formats:
- # Old API, does not work for some tracks (e.g.
- # https://soundcloud.com/giovannisarani/mezzo-valzer)
- # and might serve preview URLs (e.g.
- # http://www.soundcloud.com/snbrn/ele)
- format_dict = self._download_json(
- track_base_url + '/streams', track_id,
- 'Downloading track url', query=query, fatal=False) or {}
-
- for key, stream_url in format_dict.items():
- if invalid_url(stream_url):
- continue
- format_urls.add(stream_url)
- mobj = re.search(r'(http|hls)_([^_]+)_(\d+)_url', key)
- if mobj:
- protocol, ext, abr = mobj.groups()
- add_format({
- 'abr': abr,
- 'ext': ext,
- 'url': stream_url,
- }, protocol)
-
- 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
- urlh = self._request_webpage(
- HEADRequest(info.get('stream_url') or track_base_url + '/stream'),
- track_id, query=query, fatal=False)
- if urlh:
- stream_url = urlh.geturl()
- if not invalid_url(stream_url):
- add_format({'url': stream_url}, 'http')
-