Files
FileStreamBot/WebStreamer/bot/plugins/stream.py

134 lines
6.8 KiB
Python
Raw Normal View History

2021-05-15 23:37:14 +05:30
# (c) @Avishkarpatil
2021-04-16 19:37:44 +05:30
2022-01-02 19:22:16 +05:30
2021-04-20 15:14:57 +06:00
import asyncio
2022-01-02 19:22:16 +05:30
import urllib.parse
2021-04-16 19:37:44 +05:30
from WebStreamer.bot import StreamBot
2021-04-20 15:14:57 +06:00
from WebStreamer.utils.database import Database
from WebStreamer.utils.human_readable import humanbytes
2021-04-16 19:37:44 +05:30
from WebStreamer.vars import Var
2021-04-20 15:14:57 +06:00
from pyrogram import filters, Client
from pyrogram.errors import FloodWait, UserNotParticipant
2021-04-16 19:37:44 +05:30
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
2021-04-20 15:14:57 +06:00
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)
2021-04-16 19:37:44 +05:30
2022-01-02 19:22:16 +05:30
def get_media_file_size(m):
media = m.video or m.audio or m.document
if media and media.file_size:
return media.file_size
else:
return None
def get_media_file_name(m):
media = m.video or m.document or m.audio
if media and media.file_name:
return urllib.parse.quote_plus(media.file_name)
else:
return None
2021-04-20 15:14:57 +06:00
@StreamBot.on_message(filters.private & (filters.document | filters.video | filters.audio) & ~filters.edited, group=4)
async def private_receive_handler(c: Client, m: Message):
if not await db.is_user_exist(m.from_user.id):
await db.add_user(m.from_user.id)
await c.send_message(
Var.BIN_CHANNEL,
2021-06-05 12:43:43 +05:30
f"Nᴇ Usᴇʀ Jɪɴᴇᴅ : \n\nNᴀᴍᴇ : [{m.from_user.first_name}](tg://user?id={m.from_user.id}) Sᴛᴀʀᴛᴇᴅ Yʀ Bᴛ !!"
2021-04-20 15:14:57 +06:00
)
2021-05-24 17:56:56 +05:30
if Var.UPDATES_CHANNEL != "None":
2021-04-20 15:14:57 +06:00
try:
user = await c.get_chat_member(Var.UPDATES_CHANNEL, m.chat.id)
if user.status == "kicked":
await c.send_message(
chat_id=m.chat.id,
2021-06-05 12:43:43 +05:30
text="__Sʀʀʏ Sɪʀ, Y ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ sᴇ ᴍᴇ.__\n\n **Cɴᴛᴀᴛ Dᴇᴇʟᴘᴇʀ @Avishkarpatil Tʜᴇʏ Wɪʟʟ Hᴇʟᴘ Y**",
2021-04-20 15:14:57 +06:00
parse_mode="markdown",
disable_web_page_preview=True
)
return
except UserNotParticipant:
await c.send_message(
chat_id=m.chat.id,
2021-05-15 23:37:14 +05:30
text="""<i>Jɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜꜱᴇ ᴍᴇ 🔐</i>""",
2021-04-20 15:14:57 +06:00
reply_markup=InlineKeyboardMarkup(
2021-07-01 15:57:43 +05:30
[[ InlineKeyboardButton("Jɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Var.UPDATES_CHANNEL}") ]]
2021-04-20 15:14:57 +06:00
),
2021-05-15 23:37:14 +05:30
parse_mode="HTML"
2021-04-20 15:14:57 +06:00
)
return
except Exception:
await c.send_message(
chat_id=m.chat.id,
2021-06-05 12:43:43 +05:30
text="**Sᴍᴇᴛʜɪɴɢ ᴡᴇɴᴛ Wʀɴɢ. Cɴᴛᴀᴛ ᴍʏ ʙss** @Avishkarpatil",
2021-04-20 15:14:57 +06:00
parse_mode="markdown",
disable_web_page_preview=True)
return
try:
log_msg = await m.forward(chat_id=Var.BIN_CHANNEL)
2022-01-02 19:22:16 +05:30
file_name = get_media_file_name(m)
file_size = humanbytes(get_media_file_size(m))
stream_link = "https://{}/{}/{}".format(Var.FQDN, log_msg.message_id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}/{}".format(Var.FQDN,
2021-04-20 15:14:57 +06:00
Var.PORT,
2022-01-02 19:22:16 +05:30
log_msg.message_id,
file_name)
2021-04-20 15:14:57 +06:00
2021-05-15 23:37:14 +05:30
msg_text ="""
2021-07-02 11:34:28 +05:30
<i><u>𝗬𝗼𝘂𝗿 𝗟𝗶𝗻𝗸 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱 !</u></i>\n
<b>📂 Fɪʟᴇ ɴᴀᴍᴇ :</b> <i>{}</i>\n
<b>📦 Fɪʟᴇ ꜱɪᴢᴇ :</b> <i>{}</i>\n
<b>📥 Dɴʟᴀᴅ :</b> <i>{}</i>\n
2021-07-11 15:22:48 +05:30
<b>🚸 Nᴛᴇ : ɪs ᴘᴇʀᴍᴀɴᴇɴᴛ Lɪɴᴋ, N Exᴘɪʀᴇᴅ</b>\n
2021-06-05 12:43:43 +05:30
<i>© @AvishkarPatil </i>"""
2021-05-15 23:37:14 +05:30
await log_msg.reply_text(text=f"**RᴇQᴛᴇᴅ ʙʏ :** [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n**Uᴇʀ ɪᴅ :** `{m.from_user.id}`\n**Dɴʟᴀᴅ ʟɪɴᴋ :** {stream_link}", disable_web_page_preview=True, parse_mode="Markdown", quote=True)
2021-04-20 15:14:57 +06:00
await m.reply_text(
text=msg_text.format(file_name, file_size, stream_link),
2021-05-15 23:37:14 +05:30
parse_mode="HTML",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Dɴʟᴀᴅ ɴᴏᴡ 📥", url=stream_link)]]),
2021-04-20 15:14:57 +06:00
quote=True
)
except FloodWait as e:
print(f"Sleeping for {str(e.x)}s")
await asyncio.sleep(e.x)
2021-06-05 12:43:43 +05:30
await c.send_message(chat_id=Var.BIN_CHANNEL, text=f"Gᴛ FʟᴅWᴀɪᴛ ᴏғ {str(e.x)}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(m.from_user.id)}`", disable_web_page_preview=True, parse_mode="Markdown")
2021-04-20 15:14:57 +06:00
@StreamBot.on_message(filters.channel & (filters.document | filters.video) & ~filters.edited, group=-1)
async def channel_receive_handler(bot, broadcast):
if int(broadcast.chat.id) in Var.BANNED_CHANNELS:
await bot.leave_chat(broadcast.chat.id)
return
try:
log_msg = await broadcast.forward(chat_id=Var.BIN_CHANNEL)
2021-06-05 12:56:00 +05:30
stream_link = "https://{}/{}".format(Var.FQDN, log_msg.message_id) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}".format(Var.FQDN,
Var.PORT,
log_msg.message_id)
2021-04-20 15:14:57 +06:00
await log_msg.reply_text(
2022-01-02 19:22:16 +05:30
text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}",
2021-08-25 18:43:53 +05:30
# text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}",
2021-04-20 15:14:57 +06:00
quote=True,
parse_mode="Markdown"
)
await bot.edit_message_reply_markup(
chat_id=broadcast.chat.id,
message_id=broadcast.message_id,
reply_markup=InlineKeyboardMarkup(
2022-01-02 19:22:16 +05:30
[[InlineKeyboardButton("Dɴʟᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}")]])
2021-08-25 18:43:53 +05:30
# [[InlineKeyboardButton("Dɴʟᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}")]])
2021-04-20 15:14:57 +06:00
)
except FloodWait as w:
print(f"Sleeping for {str(w.x)}s")
await asyncio.sleep(w.x)
await bot.send_message(chat_id=Var.BIN_CHANNEL,
2021-06-05 12:43:43 +05:30
text=f"Gᴛ FʟᴅWᴀɪᴛ ᴏғ {str(w.x)}s from {broadcast.chat.title}\n\n**Cʜᴀɴɴᴇʟ ID:** `{str(broadcast.chat.id)}`",
2021-04-20 15:14:57 +06:00
disable_web_page_preview=True, parse_mode="Markdown")
except Exception as e:
2021-06-05 13:06:06 +05:30
await bot.send_message(chat_id=Var.BIN_CHANNEL, text=f"**#ᴇʀʀʀ_ᴛʀᴀᴇʙᴀᴋ:** `{e}`", disable_web_page_preview=True, parse_mode="Markdown")
2021-06-05 12:43:43 +05:30
print(f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴀᴅᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀʀ: {e}")