Skip to content

Commit

Permalink
format size
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps committed Oct 7, 2021
1 parent ccbf4c1 commit 9a8e82c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from info import START_MSG, CHANNELS, ADMINS, AUTH_CHANNEL, CUSTOM_FILE_CAPTION
from utils import Media, get_file_details
from utils import Media, get_file_details, get_size
from pyrogram.errors import UserNotParticipant
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,7 +54,7 @@ async def start(bot, cmd):
filedetails = await get_file_details(file_id)
for files in filedetails:
title = files.file_name
size=files.file_size
size=get_size(files.file_size)
f_caption=files.caption
if CUSTOM_FILE_CAPTION:
try:
Expand Down Expand Up @@ -196,4 +196,4 @@ async def bot_info(bot, message):
InlineKeyboardButton('Source Code', url='https://github.com/subinps/Media-Search-bot')
]
]
await message.reply(text="<b>Developer : <a href='https://t.me/subinps_bot'>SUBIN</a>\nLanguage : <code>Python3</code>\nLibrary : <a href='https://docs.pyrogram.org/'>Pyrogram asyncio</a>\nSource Code : <a href='https://github.com/subinps/Media-Search-bot'>Click here</a>\nUpdate Channel : <a href='https://t.me/subin_works'>XTZ Bots</a> </b>", reply_markup=InlineKeyboardMarkup(buttons), disable_web_page_preview=True)
await message.reply(text="Language : <code>Python3</code>\nLibrary : <a href='https://docs.pyrogram.org/'>Pyrogram asyncio</a>\nSource Code : <a href='https://github.com/subinps/Media-Search-bot'>Click here</a>\nUpdate Channel : <a href='https://t.me/subin_works'>XTZ Bots</a> </b>", reply_markup=InlineKeyboardMarkup(buttons), disable_web_page_preview=True)
13 changes: 2 additions & 11 deletions plugins/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pyrogram import Client, emoji, filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultCachedDocument

from utils import get_search_results, is_subscribed
from utils import get_search_results, is_subscribed, get_size
from info import CACHE_TIME, AUTH_USERS, AUTH_CHANNEL, CUSTOM_FILE_CAPTION

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -38,7 +38,7 @@ async def answer(bot, query):

for file in files:
title=file.file_name
size=file.file_size
size=get_size(file.file_size)
f_caption=file.caption
if CUSTOM_FILE_CAPTION:
try:
Expand Down Expand Up @@ -97,14 +97,5 @@ def get_reply_markup(query):
return InlineKeyboardMarkup(buttons)


def get_size(size):
"""Get size in readable format"""

units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
size = float(size)
i = 0
while size >= 1024.0 and i < len(units):
i += 1
size /= 1024.0
return "%.2f %s" % (size, units[i])

4 changes: 2 additions & 2 deletions plugins/pm_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async def cb_handler(client: Client, query: CallbackQuery):
filedetails = await get_file_details(file_id)
for files in filedetails:
title = files.file_name
size=files.file_size
size=get_size(files.file_size)
f_caption=files.caption
if CUSTOM_FILE_CAPTION:
try:
Expand Down Expand Up @@ -317,7 +317,7 @@ async def cb_handler(client: Client, query: CallbackQuery):
filedetails = await get_file_details(file_id)
for files in filedetails:
title = files.file_name
size=files.file_size
size=get_size(files.file_size)
f_caption=files.caption
if CUSTOM_FILE_CAPTION:
try:
Expand Down
11 changes: 11 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,14 @@ def unpack_new_file_id(new_file_id):
file_ref = encode_file_ref(decoded.file_reference)
return file_id, file_ref


def get_size(size):
"""Get size in readable format"""

units = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB"]
size = float(size)
i = 0
while size >= 1024.0 and i < len(units):
i += 1
size /= 1024.0
return "%.2f %s" % (size, units[i])

0 comments on commit 9a8e82c

Please sign in to comment.