From 9a386145ff5db24eed5ca93977463e4885434104 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 26 Dec 2018 18:37:35 -0800 Subject: If specified, save account to disk after adding it --- youtube/accounts.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'youtube/accounts.py') diff --git a/youtube/accounts.py b/youtube/accounts.py index 312b711..e7d3ea5 100644 --- a/youtube/accounts.py +++ b/youtube/accounts.py @@ -23,12 +23,15 @@ def save_accounts(): def add_account(username, password, save): cookiejar = http.cookiejar.LWPCookieJar() - condition = _login(username, password, cookiejar) - accounts[username] = { - "save":save, - "cookies":cookiejar.as_lwp_str(ignore_discard=False, ignore_expires=False), - } - return condition + successful = _login(username, password, cookiejar) + if successful: + accounts[username] = { + "save":save, + "cookies":cookiejar.as_lwp_str(ignore_discard=False, ignore_expires=False), + } + if save: + save_accounts() + return successful def cookiejar_from_lwp_str(lwp_str): cookiejar = http.cookiejar.LWPCookieJar() -- cgit v1.2.3