diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-07-13 17:16:29 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-07-13 17:16:29 -0700 |
commit | 97545f9b3b74044f62c93baaff9ad32f9073d217 (patch) | |
tree | 1ed7c7591374bb4e042370091e224e8686965418 /youtube/comments.py | |
parent | 2ffc727b51255bbaffe1636a023eb9eb7ce1c19b (diff) | |
download | yt-local-97545f9b3b74044f62c93baaff9ad32f9073d217.tar.lz yt-local-97545f9b3b74044f62c93baaff9ad32f9073d217.tar.xz yt-local-97545f9b3b74044f62c93baaff9ad32f9073d217.zip |
add settings for enabling/disabling comments, comment avatars, & related vids
Diffstat (limited to 'youtube/comments.py')
-rw-r--r-- | youtube/comments.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/youtube/comments.py b/youtube/comments.py index 4a00292..45a8f44 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -6,11 +6,12 @@ from string import Template import urllib.request import urllib import html +import settings comment_template = Template(''' <div class="comment-container"> <div class="comment"> <a class="author-avatar" href="$author_url" title="$author"> - <img class="author-avatar-img" src="$author_avatar"> +$avatar </a> <address> <a class="author" href="$author_url" title="$author">$author</a> @@ -23,6 +24,8 @@ $replies </div> ''') +comment_avatar_template = Template(''' <img class="author-avatar-img" src="$author_avatar">''') + reply_link_template = Template(''' <a href="$url" class="replies">View replies</a> ''') @@ -143,10 +146,17 @@ def get_comments_html(result): replies = '' if comment['replies_url']: replies = reply_link_template.substitute(url=comment['replies_url']) + if settings.enable_comment_avatars: + avatar = comment_avatar_template.substitute( + author_url = URL_ORIGIN + comment['author_url'], + author_avatar = '/' + comment['author_avatar'], + ) + else: + avatar = '' html_result += comment_template.substitute( author=html.escape(comment['author']), author_url = URL_ORIGIN + comment['author_url'], - author_avatar = '/' + comment['author_avatar'], + avatar = avatar, likes = str(comment['likes']) + ' likes' if str(comment['likes']) != '0' else '', published = comment['published'], text = format_text_runs(comment['text']), @@ -157,8 +167,10 @@ def get_comments_html(result): return html_result, result['ctoken'] def video_comments(video_id, sort=0, offset=0, secret_key=''): - result = parse_comments(request_comments(make_comment_ctoken(video_id, sort, offset, secret_key))) - return get_comments_html(result) + if settings.enable_comments: + result = parse_comments(request_comments(make_comment_ctoken(video_id, sort, offset, secret_key))) + return get_comments_html(result) + return '', '' more_comments_template = Template('''<a class="page-button more-comments" href="$url">More comments</a>''') |