Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
pin and remove a pinned comment
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypython committed Jan 22, 2021
1 parent 34d02e3 commit dfa4e35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
30 changes: 24 additions & 6 deletions ItsAGramLive/ItsAGramLive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 <text to chat>')

elif cmd[:5] == 'unpin':
self.unpin_comment()

elif cmd[:4] == 'chat':
to_send = cmd[5:]
if to_send:
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit dfa4e35

Please sign in to comment.