aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/comments.py
diff options
context:
space:
mode:
authorzrose584 <57181548+zrose584@users.noreply.github.com>2020-10-07 19:03:22 +0200
committerzrose584 <57181548+zrose584@users.noreply.github.com>2020-10-07 20:32:57 +0200
commitdebc11931fe1102f17852fd082d0dac50d477ce9 (patch)
treea0d13036eaf138e3dbfa94942b305fd8534d5361 /youtube/comments.py
parent9123d9a6cfa2af511b17591541ab2e67aa83475f (diff)
downloadyt-local-debc11931fe1102f17852fd082d0dac50d477ce9.tar.lz
yt-local-debc11931fe1102f17852fd082d0dac50d477ce9.tar.xz
yt-local-debc11931fe1102f17852fd082d0dac50d477ce9.zip
add comments.js
Diffstat (limited to 'youtube/comments.py')
-rw-r--r--youtube/comments.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/youtube/comments.py b/youtube/comments.py
index 07d4b89..1af9079 100644
--- a/youtube/comments.py
+++ b/youtube/comments.py
@@ -27,7 +27,7 @@ from flask import request
def make_comment_ctoken(video_id, sort=0, offset=0, lc='', secret_key=''):
video_id = proto.as_bytes(video_id)
secret_key = proto.as_bytes(secret_key)
-
+
page_info = proto.string(4,video_id) + proto.uint(6, sort)
offset_information = proto.nested(4, page_info) + proto.uint(5, offset)
@@ -41,11 +41,11 @@ def make_comment_ctoken(video_id, sort=0, offset=0, lc='', secret_key=''):
result = proto.nested(2, page_params) + proto.uint(3,6) + proto.nested(6, offset_information)
return base64.urlsafe_b64encode(result).decode('ascii')
-def comment_replies_ctoken(video_id, comment_id, max_results=500):
+def comment_replies_ctoken(video_id, comment_id, max_results=500):
params = proto.string(2, comment_id) + proto.uint(9, max_results)
params = proto.nested(3, params)
-
+
result = proto.nested(2, proto.string(2, video_id)) + proto.uint(3,6) + proto.nested(6, params)
return base64.urlsafe_b64encode(result).decode('ascii')
@@ -121,10 +121,18 @@ def post_process_comments_info(comments_info):
comment['view_replies_text'] = str(reply_count) + ' replies'
+ def fmt_num(num):
+ for unit in ['','k']:
+ if num < 1000:
+ return "%3.1f%s" % (num, unit) if unit else num
+ num /= 1000.0
+ return "%.1f%s" % (num, 'm')
+
+ # if comment['like_count'] = '👍 ' + str(fmt_num(comment['like_count']))
if comment['like_count'] == 1:
comment['likes_text'] = '1 like'
else:
- comment['likes_text'] = str(comment['like_count']) + ' likes'
+ comment['likes_text'] = str(fmt_num(comment['like_count'])) + ' likes'
comments_info['include_avatars'] = settings.enable_comment_avatars
if comments_info['ctoken']:
@@ -187,8 +195,10 @@ def get_comments_page():
'replying': replies,
}
+
return flask.render_template('comments_page.html',
comments_info = comments_info,
comment_posting_box_info = comment_posting_box_info,
+ slim = request.args.get('slim', False)
)