From e3fac7da54356c448bd244b578da244b62f44e9e Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 31 Dec 2018 02:52:27 -0800 Subject: Ability to delete comments --- youtube/comments.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'youtube/comments.py') diff --git a/youtube/comments.py b/youtube/comments.py index 58a03ac..1d96545 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -26,10 +26,14 @@ $avatar
$author
- $text + $text + $likes +
$replies +$action_buttons +
@@ -162,6 +166,8 @@ def parse_comments_ajax(content, replies=False): comment = { 'author': comment_raw['author']['runs'][0]['text'], 'author_url': comment_raw['author_endpoint']['url'], + 'author_channel_id': '', + 'author_id': '', 'author_avatar': comment_raw['author_thumbnail']['url'], 'likes': comment_raw['like_count'], 'published': comment_raw['published_time']['runs'][0]['text'], @@ -207,6 +213,7 @@ def parse_comments_polymer(content, replies=False): video_title = comment_raw['commentTargetTitle']['runs'][0]['text'] parent_id = comment_raw['comment']['commentRenderer']['commentId'] + # TODO: move this stuff into the comments_html function if 'replies' in comment_raw: #reply_ctoken = comment_raw['replies']['commentRepliesRenderer']['continuations'][0]['nextContinuationData']['continuation'] #comment_id, video_id = get_ids(reply_ctoken) @@ -226,12 +233,16 @@ def parse_comments_polymer(content, replies=False): comment = { 'author': common.get_plain_text(comment_raw['authorText']), 'author_url': comment_raw['authorEndpoint']['commandMetadata']['webCommandMetadata']['url'], + 'author_channel_id': comment_raw['authorEndpoint']['browseEndpoint']['browseId'], + 'author_id': comment_raw['authorId'], 'author_avatar': comment_raw['authorThumbnail']['thumbnails'][0]['url'], 'likes': comment_raw['likeCount'], 'published': common.get_plain_text(comment_raw['publishedTimeText']), 'text': comment_raw['contentText'].get('runs', ''), 'view_replies_text': view_replies_text, 'replies_url': replies_url, + 'video_id': video_id, + 'comment_id': comment_raw['commentId'], } comments.append(comment) except Exception as e: @@ -256,6 +267,16 @@ def get_comments_html(comments): ) else: avatar = '' + if comment['author_channel_id'] in accounts.accounts: + delete_url = (URL_ORIGIN + '/delete_comment?video_id=' + + comment['video_id'] + + '&channel_id='+ comment['author_channel_id'] + + '&author_id=' + comment['author_id'] + + '&comment_id=' + comment['comment_id']) + + action_buttons = '''Delete''' + else: + action_buttons = '' html_result += comment_template.substitute( author=comment['author'], author_url = URL_ORIGIN + comment['author_url'], @@ -264,8 +285,8 @@ def get_comments_html(comments): published = comment['published'], text = format_text_runs(comment['text']), datetime = '', #TODO - replies=replies, - #replies='', + replies = replies, + action_buttons = action_buttons, ) return html_result -- cgit v1.2.3