From bee14ea9ea2a3e78f70b1a68c965d15297a6ede8 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 7 Aug 2021 14:36:11 -0700 Subject: Comments: Fix exceptions when ctoken metadata are missing (None) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jesús --- youtube/comments.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'youtube/comments.py') 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)] -- cgit v1.2.3