diff --git a/misskaty/plugins/download_upload.py b/misskaty/plugins/download_upload.py
index aea2955a..0536cf0e 100644
--- a/misskaty/plugins/download_upload.py
+++ b/misskaty/plugins/download_upload.py
@@ -3,9 +3,13 @@
# * @projectName MissKatyPyro
# * Copyright ©YasirPedia All rights reserved
import asyncio
+import cloudscraper
import math
import os
+import re
import time
+from bs4 import BeautifulSoup
+from cloudscraper import create_scraper
from datetime import datetime
from logging import getLogger
from urllib.parse import unquote
@@ -31,6 +35,8 @@ __HELP__ = """
/tgraph_up [reply_to_TG_File] - Download TG File
/tiktokdl [link] - Download TikTok Video, try use ytdown command if error.
/fbdl [link] - Download Facebook Video.
+/instadl [link] - Download photo or video from instagram (Only first post).
+/twitterdl [link] - Dowload video from Twitter aka X.
/anon [link] - Upload files to Anonfiles.
/ytdown [YT-DLP Supported URL] - Downloading YT-DLP Supported Video and Audio.
"""
@@ -168,6 +174,99 @@ async def download(client, message):
)
+@app.on_message(filters.command(["instadl"], COMMAND_HANDLER))
+@capture_err
+@ratelimiter
+async def instadl(_, message):
+ if len(message.command) == 1:
+ return await message.reply(
+ f"Use command /{message.command[0]} [link] to download Instagram Photo or Video."
+ )
+ link = message.command[1]
+ msg = await message.reply("Trying download...")
+ try:
+ headers = {
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0",
+ "Accept": "*/*",
+ "Accept-Language": "en-US,en;q=0.5",
+ "Accept-Encoding": "gzip, deflate, br",
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
+ "X-Requested-With": "XMLHttpRequest",
+ "Content-Length": "99",
+ "Origin": "https://saveig.app",
+ "Connection": "keep-alive",
+ "Referer": "https://saveig.app/id",
+ }
+ post = create_scraper().post("https://saveig.app/api/ajaxSearch", data={"q": link, "t": "media", "lang": "id"}, headers=headers)
+ if post.status_code not in [200, 401]:
+ return await message.reply("Unknown error.")
+ res = post.json()
+ if r := re.findall('href="(https?://(?!play\.google\.com|/)[^"]+)"', res["data"]):
+ res = r[0].replace("&", "&")
+ fname = (await fetch.head(res)).headers.get("content-disposition", "").split("filename=")[1]
+ is_img = (await fetch.head(res)).headers.get("content-type").startswith("image")
+ if is_img:
+ await message.reply_photo(res, caption=fname)
+ await message.reply_video(res, caption=fname)
+ await msg.delete()
+ except Exception as e:
+ await message.reply(f"Failed to download instagram video..\n\nReason: {e}")
+ await msg.delete()
+
+
+@app.on_message(filters.command(["twitterdl"], COMMAND_HANDLER))
+@capture_err
+@ratelimiter
+async def twitter(_, message):
+ if len(message.command) == 1:
+ return await message.reply(
+ f"Use command /{message.command[0]} [link] to download Twitter video."
+ )
+ url = message.command[1]
+ if "x.com" in url:
+ url = url.replace("x.com", "twitter.com")
+ msg = await message.reply("Trying download...")
+ try:
+ headers = {
+ "Host": "ssstwitter.com",
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0",
+ "Accept": "*/*",
+ "Accept-Language": "en-US,en;q=0.5",
+ "Accept-Encoding": "gzip, deflate, br",
+ "HX-Request": "true",
+ "Origin": "https://ssstwitter.com",
+ "Referer": "https://ssstwitter.com/id",
+ "Cache-Control": "no-cache",
+ }
+ data = {
+ "id": url,
+ "locale": "id",
+ "tt": "bc9841580b5d72e855e7d01bf3255278l",
+ "ts": "1691416179",
+ "source": "form",
+ }
+ post = await fetch.post(f"https://ssstwitter.com/id", data=data, headers=headers, follow_redirects=True)
+ if post.status_code not in [200, 401]:
+ return await msg.edit_msg("Unknown error.")
+ soup = BeautifulSoup(post.text, "lxml")
+ cekdata = soup.find("a", {"pure-button pure-button-primary is-center u-bl dl-button download_link without_watermark vignette_active"})
+ if not cekdata:
+ return await message.reply("ERROR: Oops! It seems that this tweet doesn't have a video! Try later or check your link")
+ try:
+ fname = (await fetch.head(cekdata.get("href"))).headers.get("content-disposition", "").split("filename=")[1]
+ obj = SmartDL(cekdata.get("href"), progress_bar=False, timeout=15)
+ obj.start()
+ path = obj.get_dest()
+ await message.reply_video(path, caption=f"{fname}\n\nUploaded for {message.from_user.mention} [{message.from_user.id}]",)
+ except Exception as er:
+ LOGGING.error(f"ERROR: while fetching TwitterDL. {er}")
+ return await msg.edit_msg("ERROR: Got error while extracting link.")
+ await msg.delete()
+ except Exception as e:
+ await message.reply(f"Failed to download twitter video..\n\nReason: {e}")
+ await msg.delete()
+
+
@app.on_message(filters.command(["tiktokdl"], COMMAND_HANDLER))
@capture_err
@ratelimiter
@@ -180,11 +279,13 @@ async def tiktokdl(_, message):
msg = await message.reply("Trying download...")
try:
r = (
- await fetch.get(f"https://apimu.my.id/downloader/tiktok3?link={link}")
+ await fetch.post(f"https://lovetik.com/api/ajax/search", data={"query": link})
).json()
+ fname = (await fetch.head(r["links"][0]["a"])).headers.get("content-disposition", "")
+ filename = unquote(fname.split('filename=')[1].strip('"').split('"')[0])
await message.reply_video(
- r["hasil"]["download_mp4_hd"],
- caption=f"Title: {r['hasil']['video_title']}\nUploader: {r['hasil']['name']}\n👍: {r['hasil']['like']} 🔁: {r['hasil']['share']} 💬: {r['hasil']['comment']}\n\nUploaded for {message.from_user.mention} [{message.from_user.id}]",
+ r["links"][0]["a"],
+ caption=f"Title: {filename}\nUploader: {r['author_name']}\n\nUploaded for {message.from_user.mention} [{message.from_user.id}]",
)
await msg.delete()
except Exception as e:
@@ -194,6 +295,7 @@ async def tiktokdl(_, message):
@app.on_message(filters.command(["fbdl"], COMMAND_HANDLER))
@capture_err
+@new_task
async def fbdl(_, message):
if len(message.command) == 1:
return await message.reply(
@@ -207,7 +309,7 @@ async def fbdl(_, message):
url = resjson["result"]["hd"]
except KeyError:
url = resjson["result"]["sd"]
- obj = SmartDL(url, progress_bar=False, timeout=15)
+ obj = SmartDL(url, progress_bar=False, timeout=15, verify=False)
obj.start()
path = obj.get_dest()
await message.reply_video(
diff --git a/misskaty/plugins/genss.py b/misskaty/plugins/genss.py
index d33fb62f..a0db2412 100644
--- a/misskaty/plugins/genss.py
+++ b/misskaty/plugins/genss.py
@@ -48,7 +48,7 @@ async def genss(self: Client, ctx: Message, strings):
url = the_url_parts.strip()
file_name = os.path.basename(url)
download_file_path = os.path.join("downloads/", file_name)
- downloader = SmartDL(url, download_file_path, progress_bar=False, timeout=10)
+ downloader = SmartDL(url, download_file_path, progress_bar=False, timeout=10, verify=False)
try:
downloader.start(blocking=False)
except Exception as err:
diff --git a/misskaty/plugins/nightmodev2.py b/misskaty/plugins/nightmodev2.py
index a9dd47e3..eb322000 100644
--- a/misskaty/plugins/nightmodev2.py
+++ b/misskaty/plugins/nightmodev2.py
@@ -14,6 +14,7 @@ from pyrogram.errors import (
ChannelPrivate,
ChatAdminRequired,
ChatNotModified,
+ ChatRestricted,
PeerIdInvalid,
)
from pyrogram.types import ChatPermissions, InlineKeyboardButton, InlineKeyboardMarkup
@@ -131,13 +132,17 @@ async def un_mute_chat(chat_id: int, perm: ChatPermissions):
else:
job = scheduler.get_job(f"enable_nightmode_{chat_id}")
close_at = job.next_run_time
- await app.send_message(
- chat_id,
- langdict[getlang]["nightmodev2"]["nmd_off_success"].format(
- dt=tglsekarang(), close_at=close_at
- ),
- reply_markup=reply_markup,
- )
+ try:
+ await app.send_message(
+ chat_id,
+ langdict[getlang]["nightmodev2"]["nmd_off_success"].format(
+ dt=tglsekarang(), close_at=close_at
+ ),
+ reply_markup=reply_markup,
+ )
+ except ChatRestricted:
+ scheduler.remove_job(f"enable_nightmode_{chat_id}")
+ scheduler.remove_job(f"disable_nightmode_{chat_id}")
async def mute_chat(chat_id: int):
diff --git a/misskaty/plugins/start_help.py b/misskaty/plugins/start_help.py
index 9842d966..be45e143 100644
--- a/misskaty/plugins/start_help.py
+++ b/misskaty/plugins/start_help.py
@@ -7,6 +7,7 @@
import re
from pyrogram import Client, filters
+from pyrogram.errors import ChatSendPhotosForbidden, ChatWriteForbidden
from pyrogram.types import (
CallbackQuery,
InlineKeyboardButton,
@@ -72,11 +73,14 @@ keyboard = InlineKeyboardMarkup(
async def start(_, ctx: Message, strings):
if ctx.chat.type.value != "private":
nama = ctx.from_user.mention if ctx.from_user else ctx.sender_chat.title
- return await ctx.reply_photo(
- photo="https://telegra.ph/file/90e9a448bc2f8b055b762.jpg",
- caption=strings("start_msg").format(kamuh=nama),
- reply_markup=keyboard,
- )
+ try:
+ return await ctx.reply_photo(
+ photo="https://telegra.ph/file/90e9a448bc2f8b055b762.jpg",
+ caption=strings("start_msg").format(kamuh=nama),
+ reply_markup=keyboard,
+ )
+ except (ChatSendPhotosForbidden, ChatWriteForbidden):
+ return await ctx.chat.leave()
if len(ctx.text.split()) > 1:
name = (ctx.text.split(None, 1)[1]).lower()
if "_" in name:
diff --git a/misskaty/plugins/webss.py b/misskaty/plugins/webss.py
index 7c05eb9a..b99ca565 100644
--- a/misskaty/plugins/webss.py
+++ b/misskaty/plugins/webss.py
@@ -35,7 +35,7 @@ async def take_ss(_, ctx: Message, strings):
msg = await ctx.reply_msg(strings("wait_str"))
try:
url = f"https://webss.yasirapi.eu.org/api?url={url}&width=1280&height=720"
- downloader = SmartDL(url, download_file_path, progress_bar=False, timeout=10)
+ downloader = SmartDL(url, download_file_path, progress_bar=False, timeout=10, verify=False)
downloader.start(blocking=True)
await gather(
*[