aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/comments.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-12-26 19:37:15 -0800
committerJames Taylor <user234683@users.noreply.github.com>2018-12-26 19:37:15 -0800
commitfcbd8ebef6f4b3648f9b04cb8b7788fed4aeb719 (patch)
tree73625c7c9a30c742c76cb055219ab6be9d959a99 /youtube/comments.py
parentdfbd7778d10c15cf2e12e9007beba5458a3f3ab1 (diff)
downloadyt-local-fcbd8ebef6f4b3648f9b04cb8b7788fed4aeb719.tar.lz
yt-local-fcbd8ebef6f4b3648f9b04cb8b7788fed4aeb719.tar.xz
yt-local-fcbd8ebef6f4b3648f9b04cb8b7788fed4aeb719.zip
Added account selection to comment boxes
Diffstat (limited to 'youtube/comments.py')
-rw-r--r--youtube/comments.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/youtube/comments.py b/youtube/comments.py
index abc0a79..1b22d24 100644
--- a/youtube/comments.py
+++ b/youtube/comments.py
@@ -1,5 +1,5 @@
import json
-from youtube import proto, common
+from youtube import proto, common, accounts
import base64
from youtube.common import uppercase_escape, default_multi_get, format_text_runs, URL_ORIGIN, fetch_url
from string import Template
@@ -311,8 +311,21 @@ video_metadata_template = Template('''<section class="video-metadata">
<span>Sorted by $sort</span>
</section>
''')
+account_option_template = Template('''
+ <option value="$username">$username</option>''')
+
+def comment_box_account_options():
+ return ''.join(account_option_template.substitute(username=username) for username in accounts.username_list())
+
comment_box_template = Template('''
<form action="$form_action" method="post" class="comment-form">
+ <div id="comment-account-options">
+ <label for="username-selection">Account:</label>
+ <select id="username-selection">
+$options
+ </select>
+ <a href="''' + common.URL_ORIGIN + '''/login" target="_blank">Add account</a>
+ </div>
<textarea name="comment_text"></textarea>
$video_id_input
<button type="submit" class="post-comment-button">$post_text</button>
@@ -334,7 +347,7 @@ def get_comments_page(query_string):
if replies:
page_title = 'Replies'
video_metadata = ''
- comment_box = comment_box_template.substitute(form_action='', video_id_input='', post_text='Post reply')
+ comment_box = comment_box_template.substitute(form_action='', video_id_input='', post_text='Post reply', options=comment_box_account_options())
comment_links = ''
else:
page_number = str(int(metadata['offset']/20) + 1)
@@ -350,7 +363,8 @@ def get_comments_page(query_string):
comment_box = comment_box_template.substitute(
form_action= common.URL_ORIGIN + '/post_comment',
video_id_input='''<input type="hidden" name="video_id" value="''' + metadata['video_id'] + '''">''',
- post_text='Post comment'
+ post_text='Post comment',
+ options=comment_box_account_options(),
)
other_sort_url = common.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(metadata['video_id'], sort=1 - metadata['sort'])