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:
sigma67 2020-05-19 15:49:55 +02:00
commit 3f186d4e00
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
4 changed files with 20 additions and 21 deletions

View file

@ -2,6 +2,7 @@
brand_account = 101234229123420379537 brand_account = 101234229123420379537
headers = headers_auth_json_as_string headers = headers_auth_json_as_string
headers_file = ./headers_auth.json headers_file = ./headers_auth.json
headers_raw = raw_headers_pasted_from_browser
[playlists] [playlists]
own = owned_playlist_id own = owned_playlist_id

View file

@ -15,7 +15,7 @@ class TestYTMusic(unittest.TestCase):
self.assertRaises(Exception, YTMusic, "{}") self.assertRaises(Exception, YTMusic, "{}")
def test_setup(self): def test_setup(self):
YTMusic.setup(config['auth']['headers_file']) YTMusic.setup(config['auth']['headers_file'], config['auth']['headers_raw'])
############### ###############
# BROWSING # BROWSING

View file

@ -6,17 +6,19 @@ import platform
path = os.path.dirname(os.path.realpath(__file__)) + os.sep path = os.path.dirname(os.path.realpath(__file__)) + os.sep
def setup(filepath=None): def setup(filepath=None, headers_raw=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:")
contents = [] contents = []
while True: if not headers_raw:
try: eof = "Ctrl-D" if platform.system() != "Windows" else "'Enter, Ctrl-Z, Enter'"
line = input() print("Please paste the request headers from Firefox and press " + eof + " to continue:")
except EOFError: while True:
break try:
contents.append(line) line = input()
except EOFError:
break
contents.append(line)
else:
contents = input.split('\n')
required_headers = ["Cookie"] required_headers = ["Cookie"]
try: try:

View file

@ -78,15 +78,17 @@ class YTMusic:
raise Exception("Please provide authentication before using this function") raise Exception("Please provide authentication before using this function")
@classmethod @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 Requests browser headers from the user via command line
and returns a string that can be passed to YTMusic() and returns a string that can be passed to YTMusic()
:param filepath: Optional filepath to store headers to. :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: configuration headers string
""" """
return setup(filepath) return setup(filepath, headers_raw)
############### ###############
# BROWSING # BROWSING
@ -807,10 +809,7 @@ class YTMusic:
body = {'playlistId': playlistId} body = {'playlistId': playlistId}
actions = [] actions = []
if title: if title:
actions.append({ actions.append({'action': 'ACTION_SET_PLAYLIST_NAME', 'playlistName': title})
'action': 'ACTION_SET_PLAYLIST_NAME',
'playlistName': title
})
if description: if description:
actions.append({ actions.append({
@ -832,10 +831,7 @@ class YTMusic:
}) })
if addPlaylistId: if addPlaylistId:
actions.append({ actions.append({'action': 'ACTION_ADD_PLAYLIST', 'addedFullListId': addPlaylistId})
'action': 'ACTION_ADD_PLAYLIST',
'addedFullListId': addPlaylistId}
)
body['actions'] = actions body['actions'] = actions
endpoint = 'browse/edit_playlist' endpoint = 'browse/edit_playlist'