From 6146c5293bc44edd3a5797275874b58cd019a4fc Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 31 Aug 2018 23:10:22 -0700 Subject: Return comments by newest after posting top-level comment --- youtube/account_functions.py | 9 ++------- youtube/comments.css | 9 ++++++--- youtube/comments.py | 12 +++++++++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/youtube/account_functions.py b/youtube/account_functions.py index 9dd3d10..b3c9541 100644 --- a/youtube/account_functions.py +++ b/youtube/account_functions.py @@ -93,12 +93,7 @@ def post_comment(query_string, fields): return comments.get_comments_page(query_string) else: _post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data) - return common.yt_basic_template.substitute( - page_title = "Success", - style = '', - header = common.get_header(), - page = 'Comment sucessfully posted', - ) + return comments.get_comments_page('ctoken=' + comments.make_comment_ctoken(video_id, sort=1)) def get_post_comment_page(query_string): @@ -120,7 +115,7 @@ textarea{ grid-column:2; }''' page = '''
-
+ diff --git a/youtube/comments.css b/youtube/comments.css index 599f569..ed1721f 100644 --- a/youtube/comments.css +++ b/youtube/comments.css @@ -1,10 +1,10 @@ .video-metadata{ display: grid; grid-template-columns: auto 1fr; - grid-template-rows: auto 1fr auto; + grid-template-rows: auto auto 1fr auto; } .video-metadata > .video-metadata-thumbnail-box{ - grid-row: 1 / span 2; + grid-row: 1 / span 3; } .video-metadata > .title{ word-wrap:break-word; @@ -14,8 +14,11 @@ grid-row: 2; font-size: 15px; } + .video-metadata > span{ + grid-row:3; + } .video-metadata > hr{ - grid-row: 3; + grid-row: 4; grid-column: 1 / span 2; width: 100%; } diff --git a/youtube/comments.py b/youtube/comments.py index a1f08bf..2913bde 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -80,9 +80,13 @@ def ctoken_metadata(ctoken): result['offset'] = offset_information.get(5, 0) result['is_replies'] = False - if 3 in offset_information: - if 2 in offset_information[3]: - result['is_replies'] = True + if (3 in offset_information) and (2 in offset_information[3]): + result['is_replies'] = True + else: + try: + result['sort'] = offset_information[4][6] + except KeyError: + result['sort'] = 0 return result def get_ids(ctoken): @@ -252,6 +256,7 @@ video_metadata_template = Template(''' ''') @@ -282,6 +287,7 @@ def get_comments_page(query_string): video_metadata = video_metadata_template.substitute( page_number = page_number, + sort = 'top' if metadata['sort'] == 0 else 'newest', title = html.escape(parsed_comments['video_title']), url = common.URL_ORIGIN + '/watch?v=' + metadata['video_id'], thumbnail = '/i.ytimg.com/vi/'+ metadata['video_id'] + '/mqdefault.jpg', -- cgit v1.2.3