aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/account_functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'youtube/account_functions.py')
-rw-r--r--youtube/account_functions.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/youtube/account_functions.py b/youtube/account_functions.py
index 9b75c27..985f7d1 100644
--- a/youtube/account_functions.py
+++ b/youtube/account_functions.py
@@ -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:
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})"''')
def post_comment(query_string, fields):
@@ -96,7 +120,8 @@ def post_comment(query_string, fields):
else:
_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))
-
+
+
def get_post_comment_page(query_string):
parameters = urllib.parse.parse_qs(query_string)