comment deletion function

This commit is contained in:
James Taylor 2018-09-05 21:25:58 -07:00
parent 46cfd682ce
commit e31fd60286

View File

@ -64,7 +64,31 @@ def _post_comment_reply(text, video_id, parent_comment_id, session_token, cookie
'''with open('debug/post_comment_response', 'wb') as f: '''with open('debug/post_comment_response', 'wb') as f:
f.write(content)''' f.write(content)'''
def delete_comment(video_id, comment_id, author_id, session_token, cookie):
headers = {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'X-YouTube-Client-Name': '2',
'X-YouTube-Client-Version': '2.20180823',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': cookie,
}
action = proto.uint(1,6) + proto.string(3, comment_id) + proto.string(5, video_id) + proto.string(9, author_id)
action = proto.percent_b64encode(action).decode('ascii')
sej = json.dumps({"clickTrackingParams":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","commandMetadata":{"webCommandMetadata":{"url":"/service_ajax","sendPost":True}},"performCommentActionEndpoint":{"action":action}})
data_dict = {
'sej': sej,
'session_token': session_token,
}
data = urllib.parse.urlencode(data_dict).encode()
req = urllib.request.Request("https://m.youtube.com/service_ajax?name=performCommentActionEndpoint", headers=headers, data=data)
response = urllib.request.urlopen(req, timeout = 5)
content = response.read()
xsrf_token_regex = re.compile(r'''XSRF_TOKEN"\s*:\s*"([\w-]*(?:=|%3D){0,2})"''') xsrf_token_regex = re.compile(r'''XSRF_TOKEN"\s*:\s*"([\w-]*(?:=|%3D){0,2})"''')
def post_comment(query_string, fields): def post_comment(query_string, fields):
@ -96,7 +120,8 @@ def post_comment(query_string, fields):
else: else:
_post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data) _post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data)
return comments.get_comments_page('ctoken=' + comments.make_comment_ctoken(video_id, sort=1)) return comments.get_comments_page('ctoken=' + comments.make_comment_ctoken(video_id, sort=1))
def get_post_comment_page(query_string): def get_post_comment_page(query_string):
parameters = urllib.parse.parse_qs(query_string) parameters = urllib.parse.parse_qs(query_string)