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

Commit dfa4e35

Browse files
committed
pin and remove a pinned comment
#38
1 parent 34d02e3 commit dfa4e35

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

ItsAGramLive/ItsAGramLive.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ItsAGramLive:
3737
broadcast_id: int = None
3838
stream_key: str = None
3939
stream_server: str = None
40+
pinned_comment_id: str = None
4041

4142
DEVICE_SETS = {
4243
"app_version": "136.0.0.34.124",
@@ -285,13 +286,16 @@ def start(self):
285286
elif cmd == 'comments':
286287
self.get_comments()
287288

288-
elif cmd[:11] == 'pin comment':
289-
to_send = cmd[12:]
289+
elif cmd[:3] == 'pin':
290+
to_send = cmd[4:]
290291
if to_send:
291292
self.pin_comment(to_send)
292293
else:
293294
print('usage: chat <text to chat>')
294295

296+
elif cmd[:5] == 'unpin':
297+
self.unpin_comment()
298+
295299
elif cmd[:4] == 'chat':
296300
to_send = cmd[5:]
297301
if to_send:
@@ -514,18 +518,32 @@ def get_comments(self):
514518
def pin_comment(self, to_send):
515519
if self.send_comment(msg=to_send):
516520
if self.send_request("live/{}/get_comment/".format(self.broadcast_id)):
521+
for comment in [comment for comment in self.LastJson['comments']]:
522+
if comment.get("text") == to_send:
523+
self.pinned_comment_id = comment.get("pk")
517524
data = json.dumps(
518525
{
519526
"_csrftoken": self.token,
520527
"_uid": self.username_id,
521528
"_uuid": self.uuid,
522-
"comment_id": self.LastJson['comments'][-1].get("pk")
529+
"comment_id": self.pinned_comment_id
523530
})
524531
if self.send_request(endpoint='live/{}/pin_comment/'.format(self.broadcast_id),
525532
post=self.generate_signature(data)):
526-
print('Live Posted to Story!')
527-
self.unmute_comment()
533+
print('Comment pinned!')
528534
return True
529535

530-
self.unmute_comment()
536+
return False
537+
538+
def unpin_comment(self):
539+
data = json.dumps({
540+
"_csrftoken": self.token,
541+
"_uid": self.username_id,
542+
"_uuid": self.uuid,
543+
"comment_id": self.pinned_comment_id
544+
})
545+
if self.send_request(endpoint='live/{}/unpin_comment/'.format(self.broadcast_id),
546+
post=self.generate_signature(data)):
547+
print('Comment unpinned!')
548+
return True
531549
return False

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ python3 live_broadcast_ffmpeg.py -u yourInstagramUsername -p yourPassword -f /pa
107107
List viewers
108108
- **chat**
109109
Send a comment
110+
- **pin**
111+
Send a comment and pin it
112+
- **unpin**
113+
Remove a pinned comment
110114
- **comments**
111115
Get the list of comments
112116
- **wave**

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setuptools.setup(
1212
name='ItsAGramLive',
13-
version='1.4.5',
13+
version='1.5.5',
1414
packages=setuptools.find_packages(),
1515
url='https://github.com/harrypython/itsagramlive',
1616
license='GPL-3.0',

0 commit comments

Comments
 (0)