diff options
-rw-r--r-- | youtube/accounts.py | 16 | ||||
-rw-r--r-- | youtube/comments.py | 4 |
2 files changed, 11 insertions, 9 deletions
diff --git a/youtube/accounts.py b/youtube/accounts.py index 0737439..e7336a4 100644 --- a/youtube/accounts.py +++ b/youtube/accounts.py @@ -16,11 +16,12 @@ except FileNotFoundError: # global var for temporary storage of account info accounts = {} -def username_list(): - return accounts.keys() +def account_list_data(): + '''Returns iterable of (channel_id, account_display_name)''' + return ( (channel_id, account['display_name']) for channel_id, account in accounts.items() ) def save_accounts(): - to_save = {username: account for username, account in accounts.items() if account['save']} + to_save = {channel_id: account for channel_id, account in accounts.items() if account['save']} with open(os.path.join(settings.data_dir, 'accounts.txt'), 'w', encoding='utf-8') as f: f.write(json.dumps(to_save, indent=4)) @@ -28,9 +29,10 @@ def add_account(username, password, save, use_tor): cookiejar = http.cookiejar.LWPCookieJar() result = _login(username, password, cookiejar, use_tor) if isinstance(result, dict): - accounts[username] = { + accounts[result["channel_id"]] = { "save":save, - "channel_id": result["channel_id"], + "username": username, + "display_name": username, "cookies":cookiejar.as_lwp_str(ignore_discard=False, ignore_expires=False).split('\n'), } if save: @@ -46,8 +48,8 @@ def cookiejar_from_lwp_str(lwp_str): cookiejar._really_load(io.StringIO(lwp_str), "", False, False) return cookiejar -def account_cookiejar(username): - return cookiejar_from_lwp_str('\n'.join(accounts[username]['cookies'])) +def account_cookiejar(channel_id): + return cookiejar_from_lwp_str('\n'.join(accounts[channel_id]['cookies'])) def get_account_login_page(query_string): style = ''' diff --git a/youtube/comments.py b/youtube/comments.py index bec7ea4..e650a35 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -312,10 +312,10 @@ video_metadata_template = Template('''<section class="video-metadata"> </section> ''') account_option_template = Template(''' - <option value="$username">$username</option>''') + <option value="$channel_id">$display_name</option>''') def comment_box_account_options(): - return ''.join(account_option_template.substitute(username=username) for username in accounts.username_list()) + return ''.join(account_option_template.substitute(channel_id=channel_id, display_name=display_name) for channel_id, display_name in accounts.account_list_data()) comment_box_template = Template(''' <form action="$form_action" method="post" class="comment-form"> |