Create storydl.py
Browse files- Akeno/plugins/storydl.py +97 -0
Akeno/plugins/storydl.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
+
import io
|
4 |
+
from pyrogram import Client, filters
|
5 |
+
from pyrogram.types import *
|
6 |
+
from pyrogram import *
|
7 |
+
from pyrogram.errors import *
|
8 |
+
from pyrogram import Client as ren
|
9 |
+
from Akeno.utils.handler import *
|
10 |
+
from Akeno.utils.scripts import progress
|
11 |
+
|
12 |
+
@Akeno(
|
13 |
+
~filters.scheduled
|
14 |
+
& filters.command(["hpyer", "hyper", "hek"])
|
15 |
+
& filters.me
|
16 |
+
& ~filters.forwarded
|
17 |
+
)
|
18 |
+
async def hyperok(client: Client, message: Message):
|
19 |
+
link = message.text.split(" ", 1)[1] if len(message.command) > 1 else None
|
20 |
+
if not link:
|
21 |
+
return
|
22 |
+
then_do = link.split("/")
|
23 |
+
developed_by_me = int(then_do[-1])
|
24 |
+
text = f">> [{developed_by_me}]({link})"
|
25 |
+
await message.edit_text(text, disable_web_page_preview=True)
|
26 |
+
|
27 |
+
@Akeno(
|
28 |
+
~filters.scheduled
|
29 |
+
& filters.command(["copy"])
|
30 |
+
& filters.me
|
31 |
+
& ~filters.forwarded
|
32 |
+
)
|
33 |
+
async def get_story_dl(client: Client, message: Message):
|
34 |
+
command, *options = message.text.split(" ", 2) if message.command else [None, []]
|
35 |
+
if not command:
|
36 |
+
await message.reply_text("Invalid command")
|
37 |
+
return
|
38 |
+
copy_chat = False
|
39 |
+
copy_story = False
|
40 |
+
for option in options:
|
41 |
+
if option == "-c":
|
42 |
+
copy_chat = True
|
43 |
+
elif option == "-s":
|
44 |
+
copy_story = True
|
45 |
+
text_link = options[-1] if options else None
|
46 |
+
if not text_link or not text_link.startswith("https://t.me/"):
|
47 |
+
await message.reply_text("Invalid story or copy(chats) link")
|
48 |
+
return
|
49 |
+
try:
|
50 |
+
target_link = text_link.split("/c/") if "/c/" in text_link else text_link.split("/")
|
51 |
+
random_id = int(target_link[-1].split("/")[-1]) if len(target_link) > 1 else None
|
52 |
+
desired_username = target_link[3] if len(target_link) > 3 else None
|
53 |
+
username = "@" + desired_username if desired_username else "-100" + target_link[1].split("/")[0] if len(target_link) > 1 else None
|
54 |
+
if copy_chat and copy_story:
|
55 |
+
await message.reply_text("Invalid options. Choose either -c or -s.")
|
56 |
+
return
|
57 |
+
elif copy_chat:
|
58 |
+
await client.copy_message(message.chat.id, from_chat_id=username, message_id=random_id, protect_content=True)
|
59 |
+
elif copy_story:
|
60 |
+
stories = await client.get_stories(username, story_ids=[random_id])
|
61 |
+
if stories:
|
62 |
+
for story in stories:
|
63 |
+
file_id = (
|
64 |
+
story.photo.file_id if story and story.photo else None
|
65 |
+
or story.video.file_id if story and story.video else None
|
66 |
+
)
|
67 |
+
caption = story.caption or f"By {client.me.mention}"
|
68 |
+
if file_id:
|
69 |
+
documents = await client.download_media(file_id)
|
70 |
+
if documents.endswith((".mp4", ".gif")):
|
71 |
+
send_function = client.send_video
|
72 |
+
else:
|
73 |
+
send_function = client.send_photo
|
74 |
+
pro = await message.reply_text("Processing...")
|
75 |
+
seconds_time = time.time()
|
76 |
+
await send_function(
|
77 |
+
message.chat.id,
|
78 |
+
documents,
|
79 |
+
caption=caption,
|
80 |
+
progress=progress,
|
81 |
+
progress_args=(pro, seconds_time, "Processing..."))
|
82 |
+
|
83 |
+
)
|
84 |
+
await pro.delete()
|
85 |
+
os.remove(documents)
|
86 |
+
else:
|
87 |
+
await client.send_message(message.chat.id, f"Error: No stories found for {username}")
|
88 |
+
else:
|
89 |
+
await message.reply_text("Invalid options. Choose either -c or -s.")
|
90 |
+
except ValueError as e:
|
91 |
+
await message.reply_text(f"Error parsing for {username}: {e}")
|
92 |
+
except ChatWriteForbidden as e:
|
93 |
+
await message.reply_text(f"Error: Bot doesn't have permission to write in the channel {username}")
|
94 |
+
except UserIsBlocked as e:
|
95 |
+
await message.reply_text(f"Error: Bot is blocked by the user {username}")
|
96 |
+
except Exception as e:
|
97 |
+
await message.reply_text(f"Error retrieving or sending for {username}: {e}")
|