[soundcloud] Download Soundcloud GO+ high quality streams and private playlists

This commit is contained in:
unkernet 2023-06-16 16:40:58 +07:00
parent 4d05f84325
commit ca0b2658af

View File

@ -293,6 +293,11 @@ class SoundcloudIE(InfoExtractor):
if non_fatal: if non_fatal:
del kwargs['fatal'] del kwargs['fatal']
query = kwargs.get('query', {}).copy() query = kwargs.get('query', {}).copy()
oauth_token = self._get_cookies(self._BASE_URL).get('oauth_token')
if oauth_token:
if not kwargs.get('headers'):
kwargs['headers'] = {}
kwargs['headers']['authorization'] = 'OAuth ' + oauth_token.value
for _ in range(2): for _ in range(2):
query['client_id'] = self._CLIENT_ID query['client_id'] = self._CLIENT_ID
kwargs['query'] = query kwargs['query'] = query
@ -319,6 +324,7 @@ class SoundcloudIE(InfoExtractor):
track_id = compat_str(info['id']) track_id = compat_str(info['id'])
title = info['title'] title = info['title']
duration = info.get('duration')
format_urls = set() format_urls = set()
formats = [] formats = []
query = {'client_id': self._CLIENT_ID} query = {'client_id': self._CLIENT_ID}
@ -335,12 +341,14 @@ class SoundcloudIE(InfoExtractor):
if urlh: if urlh:
format_url = urlh.geturl() format_url = urlh.geturl()
format_urls.add(format_url) format_urls.add(format_url)
filesize = int_or_none(urlh.headers.get('Content-Length'))
formats.append({ formats.append({
'format_id': 'download', 'format_id': 'download',
'ext': urlhandle_detect_ext(urlh) or 'mp3', 'ext': urlhandle_detect_ext(urlh) or 'mp3',
'filesize': int_or_none(urlh.headers.get('Content-Length')), 'filesize': filesize,
'url': format_url, 'url': format_url,
'preference': 10, 'preference': 10,
'abr': (filesize and duration) and (filesize / duration * 8),
}) })
def invalid_url(url): def invalid_url(url):