diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-12-30 23:27:51 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-12-30 23:27:51 -0800 |
commit | 913c258093d63f7b41c015587b6a8fad3b033bf3 (patch) | |
tree | 4b8494b0d2c782d3d7d5b8c47ab54a6c77f18ce8 /youtube | |
parent | 248c2e1415c2776b07d19cedb56605fc634c022d (diff) | |
download | yt-local-913c258093d63f7b41c015587b6a8fad3b033bf3.tar.lz yt-local-913c258093d63f7b41c015587b6a8fad3b033bf3.tar.xz yt-local-913c258093d63f7b41c015587b6a8fad3b033bf3.zip |
Use channel id to uniquely identify accounts, not username
Diffstat (limited to 'youtube')
-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"> |