aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/comments.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-08-07 14:36:11 -0700
committerJesús <heckyel@hyperbola.info>2021-08-09 12:00:18 -0500
commitbee14ea9ea2a3e78f70b1a68c965d15297a6ede8 (patch)
tree4dc3108d0db8daab82da2a3756f7beb08a878724 /youtube/comments.py
parent7720f3bde530f283bd4f2f56ca8382f2ceed18e0 (diff)
downloadyt-local-bee14ea9ea2a3e78f70b1a68c965d15297a6ede8.tar.lz
yt-local-bee14ea9ea2a3e78f70b1a68c965d15297a6ede8.tar.xz
yt-local-bee14ea9ea2a3e78f70b1a68c965d15297a6ede8.zip
Comments: Fix exceptions when ctoken metadata are missing (None)
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/comments.py')
-rw-r--r--youtube/comments.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/youtube/comments.py b/youtube/comments.py
index 68456bd..b23c079 100644
--- a/youtube/comments.py
+++ b/youtube/comments.py
@@ -143,7 +143,10 @@ def post_process_comments_info(comments_info):
comments_info['more_comments_url'] = concat_or_none(
util.URL_ORIGIN, '/comments?ctoken=', ctoken, replies_param)
- comments_info['page_number'] = page_number = str(int(comments_info['offset']/20) + 1)
+ if comments_info['offset'] is None:
+ comments_info['page_number'] = None
+ else:
+ comments_info['page_number'] = int(comments_info['offset']/20) + 1
if not comments_info['is_replies']:
comments_info['sort_text'] = 'top' if comments_info['sort'] == 0 else 'newest'
@@ -213,7 +216,15 @@ def get_comments_page():
post_process_comments_info(comments_info)
if not replies:
- other_sort_url = util.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(comments_info['video_id'], sort=1 - comments_info['sort'])
+ if comments_info['sort'] is None or comments_info['video_id'] is None:
+ other_sort_url = None
+ else:
+ other_sort_url = (
+ util.URL_ORIGIN
+ + '/comments?ctoken='
+ + make_comment_ctoken(comments_info['video_id'],
+ sort=1-comments_info['sort'])
+ )
other_sort_text = 'Sort by ' + ('newest' if comments_info['sort'] == 0 else 'top')
comments_info['comment_links'] = [(other_sort_text, other_sort_url)]