mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 06:10:12 +01:00
[soundcloud] Allow login using oauth token (#469)
Authored by: blackjack4494
This commit is contained in:
parent
30d569d2ac
commit
be05d5cff1
|
@ -4,7 +4,7 @@
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import random
|
# import random
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
InfoExtractor,
|
InfoExtractor,
|
||||||
|
@ -164,23 +164,11 @@ class SoundcloudIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
# downloadable song
|
# downloadable song
|
||||||
{
|
{
|
||||||
'url': 'https://soundcloud.com/oddsamples/bus-brakes',
|
'url': 'https://soundcloud.com/the80m/the-following',
|
||||||
'md5': '7624f2351f8a3b2e7cd51522496e7631',
|
'md5': '9ffcddb08c87d74fb5808a3c183a1d04',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '128590877',
|
'id': '343609555',
|
||||||
'ext': 'mp3',
|
'ext': 'wav',
|
||||||
'title': 'Bus Brakes',
|
|
||||||
'description': 'md5:0053ca6396e8d2fd7b7e1595ef12ab66',
|
|
||||||
'uploader': 'oddsamples',
|
|
||||||
'uploader_id': '73680509',
|
|
||||||
'timestamp': 1389232924,
|
|
||||||
'upload_date': '20140109',
|
|
||||||
'duration': 17.346,
|
|
||||||
'license': 'cc-by-sa',
|
|
||||||
'view_count': int,
|
|
||||||
'like_count': int,
|
|
||||||
'comment_count': int,
|
|
||||||
'repost_count': int,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
# private link, downloadable format
|
# private link, downloadable format
|
||||||
|
@ -317,12 +305,13 @@ def _download_json(self, *args, **kwargs):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or "T5R4kgWS2PRf6lzLyIravUMnKlbIxQag" # 'EXLwg5lHTO2dslU5EePe3xkw0m1h86Cd' # 'YUKXoArFcqrlQn9tfNHvvyfnDISj04zk'
|
self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'fXuVKzsVXlc6tzniWWS31etd7VHWFUuN' # persistent `client_id`
|
||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
|
_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
|
||||||
_API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
|
_API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
|
||||||
_API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
|
_API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
|
||||||
|
_API_VERIFY_AUTH_TOKEN = 'https://api-auth.soundcloud.com/connect/session%s'
|
||||||
_access_token = None
|
_access_token = None
|
||||||
_HEADERS = {}
|
_HEADERS = {}
|
||||||
_NETRC_MACHINE = 'soundcloud'
|
_NETRC_MACHINE = 'soundcloud'
|
||||||
|
@ -332,6 +321,23 @@ def _login(self):
|
||||||
if username is None:
|
if username is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if username == 'oauth' and password is not None:
|
||||||
|
self._access_token = password
|
||||||
|
query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
|
||||||
|
payload = {'session': {'access_token': self._access_token}}
|
||||||
|
token_verification = sanitized_Request(self._API_VERIFY_AUTH_TOKEN % query, json.dumps(payload).encode('utf-8'))
|
||||||
|
response = self._download_json(token_verification, None, note='Verifying login token...', fatal=False)
|
||||||
|
if response is not False:
|
||||||
|
self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
|
||||||
|
self.report_login()
|
||||||
|
else:
|
||||||
|
self.report_warning('Provided authorization token seems to be invalid. Continue as guest')
|
||||||
|
elif username is not None:
|
||||||
|
self.report_warning(
|
||||||
|
'Login using username and password is not currently supported. '
|
||||||
|
'Use "--user oauth --password <oauth_token>" to login using an oauth token')
|
||||||
|
|
||||||
|
r'''
|
||||||
def genDevId():
|
def genDevId():
|
||||||
def genNumBlock():
|
def genNumBlock():
|
||||||
return ''.join([str(random.randrange(10)) for i in range(6)])
|
return ''.join([str(random.randrange(10)) for i in range(6)])
|
||||||
|
@ -358,6 +364,7 @@ def genNumBlock():
|
||||||
self.report_warning('Unable to get access token, login may has failed')
|
self.report_warning('Unable to get access token, login may has failed')
|
||||||
else:
|
else:
|
||||||
self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
|
self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
|
||||||
|
'''
|
||||||
|
|
||||||
# signature generation
|
# signature generation
|
||||||
def sign(self, user, pw, clid):
|
def sign(self, user, pw, clid):
|
||||||
|
@ -370,9 +377,9 @@ def sign(self, user, pw, clid):
|
||||||
b = 37
|
b = 37
|
||||||
k = 37
|
k = 37
|
||||||
c = 5
|
c = 5
|
||||||
n = "0763ed7314c69015fd4a0dc16bbf4b90" # _KEY
|
n = '0763ed7314c69015fd4a0dc16bbf4b90' # _KEY
|
||||||
y = "8" # _REV
|
y = '8' # _REV
|
||||||
r = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" # _USER_AGENT
|
r = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' # _USER_AGENT
|
||||||
e = user # _USERNAME
|
e = user # _USERNAME
|
||||||
t = clid # _CLIENT_ID
|
t = clid # _CLIENT_ID
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user