Skip to content

Commit

Permalink
lexica: add instagram downlloader
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiTheModder committed Aug 9, 2024
1 parent 802bb45 commit 0742c61
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion modules/lexica.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os
import re
import time
from bs4 import BeautifulSoup
import requests

from pyrogram import Client, filters
from pyrogram.types import Message

from utils.misc import modules_help, prefix
from utils.scripts import format_exc, format_module_help
from utils.scripts import format_exc, format_module_help, progress
from utils.lexicapi import ImageGeneration, UpscaleImages, ImageModels


Expand Down Expand Up @@ -95,7 +98,69 @@ async def lgen(client: Client, message: Message):
await message.edit(format_exc(e))


@Client.on_message(filters.command("linsta", prefix) & filters.me)
async def linsta(client: Client, message: Message):
if len(message.command) < 2:
return await message.edit_text(
f"<b>Usage: </b><code>{prefix}linsta [link]*</code>"
)
link = message.text.split(maxsplit=1)[1]
url = f"https://social-dl.vercel.app/api/download?url={link}&platform=Instagram"
await message.edit_text("<code>Processing...</code>")
try:
response = requests.post(url)
if response.status_code == 200:
if response.json().get("code") == 2:
if response.json().get("message") == "success":
download_url = response.json().get("content")[0].get("url")
soup = BeautifulSoup(requests.get(link).text, "html.parser")
title = soup.find("meta", property="og:title")
if title:
title_text = title["content"]
title_text = re.sub(r"#\w+", "", title_text)
title_text = title_text.replace("\n", "")
title_text = re.sub(" +", " ", title_text)
if ".mp4" in download_url:
ext = ".mp4"
elif ".jpg" in download_url:
ext = ".jpg"
elif ".png" in download_url:
ext = ".png"
elif ".webp" in download_url:
ext = ".webp"
elif ".gif" in download_url:
ext = ".gif"
with open(f"video_insta{ext}", "wb") as f:
f.write(requests.get(download_url).content)
await message.edit_text(
"Video downloaded successfully... Uploading"
)
await client.send_video(
message.chat.id,
f"video_insta{ext}",
caption=f"<b>Title: </b><code>{title_text}</code>",
progress=progress,
progress_args=(
message,
time.time(),
"Video downloaded successfully... Uploading",
),
)
if os.path.exists(f"video_insta{ext}"):
os.remove(f"video_insta{ext}")
await message.delete()
else:
await message.edit_text("Error: Failed to retrieve download URL")
else:
await message.edit_text("Error: Invalid response format")
else:
await message.edit_text("Error: Failed to send request")
except Exception as e:
await message.edit_text(format_exc(e))


modules_help["lexica"] = {
"lgen [model_id]* [prompt/reply to prompt]*": "Generate Image with Lexica API",
"upscale [cap/reply to image]*": "Upscale Image through Lexica API",
"linsta [link]*": "Download Instagram Media",
}

0 comments on commit 0742c61

Please sign in to comment.