Add option to pass raw headers to setup() (in place of terminal input)
Based on this change, coverage now runs without user input
This commit is contained in:
parent
947bbcc17b
commit
3f186d4e00
4 changed files with 20 additions and 21 deletions
|
|
@ -2,6 +2,7 @@
|
|||
brand_account = 101234229123420379537
|
||||
headers = headers_auth_json_as_string
|
||||
headers_file = ./headers_auth.json
|
||||
headers_raw = raw_headers_pasted_from_browser
|
||||
|
||||
[playlists]
|
||||
own = owned_playlist_id
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class TestYTMusic(unittest.TestCase):
|
|||
self.assertRaises(Exception, YTMusic, "{}")
|
||||
|
||||
def test_setup(self):
|
||||
YTMusic.setup(config['auth']['headers_file'])
|
||||
YTMusic.setup(config['auth']['headers_file'], config['auth']['headers_raw'])
|
||||
|
||||
###############
|
||||
# BROWSING
|
||||
|
|
|
|||
|
|
@ -6,17 +6,19 @@ import platform
|
|||
path = os.path.dirname(os.path.realpath(__file__)) + os.sep
|
||||
|
||||
|
||||
def setup(filepath=None):
|
||||
eof = "Ctrl-D" if platform.system() != "Windows" else "'Enter, Ctrl-Z, Enter'"
|
||||
print("Please paste the request headers from Firefox and press " + eof + " to continue:")
|
||||
|
||||
def setup(filepath=None, headers_raw=None):
|
||||
contents = []
|
||||
while True:
|
||||
try:
|
||||
line = input()
|
||||
except EOFError:
|
||||
break
|
||||
contents.append(line)
|
||||
if not headers_raw:
|
||||
eof = "Ctrl-D" if platform.system() != "Windows" else "'Enter, Ctrl-Z, Enter'"
|
||||
print("Please paste the request headers from Firefox and press " + eof + " to continue:")
|
||||
while True:
|
||||
try:
|
||||
line = input()
|
||||
except EOFError:
|
||||
break
|
||||
contents.append(line)
|
||||
else:
|
||||
contents = input.split('\n')
|
||||
|
||||
required_headers = ["Cookie"]
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -78,15 +78,17 @@ class YTMusic:
|
|||
raise Exception("Please provide authentication before using this function")
|
||||
|
||||
@classmethod
|
||||
def setup(cls, filepath: str = None):
|
||||
def setup(cls, filepath: str = None, headers_raw: str = None):
|
||||
"""
|
||||
Requests browser headers from the user via command line
|
||||
and returns a string that can be passed to YTMusic()
|
||||
|
||||
:param filepath: Optional filepath to store headers to.
|
||||
:param headers_raw: Optional request headers copied from browser.
|
||||
Otherwise requested from terminal
|
||||
:return: configuration headers string
|
||||
"""
|
||||
return setup(filepath)
|
||||
return setup(filepath, headers_raw)
|
||||
|
||||
###############
|
||||
# BROWSING
|
||||
|
|
@ -807,10 +809,7 @@ class YTMusic:
|
|||
body = {'playlistId': playlistId}
|
||||
actions = []
|
||||
if title:
|
||||
actions.append({
|
||||
'action': 'ACTION_SET_PLAYLIST_NAME',
|
||||
'playlistName': title
|
||||
})
|
||||
actions.append({'action': 'ACTION_SET_PLAYLIST_NAME', 'playlistName': title})
|
||||
|
||||
if description:
|
||||
actions.append({
|
||||
|
|
@ -832,10 +831,7 @@ class YTMusic:
|
|||
})
|
||||
|
||||
if addPlaylistId:
|
||||
actions.append({
|
||||
'action': 'ACTION_ADD_PLAYLIST',
|
||||
'addedFullListId': addPlaylistId}
|
||||
)
|
||||
actions.append({'action': 'ACTION_ADD_PLAYLIST', 'addedFullListId': addPlaylistId})
|
||||
|
||||
body['actions'] = actions
|
||||
endpoint = 'browse/edit_playlist'
|
||||
|
|
|
|||
Loading…
Reference in a new issue