[soundcloud] Fix download URL with private tracks

This commit is contained in:
Tatsuyuki Ishi 2017-09-01 17:08:24 +09:00 committed by Sergey M․
parent 23b2df82c7
commit 73602bcd0c
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
1 changed files with 9 additions and 10 deletions

View File

@ -1,8 +1,8 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
import itertools import itertools
import re
from .common import ( from .common import (
InfoExtractor, InfoExtractor,
@ -17,7 +17,7 @@ from ..utils import (
ExtractorError, ExtractorError,
int_or_none, int_or_none,
unified_strdate, unified_strdate,
) update_url_query)
class SoundcloudIE(InfoExtractor): class SoundcloudIE(InfoExtractor):
@ -160,11 +160,13 @@ class SoundcloudIE(InfoExtractor):
'license': info.get('license'), 'license': info.get('license'),
} }
formats = [] formats = []
query = {'client_id': self._CLIENT_ID}
if secret_token is not None:
query['secret_token'] = secret_token
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 = update_url_query(
'https://api.soundcloud.com/tracks/{0}/download?client_id={1}'.format( 'https://api.soundcloud.com/tracks/{0}/download'.format(track_id), query)
track_id, self._CLIENT_ID))
formats.append({ formats.append({
'format_id': 'download', 'format_id': 'download',
'ext': info.get('original_format', 'mp3'), 'ext': info.get('original_format', 'mp3'),
@ -176,10 +178,7 @@ class SoundcloudIE(InfoExtractor):
# We have to retrieve the url # We have to retrieve the url
format_dict = self._download_json( format_dict = self._download_json(
'https://api.soundcloud.com/i1/tracks/%s/streams' % track_id, 'https://api.soundcloud.com/i1/tracks/%s/streams' % track_id,
track_id, 'Downloading track url', query={ track_id, 'Downloading track url', query=query)
'client_id': self._CLIENT_ID,
'secret_token': secret_token,
})
for key, stream_url in format_dict.items(): for key, stream_url in format_dict.items():
abr = int_or_none(self._search_regex( abr = int_or_none(self._search_regex(
@ -216,7 +215,7 @@ class SoundcloudIE(InfoExtractor):
# cannot be always used, sometimes it can give an HTTP 404 error # cannot be always used, sometimes it can give an HTTP 404 error
formats.append({ formats.append({
'format_id': 'fallback', 'format_id': 'fallback',
'url': info['stream_url'] + '?client_id=' + self._CLIENT_ID, 'url': update_url_query(info['stream_url'], query),
'ext': ext, 'ext': ext,
}) })