Spaces:
Running
Running
BinaryONe
commited on
Commit
·
265dfab
1
Parent(s):
0a9a39c
Changes in Database
Browse files
FileStream/bot/plugins/FileHandlers/callback.py
CHANGED
@@ -268,15 +268,14 @@ async def cb_data(bot: Client, update: CallbackQuery):
|
|
268 |
# Here we are Adding the File Into the database First
|
269 |
db_id = await db.add_file(file_info=file_info, db_type="TEMPORARY")
|
270 |
await get_file_ids(False, db_id, message)
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
)
|
280 |
except FloodWait as e:
|
281 |
print(f"Sleeping for {str(e.value)}s")
|
282 |
await asyncio.sleep(e.value)
|
|
|
268 |
# Here we are Adding the File Into the database First
|
269 |
db_id = await db.add_file(file_info=file_info, db_type="TEMPORARY")
|
270 |
await get_file_ids(False, db_id, message)
|
271 |
+
file_info = await db.GetFileByDBName(db_id, privacy_type="TEMPORARY")
|
272 |
+
reply_markup, stream_text = await priv_func(file_info['file']['file_name'], file_info['file']['file_size'])
|
273 |
+
await update.message.edit_text(
|
274 |
+
text=stream_text,
|
275 |
+
parse_mode=ParseMode.HTML,
|
276 |
+
disable_web_page_preview=True,
|
277 |
+
reply_markup=reply_markup,
|
278 |
+
)
|
|
|
279 |
except FloodWait as e:
|
280 |
print(f"Sleeping for {str(e.value)}s")
|
281 |
await asyncio.sleep(e.value)
|
FileStream/utils/FileProcessors/bot_utils.py
CHANGED
@@ -90,15 +90,12 @@ async def upload_type_func(file_info,replied_message):
|
|
90 |
user_id = file_info['user_id']
|
91 |
message_id = file_info['message_id']
|
92 |
"""
|
93 |
-
existing_file = await db.get_file_by_fileuniqueid_only(file_info['file']['file_unique_id'],file_info['privacy_type'])
|
94 |
if existing_file :
|
95 |
-
|
96 |
response = await gen_link(existing_file['_id'])
|
97 |
#await update.message.edit_text(text=stream_text,parse_mode=ParseMode.HTML,disable_web_page_preview=True,reply_markup=reply_markup,)
|
98 |
return {"reply_markup" : response["reply_markup"], "stream_text": response["stream_text"],"poster":response["poster"],"type":"ExistingFile"}
|
99 |
-
|
100 |
else:
|
101 |
-
|
102 |
name = file_info['file']['caption'] if file_info['file']['caption'] else file_info['file']['file_name']
|
103 |
title, year = Get_Title_Year(name)
|
104 |
stream_text = LANG.STREAM_TEXT_Y.format(file_info['file']['file_name'],title+" "+str(year),humanbytes(file_info['file']['file_size']))
|
@@ -146,12 +143,13 @@ async def gen_priv_file_link(_id):
|
|
146 |
])
|
147 |
else:
|
148 |
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
149 |
-
reply_markup = InlineKeyboardMarkup(
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
155 |
return reply_markup, stream_text
|
156 |
|
157 |
|
@@ -159,37 +157,39 @@ async def gen_priv_file_link(_id):
|
|
159 |
|
160 |
|
161 |
async def gen_link(_id):
|
162 |
-
file_info = await db.get_file(_id)
|
163 |
-
file_name = file_info['file']['file_name']
|
164 |
-
file_size = humanbytes(file_info['file']['file_size'])
|
165 |
-
mime_type = file_info['file']['mime_type']
|
166 |
-
poster = file_info['poster']
|
167 |
-
title=file_info["title"]
|
168 |
-
description=file_info['description']
|
169 |
release_date=str(file_info["release_date"]),
|
170 |
-
page_link = f"{Server.URL}app/watch/{_id}"
|
171 |
-
stream_link = f"{Server.URL}api/dl/{_id}"
|
172 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
173 |
|
174 |
if "video" in mime_type:
|
175 |
stream_text = LANG.STREAM_TEXT.format(poster,description,title,release_date,file_name, file_size, stream_link, page_link, file_link)
|
176 |
-
reply_markup = InlineKeyboardMarkup(
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
185 |
else:
|
186 |
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
187 |
-
reply_markup = InlineKeyboardMarkup(
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
193 |
return {"reply_markup": reply_markup, "stream_text": stream_text, "poster":poster}
|
194 |
|
195 |
|
@@ -265,10 +265,7 @@ async def is_user_authorized(message):
|
|
265 |
async def is_user_exist(bot, message):
|
266 |
if not bool(await db.get_user(message.from_user.id)):
|
267 |
#await db.add_user(message.from_user.id)
|
268 |
-
await bot.send_message(
|
269 |
-
Telegram.ULOG_GROUP,
|
270 |
-
f"**#NᴇᴡUsᴇʀ**\n**⬩ ᴜsᴇʀ ɴᴀᴍᴇ :** [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n**⬩ ᴜsᴇʀ ɪᴅ :** `{message.from_user.id}`"
|
271 |
-
)
|
272 |
|
273 |
|
274 |
#------------------[ User Status]--------------------#
|
@@ -282,10 +279,7 @@ async def is_channel_exist(bot, message):
|
|
282 |
if not bool(await db.get_user(message.chat.id)):
|
283 |
await db.add_user(message.chat.id)
|
284 |
members = await bot.get_chat_members_count(message.chat.id)
|
285 |
-
await bot.send_message(
|
286 |
-
Telegram.ULOG_GROUP,
|
287 |
-
f"**#NᴇᴡCʜᴀɴɴᴇʟ** \n**⬩ ᴄʜᴀᴛ ɴᴀᴍᴇ :** `{message.chat.title}`\n**⬩ ᴄʜᴀᴛ ɪᴅ :** `{message.chat.id}`\n**⬩ ᴛᴏᴛᴀʟ ᴍᴇᴍʙᴇʀs :** `{members}`"
|
288 |
-
)
|
289 |
|
290 |
|
291 |
# Decorator Function to check if user is authorized
|
|
|
90 |
user_id = file_info['user_id']
|
91 |
message_id = file_info['message_id']
|
92 |
"""
|
93 |
+
existing_file = await db.get_file_by_fileuniqueid_only(file_info['file']['file_unique_id'], file_info['privacy_type'])
|
94 |
if existing_file :
|
|
|
95 |
response = await gen_link(existing_file['_id'])
|
96 |
#await update.message.edit_text(text=stream_text,parse_mode=ParseMode.HTML,disable_web_page_preview=True,reply_markup=reply_markup,)
|
97 |
return {"reply_markup" : response["reply_markup"], "stream_text": response["stream_text"],"poster":response["poster"],"type":"ExistingFile"}
|
|
|
98 |
else:
|
|
|
99 |
name = file_info['file']['caption'] if file_info['file']['caption'] else file_info['file']['file_name']
|
100 |
title, year = Get_Title_Year(name)
|
101 |
stream_text = LANG.STREAM_TEXT_Y.format(file_info['file']['file_name'],title+" "+str(year),humanbytes(file_info['file']['file_size']))
|
|
|
143 |
])
|
144 |
else:
|
145 |
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
146 |
+
reply_markup = InlineKeyboardMarkup([
|
147 |
+
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
148 |
+
[
|
149 |
+
InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", url=file_link),
|
150 |
+
InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",callback_data=f"msgdelpvt_{_id}")
|
151 |
+
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
|
152 |
+
])
|
153 |
return reply_markup, stream_text
|
154 |
|
155 |
|
|
|
157 |
|
158 |
|
159 |
async def gen_link(_id):
|
160 |
+
file_info = await db.get_file(_id),
|
161 |
+
file_name = file_info['file']['file_name'],
|
162 |
+
file_size = humanbytes(file_info['file']['file_size']),
|
163 |
+
mime_type = file_info['file']['mime_type'],
|
164 |
+
poster = file_info['poster'],
|
165 |
+
title=file_info["title"],
|
166 |
+
description=file_info['description'],
|
167 |
release_date=str(file_info["release_date"]),
|
168 |
+
page_link = f"{Server.URL}app/watch/{_id}",
|
169 |
+
stream_link = f"{Server.URL}api/dl/{_id}",
|
170 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
171 |
|
172 |
if "video" in mime_type:
|
173 |
stream_text = LANG.STREAM_TEXT.format(poster,description,title,release_date,file_name, file_size, stream_link, page_link, file_link)
|
174 |
+
reply_markup = InlineKeyboardMarkup([
|
175 |
+
[
|
176 |
+
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
177 |
+
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
178 |
+
],
|
179 |
+
[
|
180 |
+
InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", url=file_link),
|
181 |
+
InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",callback_data=f"msgdelpvt_{_id}")
|
182 |
+
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
|
183 |
+
])
|
184 |
else:
|
185 |
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
186 |
+
reply_markup = InlineKeyboardMarkup([
|
187 |
+
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
188 |
+
[
|
189 |
+
InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", url=file_link),
|
190 |
+
InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",callback_data=f"msgdelpvt_{_id}")
|
191 |
+
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
|
192 |
+
])
|
193 |
return {"reply_markup": reply_markup, "stream_text": stream_text, "poster":poster}
|
194 |
|
195 |
|
|
|
265 |
async def is_user_exist(bot, message):
|
266 |
if not bool(await db.get_user(message.from_user.id)):
|
267 |
#await db.add_user(message.from_user.id)
|
268 |
+
await bot.send_message(Telegram.ULOG_GROUP,f"**#NᴇᴡUsᴇʀ**\n**⬩ ᴜsᴇʀ ɴᴀᴍᴇ :** [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n**⬩ ᴜsᴇʀ ɪᴅ :** `{message.from_user.id}`")
|
|
|
|
|
|
|
269 |
|
270 |
|
271 |
#------------------[ User Status]--------------------#
|
|
|
279 |
if not bool(await db.get_user(message.chat.id)):
|
280 |
await db.add_user(message.chat.id)
|
281 |
members = await bot.get_chat_members_count(message.chat.id)
|
282 |
+
await bot.send_message(Telegram.ULOG_GROUP,f"**#NᴇᴡCʜᴀɴɴᴇʟ** \n**⬩ ᴄʜᴀᴛ ɴᴀᴍᴇ :** `{message.chat.title}`\n**⬩ ᴄʜᴀᴛ ɪᴅ :** `{message.chat.id}`\n**⬩ ᴛᴏᴛᴀʟ ᴍᴇᴍʙᴇʀs :** `{members}`" )
|
|
|
|
|
|
|
283 |
|
284 |
|
285 |
# Decorator Function to check if user is authorized
|
FileStream/utils/FileProcessors/file_properties.py
CHANGED
@@ -50,7 +50,7 @@ async def update_file_id(message, MULTI_CLIENTS):
|
|
50 |
file_ids = {}
|
51 |
for client_id, client in MULTI_CLIENTS.items():
|
52 |
#log_msg = await client.get_messages(message['location'],message['message_id'])
|
53 |
-
media = get_media_from_message(await client.get_messages(message['location'],message['message_id']))
|
54 |
file_ids[str(client.id)] = getattr(media, "file_id", "")
|
55 |
|
56 |
return file_ids
|
@@ -63,8 +63,7 @@ async def get_private_file_ids(client: Client | bool, db_id: str,message) -> Opt
|
|
63 |
if not str(client.id) in file_id_info:
|
64 |
logging.debug("Storing file_id in DB")
|
65 |
#msg = await client.get_messages(Telegram.PFLOG_CHANNEL,file_info['message_id'])
|
66 |
-
media = get_media_from_message(await client.get_messages(
|
67 |
-
Telegram.PFLOG_CHANNEL, file_info['message_id']))
|
68 |
file_id_info[str(client.id)] = getattr(media, "file_id", "")
|
69 |
await db.update_private_file_ids(db_id, file_id_info)
|
70 |
logging.debug("Stored file_id in DB")
|
@@ -89,7 +88,7 @@ async def get_file_ids(client: Client | bool, db_id: str, message) -> Optional[F
|
|
89 |
log_msg = await send_file(FileStream, db_id, file_info, message, source)
|
90 |
#updated_info = update_file_info(log_msg)
|
91 |
await db.update_file_info(db_id, update_file_info(log_msg), file_info['privacy_type'])
|
92 |
-
await db.update_file_ids(db_id, await update_file_id(await db.GetFileByDBName(db_id, file_info['privacy_type']),MULTI_CLIENTS), file_info['privacy_type'])
|
93 |
|
94 |
logging.debug("Stored file_id of all clients in DB")
|
95 |
if not client:
|
|
|
50 |
file_ids = {}
|
51 |
for client_id, client in MULTI_CLIENTS.items():
|
52 |
#log_msg = await client.get_messages(message['location'],message['message_id'])
|
53 |
+
media = get_media_from_message(await client.get_messages(message['location'], message['message_id']))
|
54 |
file_ids[str(client.id)] = getattr(media, "file_id", "")
|
55 |
|
56 |
return file_ids
|
|
|
63 |
if not str(client.id) in file_id_info:
|
64 |
logging.debug("Storing file_id in DB")
|
65 |
#msg = await client.get_messages(Telegram.PFLOG_CHANNEL,file_info['message_id'])
|
66 |
+
media = get_media_from_message(await client.get_messages(Telegram.PFLOG_CHANNEL, file_info['message_id']))
|
|
|
67 |
file_id_info[str(client.id)] = getattr(media, "file_id", "")
|
68 |
await db.update_private_file_ids(db_id, file_id_info)
|
69 |
logging.debug("Stored file_id in DB")
|
|
|
88 |
log_msg = await send_file(FileStream, db_id, file_info, message, source)
|
89 |
#updated_info = update_file_info(log_msg)
|
90 |
await db.update_file_info(db_id, update_file_info(log_msg), file_info['privacy_type'])
|
91 |
+
await db.update_file_ids(db_id, await update_file_id(await db.GetFileByDBName(db_id, file_info['privacy_type']), MULTI_CLIENTS), file_info['privacy_type'])
|
92 |
|
93 |
logging.debug("Stored file_id of all clients in DB")
|
94 |
if not client:
|