Added account selection to comment boxes
This commit is contained in:
parent
dfbd7778d1
commit
fcbd8ebef6
@ -16,6 +16,9 @@ except FileNotFoundError:
|
|||||||
# global var for temporary storage of account info
|
# global var for temporary storage of account info
|
||||||
accounts = {}
|
accounts = {}
|
||||||
|
|
||||||
|
def username_list():
|
||||||
|
return accounts.keys()
|
||||||
|
|
||||||
def save_accounts():
|
def save_accounts():
|
||||||
to_save = {username: account for username, account in accounts.items() if account['save']}
|
to_save = {username: account for username, account in accounts.items() if account['save']}
|
||||||
with open(os.path.join(settings.data_dir, 'accounts.txt'), 'w', encoding='utf-8') as f:
|
with open(os.path.join(settings.data_dir, 'accounts.txt'), 'w', encoding='utf-8') as f:
|
||||||
|
@ -23,15 +23,29 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comment-form{
|
||||||
|
display: grid;
|
||||||
|
align-content: start;
|
||||||
|
justify-items: start;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
#comment-account-options{
|
||||||
|
display:grid;
|
||||||
|
grid-auto-flow: column;
|
||||||
|
grid-column-gap: 10px;
|
||||||
|
margin-top:10px;
|
||||||
|
margin-bottom:10px;
|
||||||
|
}
|
||||||
|
#comment-account-options a{
|
||||||
|
margin-left:10px;
|
||||||
|
}
|
||||||
|
|
||||||
.comments-area{
|
.comments-area{
|
||||||
display:grid;
|
display:grid;
|
||||||
}
|
}
|
||||||
.comment-form{
|
|
||||||
display:contents;
|
|
||||||
}
|
|
||||||
.comments-area textarea{
|
.comments-area textarea{
|
||||||
resize: vertical;
|
resize: vertical;
|
||||||
margin-top:10px;
|
justify-self:stretch;
|
||||||
}
|
}
|
||||||
.post-comment-button{
|
.post-comment-button{
|
||||||
margin-top:10px;
|
margin-top:10px;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from youtube import proto, common
|
from youtube import proto, common, accounts
|
||||||
import base64
|
import base64
|
||||||
from youtube.common import uppercase_escape, default_multi_get, format_text_runs, URL_ORIGIN, fetch_url
|
from youtube.common import uppercase_escape, default_multi_get, format_text_runs, URL_ORIGIN, fetch_url
|
||||||
from string import Template
|
from string import Template
|
||||||
@ -311,8 +311,21 @@ video_metadata_template = Template('''<section class="video-metadata">
|
|||||||
<span>Sorted by $sort</span>
|
<span>Sorted by $sort</span>
|
||||||
</section>
|
</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('''
|
comment_box_template = Template('''
|
||||||
<form action="$form_action" method="post" class="comment-form">
|
<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>
|
<textarea name="comment_text"></textarea>
|
||||||
$video_id_input
|
$video_id_input
|
||||||
<button type="submit" class="post-comment-button">$post_text</button>
|
<button type="submit" class="post-comment-button">$post_text</button>
|
||||||
@ -334,7 +347,7 @@ def get_comments_page(query_string):
|
|||||||
if replies:
|
if replies:
|
||||||
page_title = 'Replies'
|
page_title = 'Replies'
|
||||||
video_metadata = ''
|
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 = ''
|
comment_links = ''
|
||||||
else:
|
else:
|
||||||
page_number = str(int(metadata['offset']/20) + 1)
|
page_number = str(int(metadata['offset']/20) + 1)
|
||||||
@ -350,7 +363,8 @@ def get_comments_page(query_string):
|
|||||||
comment_box = comment_box_template.substitute(
|
comment_box = comment_box_template.substitute(
|
||||||
form_action= common.URL_ORIGIN + '/post_comment',
|
form_action= common.URL_ORIGIN + '/post_comment',
|
||||||
video_id_input='''<input type="hidden" name="video_id" value="''' + metadata['video_id'] + '''">''',
|
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'])
|
other_sort_url = common.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(metadata['video_id'], sort=1 - metadata['sort'])
|
||||||
|
@ -160,18 +160,21 @@ textarea{
|
|||||||
}
|
}
|
||||||
.comment-form{
|
.comment-form{
|
||||||
grid-column:2;
|
grid-column:2;
|
||||||
|
justify-content:start;
|
||||||
}'''
|
}'''
|
||||||
if parent_id: # comment reply
|
if parent_id: # comment reply
|
||||||
comment_box = comments.comment_box_template.substitute(
|
comment_box = comments.comment_box_template.substitute(
|
||||||
form_action = common.URL_ORIGIN + '/comments?parent_id=' + parent_id + "&video_id=" + video_id,
|
form_action = common.URL_ORIGIN + '/comments?parent_id=' + parent_id + "&video_id=" + video_id,
|
||||||
video_id_input = '',
|
video_id_input = '',
|
||||||
post_text = "Post reply",
|
post_text = "Post reply",
|
||||||
|
options=comments.comment_box_account_options(),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
comment_box = comments.comment_box_template.substitute(
|
comment_box = comments.comment_box_template.substitute(
|
||||||
form_action = common.URL_ORIGIN + '/post_comment',
|
form_action = common.URL_ORIGIN + '/post_comment',
|
||||||
video_id_input = '''<input type="hidden" name="video_id" value="''' + video_id + '''">''',
|
video_id_input = '''<input type="hidden" name="video_id" value="''' + video_id + '''">''',
|
||||||
post_text = "Post comment",
|
post_text = "Post comment",
|
||||||
|
options=comments.comment_box_account_options(),
|
||||||
)
|
)
|
||||||
|
|
||||||
page = '''<div class="left">\n''' + comment_box + '''</div>\n'''
|
page = '''<div class="left">\n''' + comment_box + '''</div>\n'''
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>$page_title</title>
|
<title>$page_title</title>
|
||||||
<link href="/youtube.com/shared.css" type="text/css" rel="stylesheet">
|
<link href="/youtube.com/shared.css" type="text/css" rel="stylesheet">
|
||||||
|
<link href="/youtube.com/comments.css" type="text/css" rel="stylesheet">
|
||||||
<link href="/youtube.com/favicon.ico" type="image/x-icon" rel="icon">
|
<link href="/youtube.com/favicon.ico" type="image/x-icon" rel="icon">
|
||||||
<link title="Youtube local" href="/youtube.com/opensearch.xml" rel="search" type="application/opensearchdescription+xml">
|
<link title="Youtube local" href="/youtube.com/opensearch.xml" rel="search" type="application/opensearchdescription+xml">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user