Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ wolframalpha==3.0
pyquery==1.2.17
python-twitter==3.3
lxml==4.8.0
insta-scrape==2.1.2
git+https://github.com/Zulko/moviepy.git@1c5c6336602f6164b38d27a6dbfa3ed5c5f7c402
54 changes: 54 additions & 0 deletions modules/user_inst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import re
import time

from modules.utils import http
from instascrape import Reel


async def main(bot, *args, **kwargs):
"""
inst <Reel URL>
Get reels media by link
"""
file_path = None
try:
inst_options = getattr(bot.settings, 'inst_keys', None)
if not inst_options:
return 'Module is not configured. You must set `inst_keys` in settings'
# session id
SESSIONID = inst_options['sessionid']

# Header with session id
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)\
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 \
Safari/537.36 Edg/79.0.309.43",
"cookie": f'sessionid={SESSIONID};'
}

url = args[0] if args else None
if not url or not re.match(r'^https://(www\.)?instagram.com/', url):
return 'Nothing to download'

# Passing Instagram reel link as argument in Reel Module
insta_reel = Reel(url)

chat_id = kwargs.get('chat_id')
bot.pre_send(chat_id=chat_id, action='upload_video')

# Using scrape function and passing the headers
insta_reel.scrape(headers=headers)

file_path = f"./tmp/reel{int(time.time())}.mp4"
# Giving path where we want to download reel to the
# download function
insta_reel.download(fp=file_path)

files = {'video': (file_path, open(file_path, 'rb'), 'video/mp4')}
data = {'chat_id': chat_id, 'disable_notification': True}
telegram_response = bot.call('sendVideo', 'POST', data=data, files=files)
except Exception as e:
return f"Polomkah: {e}"
finally:
file_path and os.path.exists(file_path) and os.remove(file_path)
5 changes: 4 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
'access_token_key': '',
'access_token_secret': ''
}
channel_id = ''
channel_id = ''
inst_keys = {
'sessionid': ''
}