Spaces:
Sleeping
Sleeping
Commit
·
a6fe6f9
1
Parent(s):
92b623a
new update
Browse files- bot/config.py +1 -1
- bot/modules/static.py +26 -0
- bot/plugins/files.py +25 -3
- bot/server/main.py +2 -2
- bot/utils/__init__.py +2 -1
- bot/utils/util.py +13 -0
bot/config.py
CHANGED
|
@@ -8,7 +8,7 @@ class Telegram:
|
|
| 8 |
BOT_USERNAME = env.get("TELEGRAM_BOT_USERNAME", "xxxx_streambot")
|
| 9 |
BOT_TOKEN = env.get("TELEGRAM_BOT_TOKEN", "1234567:xyz")
|
| 10 |
CHANNEL_ID = int(env.get("TELEGRAM_CHANNEL_ID", -1001684936508))
|
| 11 |
-
SECRET_CODE_LENGTH = int(env.get("SECRET_CODE_LENGTH",
|
| 12 |
|
| 13 |
class Server:
|
| 14 |
BASE_URL = env.get("BASE_URL", "https://kawaiimizo-maakichu.hf.space")
|
|
|
|
| 8 |
BOT_USERNAME = env.get("TELEGRAM_BOT_USERNAME", "xxxx_streambot")
|
| 9 |
BOT_TOKEN = env.get("TELEGRAM_BOT_TOKEN", "1234567:xyz")
|
| 10 |
CHANNEL_ID = int(env.get("TELEGRAM_CHANNEL_ID", -1001684936508))
|
| 11 |
+
SECRET_CODE_LENGTH = int(env.get("SECRET_CODE_LENGTH", 10))
|
| 12 |
|
| 13 |
class Server:
|
| 14 |
BASE_URL = env.get("BASE_URL", "https://kawaiimizo-maakichu.hf.space")
|
bot/modules/static.py
CHANGED
|
@@ -65,6 +65,18 @@ FileLinksText = \
|
|
| 65 |
`%(dl_link)s`
|
| 66 |
"""
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
MediaLinksText = \
|
| 69 |
"""
|
| 70 |
**Download Link:**
|
|
@@ -73,6 +85,20 @@ MediaLinksText = \
|
|
| 73 |
`%(stream_link)s`
|
| 74 |
"""
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
InvalidQueryText = \
|
| 77 |
"""
|
| 78 |
Query data mismatched.
|
|
|
|
| 65 |
`%(dl_link)s`
|
| 66 |
"""
|
| 67 |
|
| 68 |
+
FileLinkText = """
|
| 69 |
+
<i><u>𝗬𝗼𝘂𝗿 𝗟𝗶𝗻𝗸 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱 !</u></i> 🎉
|
| 70 |
+
|
| 71 |
+
📂 **Fɪʟᴇ ɴᴀᴍᴇ:** `{file_name}`
|
| 72 |
+
|
| 73 |
+
📦 **Fɪʟᴇ ꜱɪᴢᴇ:** `{file_size}`
|
| 74 |
+
|
| 75 |
+
📥 **Dᴏᴡɴʟᴏᴀᴅ:** __{dl_link}__
|
| 76 |
+
|
| 77 |
+
🚸 **Nᴏᴛᴇ:** **LINK WON'T EXPIRE TILL YOU REVOKE**
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
MediaLinksText = \
|
| 81 |
"""
|
| 82 |
**Download Link:**
|
|
|
|
| 85 |
`%(stream_link)s`
|
| 86 |
"""
|
| 87 |
|
| 88 |
+
MediaLinkText = """
|
| 89 |
+
<i><u>𝗬𝗼𝘂𝗿 𝗟𝗶𝗻𝗸 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗲𝗱 !</u></i> 🎉
|
| 90 |
+
|
| 91 |
+
📂 **Fɪʟᴇ ɴᴀᴍᴇ:** __{file_name}__
|
| 92 |
+
|
| 93 |
+
📦 **Fɪʟᴇ ꜱɪᴢᴇ:** `{file_size}`
|
| 94 |
+
|
| 95 |
+
📥 **Dᴏᴡɴʟᴏᴀᴅ:** __{dl_link}__
|
| 96 |
+
|
| 97 |
+
🖥 **WATCH:** __{stream_link}__
|
| 98 |
+
|
| 99 |
+
🚸 **Nᴏᴛᴇ:** **LINK WON'T EXPIRE TILL YOU REVOKE**
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
InvalidQueryText = \
|
| 103 |
"""
|
| 104 |
Query data mismatched.
|
bot/plugins/files.py
CHANGED
|
@@ -5,6 +5,7 @@ from bot import TelegramBot
|
|
| 5 |
from bot.config import Telegram, Server
|
| 6 |
from bot.modules.decorators import verify_user
|
| 7 |
from bot.modules.static import *
|
|
|
|
| 8 |
|
| 9 |
@TelegramBot.on_message(
|
| 10 |
filters.private
|
|
@@ -21,17 +22,38 @@ from bot.modules.static import *
|
|
| 21 |
async def handle_user_file(_, msg: Message):
|
| 22 |
sender_id = msg.from_user.id
|
| 23 |
secret_code = token_hex(Telegram.SECRET_CODE_LENGTH)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
file = await msg.copy(
|
| 25 |
chat_id=Telegram.CHANNEL_ID,
|
| 26 |
caption=f'||{secret_code}/{sender_id}||'
|
| 27 |
)
|
| 28 |
file_id = file.id
|
| 29 |
dl_link = f'{Server.BASE_URL}/dl/{file_id}?code={secret_code}'
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if (msg.document and 'video' in msg.document.mime_type) or msg.video:
|
| 32 |
-
stream_link = f'{Server.BASE_URL}/stream/{file_id}?code={secret_code}'
|
| 33 |
await msg.reply(
|
| 34 |
-
text=
|
| 35 |
quote=True,
|
| 36 |
reply_markup=InlineKeyboardMarkup(
|
| 37 |
[
|
|
@@ -47,7 +69,7 @@ async def handle_user_file(_, msg: Message):
|
|
| 47 |
)
|
| 48 |
else:
|
| 49 |
await msg.reply(
|
| 50 |
-
text=
|
| 51 |
quote=True,
|
| 52 |
reply_markup=InlineKeyboardMarkup(
|
| 53 |
[
|
|
|
|
| 5 |
from bot.config import Telegram, Server
|
| 6 |
from bot.modules.decorators import verify_user
|
| 7 |
from bot.modules.static import *
|
| 8 |
+
from bot.utils import humanbytes
|
| 9 |
|
| 10 |
@TelegramBot.on_message(
|
| 11 |
filters.private
|
|
|
|
| 22 |
async def handle_user_file(_, msg: Message):
|
| 23 |
sender_id = msg.from_user.id
|
| 24 |
secret_code = token_hex(Telegram.SECRET_CODE_LENGTH)
|
| 25 |
+
|
| 26 |
+
# Determine the file type and extract file name and size dynamically
|
| 27 |
+
file_type = None
|
| 28 |
+
if msg.document:
|
| 29 |
+
file_type = "document"
|
| 30 |
+
elif msg.video:
|
| 31 |
+
file_type = "video"
|
| 32 |
+
elif msg.video_note:
|
| 33 |
+
file_type = "video_note"
|
| 34 |
+
elif msg.audio:
|
| 35 |
+
file_type = "audio"
|
| 36 |
+
elif msg.voice:
|
| 37 |
+
file_type = "voice"
|
| 38 |
+
elif msg.photo:
|
| 39 |
+
file_type = "photo"
|
| 40 |
+
|
| 41 |
+
# Use getattr to dynamically access file_name and file_size
|
| 42 |
+
file_name = getattr(msg, file_type).file_name if hasattr(getattr(msg, file_type), 'file_name') else file_type.title()
|
| 43 |
+
file_size = getattr(getattr(msg, file_type), 'file_size', 0)
|
| 44 |
file = await msg.copy(
|
| 45 |
chat_id=Telegram.CHANNEL_ID,
|
| 46 |
caption=f'||{secret_code}/{sender_id}||'
|
| 47 |
)
|
| 48 |
file_id = file.id
|
| 49 |
dl_link = f'{Server.BASE_URL}/dl/{file_id}?code={secret_code}'
|
| 50 |
+
stream_link = f'{Server.BASE_URL}/stream/{file_id}?code={secret_code}'
|
| 51 |
+
formatted_message = MediaLinkText.format(file_name=file_name, file_size=humanbytes(file_size), dl_link=dl_link, stream_link=stream_link)
|
| 52 |
+
file_message = FileLinkText.format(file_name=file_name, file_size=humanbytes(file_size), dl_link=dl_link)
|
| 53 |
|
| 54 |
if (msg.document and 'video' in msg.document.mime_type) or msg.video:
|
|
|
|
| 55 |
await msg.reply(
|
| 56 |
+
text=formatted_message,
|
| 57 |
quote=True,
|
| 58 |
reply_markup=InlineKeyboardMarkup(
|
| 59 |
[
|
|
|
|
| 69 |
)
|
| 70 |
else:
|
| 71 |
await msg.reply(
|
| 72 |
+
text=file_message,
|
| 73 |
quote=True,
|
| 74 |
reply_markup=InlineKeyboardMarkup(
|
| 75 |
[
|
bot/server/main.py
CHANGED
|
@@ -37,7 +37,7 @@ async def health():
|
|
| 37 |
})
|
| 38 |
|
| 39 |
|
| 40 |
-
@bp.route('/dl/<int:file_id>')
|
| 41 |
async def transmit_file(file_id):
|
| 42 |
file = await get_message(file_id) or abort(404)
|
| 43 |
code = request.args.get('code') or abort(401)
|
|
@@ -102,7 +102,7 @@ async def transmit_file(file_id):
|
|
| 102 |
|
| 103 |
return Response(file_stream(), headers=headers, status=status_code)
|
| 104 |
|
| 105 |
-
@bp.route('/stream/<int:file_id>')
|
| 106 |
async def stream_file(file_id):
|
| 107 |
code = request.args.get('code') or abort(401)
|
| 108 |
return await render_template('player.html', mediaLink=f'{Server.BASE_URL}/dl/{file_id}?code={code}')
|
|
|
|
| 37 |
})
|
| 38 |
|
| 39 |
|
| 40 |
+
@bp.route('/dl/<int:file_id>', methods=['GET', 'POST', 'HEAD'])
|
| 41 |
async def transmit_file(file_id):
|
| 42 |
file = await get_message(file_id) or abort(404)
|
| 43 |
code = request.args.get('code') or abort(401)
|
|
|
|
| 102 |
|
| 103 |
return Response(file_stream(), headers=headers, status=status_code)
|
| 104 |
|
| 105 |
+
@bp.route('/stream/<int:file_id>', methods=['GET', 'POST', 'HEAD'])
|
| 106 |
async def stream_file(file_id):
|
| 107 |
code = request.args.get('code') or abort(401)
|
| 108 |
return await render_template('player.html', mediaLink=f'{Server.BASE_URL}/dl/{file_id}?code={code}')
|
bot/utils/__init__.py
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
from .time_format import get_readable_time, get_system_info
|
|
|
|
|
|
| 1 |
+
from .time_format import get_readable_time, get_system_info
|
| 2 |
+
from .util import humanbytes
|
bot/utils/util.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
def humanbytes(size):
|
| 3 |
+
if not size:
|
| 4 |
+
return "0 B"
|
| 5 |
+
for unit in ["", "K", "M", "G", "T"]:
|
| 6 |
+
if size < 1024:
|
| 7 |
+
break
|
| 8 |
+
size /= 1024
|
| 9 |
+
if isinstance(size, int):
|
| 10 |
+
size = f"{size} {unit}B"
|
| 11 |
+
elif isinstance(size, float):
|
| 12 |
+
size = f"{size:.2f} {unit}B"
|
| 13 |
+
return size
|