diff options
Diffstat (limited to 'youtube/comments.py')
| -rw-r--r-- | youtube/comments.py | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/youtube/comments.py b/youtube/comments.py index 8d03f22..c4e30dd 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -104,20 +104,19 @@ def post_process_comments_info(comments_info): comment['replies_url'] = None comment['replies_url'] = concat_or_none( util.URL_ORIGIN, - '/comments?replies=1&ctoken=' + ctoken) + f'/comments?replies=1&ctoken={ctoken}') if reply_count == 0: comment['view_replies_text'] = 'Reply' elif reply_count == 1: comment['view_replies_text'] = '1 reply' else: - comment['view_replies_text'] = str(reply_count) + ' replies' + comment['view_replies_text'] = f'{reply_count} replies' if comment['approx_like_count'] == '1': comment['likes_text'] = '1 like' else: - comment['likes_text'] = (str(comment['approx_like_count']) - + ' likes') + comment['likes_text'] = f"{comment['approx_like_count']} likes" comments_info['include_avatars'] = settings.enable_comment_avatars if comments_info['ctoken']: @@ -163,14 +162,13 @@ def video_comments(video_id, sort=0, offset=0, lc='', secret_key=''): comments_info = {'error': None} try: other_sort_url = ( - util.URL_ORIGIN + '/comments?ctoken=' - + make_comment_ctoken(video_id, sort=1 - sort, lc=lc) + f"{util.URL_ORIGIN}/comments?ctoken=" + f"{make_comment_ctoken(video_id, sort=1 - sort, lc=lc)}" ) - other_sort_text = 'Sort by ' + ('newest' if sort == 0 else 'top') + other_sort_text = f'Sort by {"newest" if sort == 0 else "top"}' - this_sort_url = (util.URL_ORIGIN - + '/comments?ctoken=' - + make_comment_ctoken(video_id, sort=sort, lc=lc)) + this_sort_url = (f"{util.URL_ORIGIN}/comments?ctoken=" + f"{make_comment_ctoken(video_id, sort=sort, lc=lc)}") comments_info['comment_links'] = [ (other_sort_text, other_sort_url), @@ -188,17 +186,16 @@ def video_comments(video_id, sort=0, offset=0, lc='', secret_key=''): if e.code == '429' and settings.route_tor: comments_info['error'] = 'Error: YouTube blocked the request because the Tor exit node is overutilized.' if e.error_message: - comments_info['error'] += '\n\n' + e.error_message - comments_info['error'] += '\n\nExit node IP address: %s' % e.ip + comments_info['error'] += f'\n\n{e.error_message}' + comments_info['error'] += f'\n\nExit node IP address: {e.ip}' else: - comments_info['error'] = 'YouTube blocked the request. Error: %s' % str(e) + comments_info['error'] = f'YouTube blocked the request. Error: {e}' except Exception as e: - comments_info['error'] = 'YouTube blocked the request. Error: %s' % str(e) + comments_info['error'] = f'YouTube blocked the request. Error: {e}' if comments_info.get('error'): - print('Error retrieving comments for ' + str(video_id) + ':\n' + - comments_info['error']) + print(f'Error retrieving comments for {video_id}:\n{comments_info["error"]}') return comments_info @@ -218,12 +215,10 @@ def get_comments_page(): 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']) + f'{util.URL_ORIGIN}/comments?ctoken=' + f'{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') + other_sort_text = f'Sort by {"newest" if comments_info["sort"] == 0 else "top"}' comments_info['comment_links'] = [(other_sort_text, other_sort_url)] return flask.render_template( |
