Return comments by newest after posting top-level comment

This commit is contained in:
James Taylor 2018-08-31 23:10:22 -07:00
parent a9ea97ad39
commit 6146c5293b
3 changed files with 17 additions and 13 deletions

View File

@ -93,12 +93,7 @@ def post_comment(query_string, fields):
return comments.get_comments_page(query_string) return comments.get_comments_page(query_string)
else: else:
_post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data) _post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data)
return common.yt_basic_template.substitute( return comments.get_comments_page('ctoken=' + comments.make_comment_ctoken(video_id, sort=1))
page_title = "Success",
style = '',
header = common.get_header(),
page = 'Comment sucessfully posted',
)
def get_post_comment_page(query_string): def get_post_comment_page(query_string):
@ -120,7 +115,7 @@ textarea{
grid-column:2; grid-column:2;
}''' }'''
page = '''<div class="left"> page = '''<div class="left">
<form action="" method="post" class="comment-form"> <form action="''' + common.URL_ORIGIN + '/comments?ctoken=' + comments.make_comment_ctoken(video_id, sort=1).replace("=", "%3D") + '''" method="post" class="comment-form">
<textarea name="comment_text"></textarea> <textarea name="comment_text"></textarea>
<input type="hidden" name="video_id" value="''' + video_id + '''"> <input type="hidden" name="video_id" value="''' + video_id + '''">
<button type="submit">Post comment</button> <button type="submit">Post comment</button>

View File

@ -1,10 +1,10 @@
.video-metadata{ .video-metadata{
display: grid; display: grid;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto; grid-template-rows: auto auto 1fr auto;
} }
.video-metadata > .video-metadata-thumbnail-box{ .video-metadata > .video-metadata-thumbnail-box{
grid-row: 1 / span 2; grid-row: 1 / span 3;
} }
.video-metadata > .title{ .video-metadata > .title{
word-wrap:break-word; word-wrap:break-word;
@ -14,8 +14,11 @@
grid-row: 2; grid-row: 2;
font-size: 15px; font-size: 15px;
} }
.video-metadata > span{
grid-row:3;
}
.video-metadata > hr{ .video-metadata > hr{
grid-row: 3; grid-row: 4;
grid-column: 1 / span 2; grid-column: 1 / span 2;
width: 100%; width: 100%;
} }

View File

@ -80,9 +80,13 @@ def ctoken_metadata(ctoken):
result['offset'] = offset_information.get(5, 0) result['offset'] = offset_information.get(5, 0)
result['is_replies'] = False result['is_replies'] = False
if 3 in offset_information: if (3 in offset_information) and (2 in offset_information[3]):
if 2 in offset_information[3]: result['is_replies'] = True
result['is_replies'] = True else:
try:
result['sort'] = offset_information[4][6]
except KeyError:
result['sort'] = 0
return result return result
def get_ids(ctoken): def get_ids(ctoken):
@ -252,6 +256,7 @@ video_metadata_template = Template('''<section class="video-metadata">
<a class="title" href="$url" title="$title">$title</a> <a class="title" href="$url" title="$title">$title</a>
<h2>Comments page $page_number</h2> <h2>Comments page $page_number</h2>
<span>Sorted by $sort</span>
<hr> <hr>
</section> </section>
''') ''')
@ -282,6 +287,7 @@ def get_comments_page(query_string):
video_metadata = video_metadata_template.substitute( video_metadata = video_metadata_template.substitute(
page_number = page_number, page_number = page_number,
sort = 'top' if metadata['sort'] == 0 else 'newest',
title = html.escape(parsed_comments['video_title']), title = html.escape(parsed_comments['video_title']),
url = common.URL_ORIGIN + '/watch?v=' + metadata['video_id'], url = common.URL_ORIGIN + '/watch?v=' + metadata['video_id'],
thumbnail = '/i.ytimg.com/vi/'+ metadata['video_id'] + '/mqdefault.jpg', thumbnail = '/i.ytimg.com/vi/'+ metadata['video_id'] + '/mqdefault.jpg',