+ self.to_screen('%s: Resolving id' % video_id)
+
+ @classmethod
+ def _resolv_url(cls, url):
+ return 'http://api.soundcloud.com/resolve.json?url=' + url + '&client_id=' + cls._CLIENT_ID
+
+ def _extract_info_dict(self, info, full_title=None, quiet=False, secret_token=None):
+ track_id = compat_str(info['id'])
+ name = full_title or track_id
+ if quiet:
+ self.report_extraction(name)
+
+ thumbnail = info['artwork_url']
+ if thumbnail is not None:
+ thumbnail = thumbnail.replace('-large', '-t500x500')
+ ext = 'mp3'
+ result = {
+ 'id': track_id,
+ 'uploader': info['user']['username'],
+ 'upload_date': unified_strdate(info['created_at']),
+ 'title': info['title'],
+ 'description': info['description'],
+ 'thumbnail': thumbnail,
+ 'duration': int_or_none(info.get('duration'), 1000),
+ 'webpage_url': info.get('permalink_url'),
+ }
+ 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))
+ formats.append({
+ 'format_id': 'download',
+ 'ext': info.get('original_format', 'mp3'),
+ 'url': format_url,
+ '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))
+ 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': 'flv',
+ '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._check_formats(formats, track_id)
+ self._sort_formats(formats)
+ result['formats'] = formats
+
+ return result