From dfa4e355c3b725848d1abd396c1f211f74b7dc01 Mon Sep 17 00:00:00 2001 From: harrypython Date: Fri, 22 Jan 2021 07:01:50 -0800 Subject: [PATCH] pin and remove a pinned comment #38 --- ItsAGramLive/ItsAGramLive.py | 30 ++++++++++++++++++++++++------ README.md | 4 ++++ setup.py | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/ItsAGramLive/ItsAGramLive.py b/ItsAGramLive/ItsAGramLive.py index 8130af8..3b233ef 100644 --- a/ItsAGramLive/ItsAGramLive.py +++ b/ItsAGramLive/ItsAGramLive.py @@ -37,6 +37,7 @@ class ItsAGramLive: broadcast_id: int = None stream_key: str = None stream_server: str = None + pinned_comment_id: str = None DEVICE_SETS = { "app_version": "136.0.0.34.124", @@ -285,13 +286,16 @@ def start(self): elif cmd == 'comments': self.get_comments() - elif cmd[:11] == 'pin comment': - to_send = cmd[12:] + elif cmd[:3] == 'pin': + to_send = cmd[4:] if to_send: self.pin_comment(to_send) else: print('usage: chat ') + elif cmd[:5] == 'unpin': + self.unpin_comment() + elif cmd[:4] == 'chat': to_send = cmd[5:] if to_send: @@ -514,18 +518,32 @@ def get_comments(self): def pin_comment(self, to_send): if self.send_comment(msg=to_send): if self.send_request("live/{}/get_comment/".format(self.broadcast_id)): + for comment in [comment for comment in self.LastJson['comments']]: + if comment.get("text") == to_send: + self.pinned_comment_id = comment.get("pk") data = json.dumps( { "_csrftoken": self.token, "_uid": self.username_id, "_uuid": self.uuid, - "comment_id": self.LastJson['comments'][-1].get("pk") + "comment_id": self.pinned_comment_id }) if self.send_request(endpoint='live/{}/pin_comment/'.format(self.broadcast_id), post=self.generate_signature(data)): - print('Live Posted to Story!') - self.unmute_comment() + print('Comment pinned!') return True - self.unmute_comment() + return False + + def unpin_comment(self): + data = json.dumps({ + "_csrftoken": self.token, + "_uid": self.username_id, + "_uuid": self.uuid, + "comment_id": self.pinned_comment_id + }) + if self.send_request(endpoint='live/{}/unpin_comment/'.format(self.broadcast_id), + post=self.generate_signature(data)): + print('Comment unpinned!') + return True return False diff --git a/README.md b/README.md index 6791108..4bf9f17 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ python3 live_broadcast_ffmpeg.py -u yourInstagramUsername -p yourPassword -f /pa List viewers - **chat** Send a comment +- **pin** + Send a comment and pin it +- **unpin** + Remove a pinned comment - **comments** Get the list of comments - **wave** diff --git a/setup.py b/setup.py index 0bddc12..745998a 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setuptools.setup( name='ItsAGramLive', - version='1.4.5', + version='1.5.5', packages=setuptools.find_packages(), url='https://github.com/harrypython/itsagramlive', license='GPL-3.0',