├── runtime.txt ├── Procfile ├── requirements.txt ├── Dockerfile ├── helper ├── date.py ├── set.py ├── ffmpeg.py ├── progress.py └── database.py ├── plugins ├── refer.py ├── about.py ├── thumbfunction.py ├── broadcast.py ├── caption.py ├── upgrade.py ├── admin.py ├── myplane.py ├── filedetect.py ├── start.py └── cb_data.py ├── bot.py ├── README.md └── app.json /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.10 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: python3 bot.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow 2 | humanize 3 | hachoir 4 | pyrogram==2.0.57 5 | TgCrypto 6 | pymongo==4.6.3 7 | dnspython 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10 2 | 3 | WORKDIR /webx 4 | 5 | COPY requirements.txt ./ 6 | 7 | RUN pip install -r requirements.txt 8 | 9 | COPY . . 10 | 11 | CMD ["python3", "bot.py"] -------------------------------------------------------------------------------- /helper/date.py: -------------------------------------------------------------------------------- 1 | from datetime import timedelta, date ,datetime 2 | import time 3 | 4 | def add_date(): 5 | today = date.today() 6 | ex_date = today + timedelta(days=30) 7 | pattern = '%Y-%m-%d' 8 | epcho = int(time.mktime(time.strptime(str(ex_date), pattern))) 9 | normal_date = datetime.fromtimestamp(epcho).strftime('%Y-%m-%d') 10 | return epcho , normal_date 11 | 12 | def check_expi(saved_date): 13 | today = date.today() 14 | pattern = '%Y-%m-%d' 15 | epcho = int(time.mktime(time.strptime(str(today), pattern))) 16 | then = saved_date - epcho 17 | print(then) 18 | if then > 0: 19 | return True 20 | else: 21 | return False 22 | -------------------------------------------------------------------------------- /plugins/refer.py: -------------------------------------------------------------------------------- 1 | from pyrogram import Client, filters 2 | from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 3 | @Client.on_message(filters.private & filters.command(["refer"])) 4 | async def refer(client,message): 5 | reply_markup = InlineKeyboardMarkup( 6 | [ [ InlineKeyboardButton("Share Your Link" ,url=f"https://t.me/share/url?url=https://t.me/webxrenamebot?start={message.from_user.id}") ] ]) 7 | await message.reply_text(f"Refer And Earn Get 100MB Upload Limit\nPer Refer 100MB\n Your Link :- https://t.me/webxrenamebot?start={message.from_user.id} ",reply_to_message_id = message.id,reply_markup=reply_markup,) 8 | 9 | -------------------------------------------------------------------------------- /plugins/about.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyrogram import Client, filters 3 | token = os.environ.get('TOKEN','') 4 | botid = token.split(':')[0] 5 | from helper.database import botdata, find_one, total_user 6 | from helper.progress import humanbytes 7 | @Client.on_message(filters.private & filters.command(["about"])) 8 | async def start(client,message): 9 | botdata(int(botid)) 10 | data = find_one(int(botid)) 11 | total_rename = data["total_rename"] 12 | total_size = data["total_size"] 13 | await message.reply_text(f"Total User:- {total_user()}\nBot :- @webxrenamebot\nCreater :- @WebX_Divin\nLanguage :-Python3\nLibrary :- Pyrogram\nServer :- Oracle Cloud\nTotal Renamed File :-{total_rename}\nTotal Size Renamed :- {humanbytes(int(total_size))} ",quote=True) 14 | -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | from pyrogram import Client, compose,idle 3 | import os 4 | 5 | from plugins.cb_data import app as Client2 6 | 7 | TOKEN = os.environ.get("TOKEN", "") 8 | 9 | API_ID = int(os.environ.get("API_ID", "")) 10 | 11 | API_HASH = os.environ.get("API_HASH", "") 12 | 13 | STRING = os.environ.get("STRING", "") 14 | 15 | 16 | bot = Client( 17 | 18 | "Renamer", 19 | 20 | bot_token=TOKEN, 21 | 22 | api_id=API_ID, 23 | 24 | api_hash=API_HASH, 25 | 26 | plugins=dict(root='plugins')) 27 | 28 | 29 | if STRING: 30 | apps = [Client2,bot] 31 | for app in apps: 32 | app.start() 33 | idle() 34 | for app in apps: 35 | app.stop() 36 | 37 | else: 38 | bot.run() 39 | -------------------------------------------------------------------------------- /plugins/thumbfunction.py: -------------------------------------------------------------------------------- 1 | from pyrogram import Client, filters 2 | from helper.database import find, delthumb, addthumb 3 | 4 | @Client.on_message(filters.private & filters.command(['viewthumb'])) 5 | async def viewthumb(client,message): 6 | print(message.chat.id) 7 | thumb = find(int(message.chat.id))[0] 8 | if thumb : 9 | await client.send_photo(message.chat.id,photo =f"{thumb}") 10 | else: 11 | await message.reply_text("**You don't have any custom thumbnail**") 12 | 13 | 14 | @Client.on_message(filters.private & filters.command(['delthumb'])) 15 | async def removethumb(client,message): 16 | delthumb(int(message.chat.id)) 17 | await message.reply_text("**Custom thumbnail deleted successfully**") 18 | 19 | @Client.on_message(filters.private & filters.photo) 20 | async def addthumbs(client,message): 21 | file_id = str(message.photo.file_id) 22 | addthumb(message.chat.id , file_id) 23 | await message.reply_text("**Custom thumbnail saved successfully** ✅") 24 | 25 | -------------------------------------------------------------------------------- /plugins/broadcast.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyrogram.errors import FloodWait 3 | import asyncio 4 | from pyrogram import Client ,filters 5 | from helper.database import getid ,delete 6 | import time 7 | ADMIN = int(os.environ.get("ADMIN", "")) 8 | 9 | 10 | @Client.on_message(filters.private & filters.user(ADMIN) & filters.command(["broadcast"])) 11 | async def broadcast(bot, message): 12 | if (message.reply_to_message): 13 | ms = await message.reply_text("Geting All ids from database ...........") 14 | ids = getid() 15 | tot = len(ids) 16 | success = 0 17 | failed = 0 18 | await ms.edit(f"Starting Broadcast .... \n Sending Message To {tot} Users") 19 | for id in ids: 20 | try: 21 | time.sleep(1) 22 | await message.reply_to_message.copy(id) 23 | success += 1 24 | except: 25 | failed += 1 26 | delete({"_id":id}) 27 | pass 28 | try: 29 | await ms.edit( f"Message sent to {success} chat(s). {failed} chat(s) failed on receiving message. \nTotal - {tot}" ) 30 | except FloodWait as e: 31 | await asyncio.sleep(t.x) 32 | -------------------------------------------------------------------------------- /helper/set.py: -------------------------------------------------------------------------------- 1 | from typing import Dict, List 2 | def escape_invalid_curly_brackets(text: str, valids: List[str]) -> str: 3 | new_text = "" 4 | idx = 0 5 | while idx < len(text): 6 | if text[idx] == "{": 7 | if idx + 1 < len(text) and text[idx + 1] == "{": 8 | idx += 2 9 | new_text += "{{{{" 10 | continue 11 | else: 12 | success = False 13 | for v in valids: 14 | if text[idx:].startswith('{' + v + '}'): 15 | success = True 16 | break 17 | if success: 18 | new_text += text[idx: idx + len(v) + 2] 19 | idx += len(v) + 2 20 | continue 21 | else: 22 | new_text += "{{" 23 | 24 | elif text[idx] == "}": 25 | if idx + 1 < len(text) and text[idx + 1] == "}": 26 | idx += 2 27 | new_text += "}}}}" 28 | continue 29 | else: 30 | new_text += "}}" 31 | 32 | else: 33 | new_text += text[idx] 34 | idx += 1 35 | 36 | return new_text 37 | -------------------------------------------------------------------------------- /plugins/caption.py: -------------------------------------------------------------------------------- 1 | from pyrogram import Client, filters 2 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 3 | from helper.database import * 4 | 5 | @Client.on_message(filters.private & filters.command('set_caption')) 6 | async def add_caption(client, message): 7 | if len(message.command) == 1: 8 | return await message.reply_text("**Give me a caption to set.\n\nExample:- `/set_caption File Name`**") 9 | caption = message.text.split(" ", 1)[1] 10 | addcaption(int(message.chat.id), caption) 11 | await message.reply_text("**Your Caption successfully added ✅**") 12 | 13 | @Client.on_message(filters.private & filters.command('del_caption')) 14 | async def delete_caption(client, message): 15 | caption = find(int(message.chat.id))[1] 16 | if not caption: 17 | await message.reply_text("**You dont have any custom caption**") 18 | return 19 | delcaption(int(message.chat.id)) 20 | await message.reply_text("**Your caption successfully deleted ✅**") 21 | 22 | @Client.on_message(filters.private & filters.command('see_caption')) 23 | async def see_caption(client, message): 24 | caption = find(int(message.chat.id))[1] 25 | if caption: 26 | await message.reply_text(f"Your Caption:\n\n`{caption}`") 27 | else: 28 | await message.reply_text("**You dont have any custom caption**") 29 | 30 | -------------------------------------------------------------------------------- /helper/ffmpeg.py: -------------------------------------------------------------------------------- 1 | import time 2 | import os 3 | import asyncio 4 | from PIL import Image 5 | from hachoir.metadata import extractMetadata 6 | from hachoir.parser import createParser 7 | 8 | async def fix_thumb(thumb): 9 | width = 0 10 | height = 0 11 | try: 12 | if thumb != None: 13 | metadata = extractMetadata(createParser(thumb)) 14 | if metadata.has("width"): 15 | width = metadata.get("width") 16 | if metadata.has("height"): 17 | height = metadata.get("height") 18 | Image.open(thumb).convert("RGB").save(thumb) 19 | img = Image.open(thumb) 20 | img.resize((320, height)) 21 | img.save(thumb, "JPEG") 22 | except Exception as e: 23 | print(e) 24 | thumb = None 25 | 26 | return width, height, thumb 27 | 28 | async def take_screen_shot(video_file, output_directory, ttl): 29 | out_put_file_name = f"{output_directory}/{time.time()}.jpg" 30 | file_genertor_command = [ 31 | "ffmpeg", 32 | "-ss", 33 | str(ttl), 34 | "-i", 35 | video_file, 36 | "-vframes", 37 | "1", 38 | out_put_file_name 39 | ] 40 | process = await asyncio.create_subprocess_exec( 41 | *file_genertor_command, 42 | stdout=asyncio.subprocess.PIPE, 43 | stderr=asyncio.subprocess.PIPE, 44 | ) 45 | stdout, stderr = await process.communicate() 46 | e_response = stderr.decode().strip() 47 | t_response = stdout.decode().strip() 48 | if os.path.lexists(out_put_file_name): 49 | return out_put_file_name 50 | return None 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rename Bot Premium Repo. Give a star and Use the Repo as your need. 2 | 3 | ---- 4 | 5 | # Features 6 | - Renames very fast . 7 | - Permanent Thumbnail support. 8 | - Supports Broadcasts. 9 | - Set custom caption. 10 | - Force subscribe available. 11 | - Deploy on any PaaS. 12 | - Developer Service 24x7. 🔥 13 | 14 | # Required Configs 15 | 16 | * TOKEN - Get bot token from @BotFather 17 | 18 | * API_ID - From my.telegram.org 19 | 20 | * API_HASH - From my.telegram.org 21 | 22 | * ADMIN - Your User ID 23 | 24 | * DB_URL - Mongo Database URL from https://cloud.mongodb.com/ 25 | 26 | * DB_NAME - ```optional``` Your database name from mongoDB. Default will be 'my' 27 | 28 | * STRING - ```optional``` Session String For Premium Users To Upload 4GB File 29 | 30 | * LOG_CHANNEL - Channel Id to Store Files renamed files. Act as a Dump 31 | 32 | # Commands 33 | 34 | #### Copy and paste the command in Botfather 35 | 36 | ``` 37 | start - Start Messsage 38 | viewthumb - View Your Saved thumbnail 39 | delthumb - Delete Your Thumbnail 40 | about - About Bot 41 | broadcast - (Admin Use Only)Send Message To All Users 42 | addpremium - (Admin Use Only)Add Users To Rename More Then 4Gb Files and Remove Time Limit 43 | 44 | ``` 45 | 46 | # Deploy on VPS 47 | 48 | * Clone the Repo 49 | ``` 50 | git clone https://github.com/WebX-Divin/RenameBot-Premium 51 | ``` 52 | * Move to the Repo Folder 53 | ``` 54 | cd RenameBot-Premium 55 | ``` 56 | * Update the instance 57 | ``` 58 | apt update && upgrade 59 | ``` 60 | * Install the requirements 61 | ``` 62 | pip install -r requirements.txt 63 | ``` 64 | * Create the nested environment 65 | ``` 66 | apt install tmux 67 | ``` 68 | * Open the nested environment 69 | ``` 70 | tmux 71 | ``` 72 | * Run the Bot 73 | ``` 74 | python3 bot.py 75 | ``` 76 | 77 | # Join Telegram Channel 78 | - [WebXBots](https://t.me/WebXBots). Bot Updates Channel 79 | - Support Group [WebX-Support](https://t.me/Web_X_Support). For Bug report. -------------------------------------------------------------------------------- /plugins/upgrade.py: -------------------------------------------------------------------------------- 1 | from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 2 | from pyrogram import Client , filters 3 | 4 | @Client.on_callback_query(filters.regex('upgrade')) 5 | async def upgrade(bot,update): 6 | text = """**Free Plan User** 7 | Daily Upload limit 2GB 8 | Price 0 9 | 10 | **VIP 1 ** 11 | Daily Upload limit 10GB 12 | Price Rs 55 🇮🇳/🌎 0.67$ per Month 13 | 14 | **VIP 2 ** 15 | Daily Upload limit 50GB 16 | Price Rs 80 🇮🇳/🌎 0.97$ per Month 17 | 18 | Pay Using Upi I'd ```divindass@fbl``` 19 | 20 | After Payment Send Screenshots Of 21 | Payment To Admin""" 22 | keybord = InlineKeyboardMarkup([[ 23 | InlineKeyboardButton("ADMIN 🛂",url = "https://t.me/webx_admin_bot")], 24 | [InlineKeyboardButton("PayPal 🌎",url = "https://t.me/webx_admin_bot"), 25 | InlineKeyboardButton("UPI ",url = "https://t.me/webx_admin_bot")],[InlineKeyboardButton("Cancel",callback_data = "cancel") ]]) 26 | await update.message.edit(text = text,reply_markup = keybord) 27 | 28 | 29 | @Client.on_message(filters.private & filters.command(["upgrade"])) 30 | async def upgradecm(bot,message): 31 | text = """**Free Plan User** 32 | Daily Upload limit 2GB 33 | Price 0 34 | 35 | **VIP 1 ** 36 | Daily Upload limit 10GB 37 | Price Rs 55 🇮🇳/🌎 0.67$ per Month 38 | 39 | **VIP 2 ** 40 | Daily Upload limit 50GB 41 | Price Rs 80 🇮🇳/🌎 0.97$ per Month 42 | 43 | 44 | Pay Using Upi I'd ```divindass@fbl``` 45 | 46 | After Payment Send Screenshots Of 47 | Payment To Admin""" 48 | keybord = InlineKeyboardMarkup([[ 49 | InlineKeyboardButton("ADMIN 🛂",url = "https://t.me/webx_admin_bot")], 50 | [InlineKeyboardButton("PayPal 🌎",url = "https://t.me/webx_admin_bot"), 51 | InlineKeyboardButton("Paytm",url = "https://t.me/webx_admin_bot")],[InlineKeyboardButton("Cancel",callback_data = "cancel") ]]) 52 | await message.reply_text(text = text,reply_markup = keybord) 53 | -------------------------------------------------------------------------------- /plugins/admin.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyrogram import Client, filters 3 | from helper.date import add_date 4 | from helper.database import uploadlimit , usertype,addpre 5 | ADMIN = int(os.environ.get("ADMIN", "")) 6 | from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 7 | 8 | 9 | @Client.on_message(filters.private & filters.user(ADMIN) & filters.command(["warn"])) 10 | async def warn(c, m): 11 | if len(m.command) >= 3: 12 | try: 13 | user_id = m.text.split(' ', 2)[1] 14 | reason = m.text.split(' ', 2)[2] 15 | await m.reply_text("User Notfied Sucessfully") 16 | await c.send_message(chat_id=int(user_id), text=reason) 17 | except: 18 | await m.reply_text("User Not Notfied Sucessfully 😔") 19 | 20 | 21 | @Client.on_message(filters.private & filters.user(ADMIN) & filters.command(["addpremium"])) 22 | async def buypremium(bot, message): 23 | await message.reply_text("Select Plan.........",quote=True,reply_markup=InlineKeyboardMarkup([[ 24 | InlineKeyboardButton("VIP 1",callback_data = "vip1"), 25 | InlineKeyboardButton("VIP 2",callback_data = "vip2") ]])) 26 | 27 | 28 | @Client.on_callback_query(filters.regex('vip1')) 29 | async def vip1(bot,update): 30 | id = update.message.reply_to_message.text.split("/addpremium") 31 | user_id = id[1].replace(" ", "") 32 | inlimit = 10737418240 33 | uploadlimit(int(user_id),10737418240) 34 | usertype(int(user_id),"VIP1") 35 | addpre(int(user_id)) 36 | await update.message.edit("Added successfully To Premium Upload limit 10 GB") 37 | await bot.send_message(user_id,"Hey Ur Upgraded To VIP 1 check your plan here /myplan") 38 | 39 | @Client.on_callback_query(filters.regex('vip2')) 40 | async def vip2(bot,update): 41 | id = update.message.reply_to_message.text.split("/addpremium") 42 | user_id = id[1].replace(" ", "") 43 | inlimit = 53687091200 44 | uploadlimit(int(user_id),53687091200) 45 | usertype(int(user_id),"VIP2") 46 | addpre(int(user_id)) 47 | await update.message.edit("Added successfully To Premium Upload limit 50 GB") 48 | await bot.send_message(user_id,"Hey Ur Upgraded To VIP 2 check your plan here /myplan") 49 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | 4 | "name": "Renamer Bot", 5 | 6 | "description": "Telegram File Renamer Bot 4GB ", 7 | 8 | "keywords": [ 9 | 10 | "Renamer ", 11 | 12 | "4GB File", 13 | 14 | "telegram" 15 | 16 | ], 17 | 18 | "repository": "https://github.com/WebX-Divin", 19 | 20 | "success_url": "https://t.me/webx_admin_bot", 21 | 22 | "env": { 23 | 24 | "CHANNEL": { 25 | 26 | "description": "Channel or Group user Name With @", 27 | 28 | "required":true 29 | 30 | 31 | 32 | }, 33 | 34 | "STRING": { 35 | 36 | "description": "Pyrogram String Session", 37 | 38 | "required": true 39 | 40 | }, 41 | 42 | "API_ID": { 43 | 44 | "description": "Your APP ID From my.telegram.org ", 45 | 46 | "required": true 47 | 48 | }, 49 | 50 | "API_HASH": { 51 | 52 | "description": "Your API Hash From my.telegram.org ", 53 | 54 | "required": true 55 | 56 | }, 57 | 58 | "TOKEN": { 59 | 60 | "description": "Your Bot Token From @BotFather", 61 | 62 | "required": true 63 | 64 | }, 65 | 66 | "ADMIN": { 67 | 68 | "description":"Add Your User ID", 69 | 70 | "required": true 71 | 72 | }, 73 | 74 | "DB_URL":{ 75 | 76 | "description":"Database Url Get It From Mongo DB" 77 | 78 | }, 79 | 80 | "DB_NAME":{ 81 | 82 | "description":"Database Name ", 83 | 84 | "required":true 85 | 86 | }, 87 | 88 | "LOG_CHANNEL":{ 89 | 90 | "description":"Channel Id Need Store Files Get Your channel id", 91 | 92 | "required": true 93 | 94 | } 95 | 96 | 97 | 98 | }, 99 | 100 | "buildpacks": [ 101 | 102 | { 103 | 104 | "url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest" 105 | 106 | }, 107 | 108 | { 109 | 110 | "url": "heroku/python" 111 | 112 | } 113 | 114 | ] 115 | 116 | } 117 | -------------------------------------------------------------------------------- /plugins/myplane.py: -------------------------------------------------------------------------------- 1 | import time 2 | from pyrogram import Client, filters 3 | from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 4 | from helper.database import find_one,used_limit 5 | from helper.database import daily as daily_ 6 | import datetime 7 | from datetime import timedelta, date ,datetime 8 | from datetime import date as date_ 9 | from helper.progress import humanbytes 10 | from helper.database import daily as daily_ 11 | from helper.date import check_expi 12 | from helper.database import uploadlimit , usertype 13 | 14 | @Client.on_message(filters.private & filters.command(["myplan"])) 15 | async def start(client,message): 16 | used_ = find_one(message.from_user.id) 17 | daily = used_["daily"] 18 | expi = daily - int(time.mktime(time.strptime(str(date_.today()), '%Y-%m-%d'))) 19 | if expi != 0: 20 | today = date_.today() 21 | pattern = '%Y-%m-%d' 22 | epcho = int(time.mktime(time.strptime(str(today), pattern))) 23 | daily_(message.from_user.id,epcho) 24 | used_limit(message.from_user.id,0) 25 | _newus = find_one(message.from_user.id) 26 | used = _newus["used_limit"] 27 | limit = _newus["uploadlimit"] 28 | remain = int(limit)- int(used) 29 | user = _newus["usertype"] 30 | ends = _newus["prexdate"] 31 | if ends: 32 | pre_check = check_expi(ends) 33 | if pre_check == False: 34 | uploadlimit(message.from_user.id,2147483648) 35 | usertype(message.from_user.id,"Free") 36 | if ends == None: 37 | text = f"User ID:- ```{message.from_user.id}```\nPlan :- {user}\nDaly Upload Limit :- {humanbytes(limit)}\nToday Used :- {humanbytes(used)}\nRemain:- {humanbytes(remain)}" 38 | else: 39 | normal_date = datetime.fromtimestamp(ends).strftime('%Y-%m-%d') 40 | text = f"User ID:- ```{message.from_user.id}```\nPlan :- {user}\nDaly Upload Limit :- {humanbytes(limit)}\nToday Used :- {humanbytes(used)}\nRemain:- {humanbytes(remain)}\n\n```Your Plan Ends On :- {normal_date}" 41 | 42 | if user == "Free": 43 | await message.reply(text,quote = True,reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("Upgrade 💰💳",callback_data = "upgrade"), InlineKeyboardButton("Cancel ✖️ ",callback_data = "cancel") ]])) 44 | else: 45 | await message.reply(text,quote=True) 46 | 47 | -------------------------------------------------------------------------------- /helper/progress.py: -------------------------------------------------------------------------------- 1 | import math 2 | import time 3 | 4 | 5 | async def progress_for_pyrogram( 6 | current, 7 | total, 8 | ud_type, 9 | message, 10 | start 11 | ): 12 | 13 | now = time.time() 14 | diff = now - start 15 | if round(diff % 10.00) == 0 or current == total: 16 | # if round(current / total * 100, 0) % 5 == 0: 17 | percentage = current * 100 / total 18 | speed = current / diff 19 | elapsed_time = round(diff) * 1000 20 | time_to_completion = round((total - current) / speed) * 1000 21 | estimated_total_time = elapsed_time + time_to_completion 22 | 23 | elapsed_time = TimeFormatter(milliseconds=elapsed_time) 24 | estimated_total_time = TimeFormatter(milliseconds=estimated_total_time) 25 | 26 | progress = "[{0}{1}] \n**Progress**: {2}%\n".format( 27 | ''.join(["●" for i in range(math.floor(percentage / 5))]), 28 | ''.join(["○" for i in range(20 - math.floor(percentage / 5))]), 29 | round(percentage, 2)) 30 | 31 | tmp = progress + "{0} of {1}\n**Speed**: {2}/s\n**ETA**: {3}\n".format( 32 | humanbytes(current), 33 | humanbytes(total), 34 | humanbytes(speed), 35 | # elapsed_time if elapsed_time != '' else "0 s", 36 | estimated_total_time if estimated_total_time != '' else "0 s" 37 | ) 38 | try: 39 | await message.edit( 40 | text="{}\n {}".format( 41 | ud_type, 42 | tmp 43 | ) 44 | ) 45 | except: 46 | pass 47 | 48 | 49 | def humanbytes(size): 50 | # https://stackoverflow.com/a/49361727/4723940 51 | # 2**10 = 1024 52 | if not size: 53 | return "" 54 | power = 2**10 55 | n = 0 56 | Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'} 57 | while size > power: 58 | size /= power 59 | n += 1 60 | return str(round(size, 2)) + " " + Dic_powerN[n] + 'B' 61 | 62 | 63 | def TimeFormatter(milliseconds: int) -> str: 64 | seconds, milliseconds = divmod(int(milliseconds), 1000) 65 | minutes, seconds = divmod(seconds, 60) 66 | hours, minutes = divmod(minutes, 60) 67 | days, hours = divmod(hours, 24) 68 | tmp = ((str(days) + "d, ") if days else "") + \ 69 | ((str(hours) + "h, ") if hours else "") + \ 70 | ((str(minutes) + "m, ") if minutes else "") + \ 71 | ((str(seconds) + "s, ") if seconds else "") + \ 72 | ((str(milliseconds) + "ms, ") if milliseconds else "") 73 | return tmp[:-2] 74 | -------------------------------------------------------------------------------- /plugins/filedetect.py: -------------------------------------------------------------------------------- 1 | from pyrogram import Client, filters 2 | from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 3 | 4 | @Client.on_message(filters.private & filters.reply) 5 | async def refunc(client,message): 6 | if (message.reply_to_message.reply_markup) and isinstance(message.reply_to_message.reply_markup, ForceReply): 7 | new_name = message.text 8 | await message.delete() 9 | media = await client.get_messages(message.chat.id,message.reply_to_message.id) 10 | file = media.reply_to_message.document or media.reply_to_message.video or media.reply_to_message.audio 11 | filename = file.file_name 12 | types = file.mime_type.split("/") 13 | mime = types[0] 14 | mg_id = media.reply_to_message.id 15 | try: 16 | out = new_name.split(".") 17 | out[1] 18 | out_name = out[-1] 19 | out_filename = new_name 20 | await message.reply_to_message.delete() 21 | if mime == "video": 22 | markup = InlineKeyboardMarkup([[ 23 | InlineKeyboardButton("📁 Document",callback_data = "doc"), 24 | InlineKeyboardButton("🎥 Video",callback_data = "vid") ]]) 25 | elif mime == "audio": 26 | markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📁 Document",callback_data = "doc") 27 | ,InlineKeyboardButton("🎵 audio",callback_data = "aud") ]]) 28 | else: 29 | markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📁 Document",callback_data = "doc") ]]) 30 | # dont chenge this message.reply_text 31 | await message.reply_text(f"**Select the output file type**\n**Output FileName** :- ```{out_filename}```",reply_to_message_id=mg_id,reply_markup = markup) 32 | 33 | except: 34 | try: 35 | out = filename.split(".") 36 | out_name = out[-1] 37 | out_filename= new_name + "."+ out_name 38 | except: 39 | await message.reply_to_message.delete() 40 | await message.reply_text("**Error** : No Extension in File, Not Supporting" 41 | ,reply_to_message_id=mg_id) 42 | return 43 | await message.reply_to_message.delete() 44 | if mime == "video": 45 | markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📁 Document",callback_data = "doc") 46 | ,InlineKeyboardButton("🎥 Video",callback_data = "vid") ]]) 47 | elif mime == "audio": 48 | markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📁 Document",callback_data = "doc") 49 | ,InlineKeyboardButton("🎵 audio",callback_data = "aud") ]]) 50 | else: 51 | markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📁 Document",callback_data = "doc") ]]) 52 | # dont chenge this message.reply_text 53 | await message.reply_text(f"**Select the output file type**\n**Output FileName** :- ```{out_filename}```", 54 | reply_to_message_id=mg_id,reply_markup = markup) 55 | 56 | -------------------------------------------------------------------------------- /helper/database.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | import os 3 | from helper.date import add_date 4 | DB_NAME = os.environ.get("DB_NAME","") 5 | DB_URL = os.environ.get("DB_URL","") 6 | mongo = pymongo.MongoClient(DB_URL) 7 | db = mongo[DB_NAME] 8 | dbcol = db["user"] 9 | 10 | #Total User 11 | 12 | def total_user(): 13 | user = dbcol.count_documents({}) 14 | return user 15 | 16 | #insert bot Data 17 | def botdata(chat_id): 18 | bot_id = int(chat_id) 19 | try: 20 | bot_data = {"_id":bot_id,"total_rename":0,"total_size":0} 21 | dbcol.insert_one(bot_data) 22 | except: 23 | pass 24 | 25 | 26 | def total_rename(chat_id,renamed_file): 27 | now = int(renamed_file) + 1 28 | dbcol.update_one({"_id":chat_id},{"$set":{"total_rename":str(now)}}) 29 | 30 | def total_size(chat_id,total_size,now_file_size): 31 | now = int(total_size) + now_file_size 32 | dbcol.update_one({"_id":chat_id},{"$set":{"total_size":str(now)}}) 33 | 34 | 35 | #insert user data 36 | def insert(chat_id): 37 | user_id = int(chat_id) 38 | user_det = {"_id":user_id,"file_id":None ,"caption":None ,"daily":0 ,"date":0 , "uploadlimit" :2147483648,"used_limit":0,"usertype":"Free","prexdate" : None} 39 | try: 40 | dbcol.insert_one(user_det) 41 | except: 42 | return True 43 | pass 44 | 45 | def addthumb(chat_id, file_id): 46 | dbcol.update_one({"_id":chat_id},{"$set":{"file_id":file_id}}) 47 | 48 | def delthumb(chat_id): 49 | dbcol.update_one({"_id":chat_id},{"$set":{"file_id":None}}) 50 | 51 | def addcaption(chat_id, caption): 52 | dbcol.update_one({"_id": chat_id},{"$set":{"caption": caption}}) 53 | 54 | def delcaption(chat_id): 55 | dbcol.update_one({"_id": chat_id},{"$set":{"caption":None}}) 56 | 57 | def dateupdate(chat_id,date): 58 | dbcol.update_one({"_id":chat_id},{"$set":{"date":date}}) 59 | 60 | def used_limit(chat_id,used): 61 | dbcol.update_one({"_id":chat_id},{"$set":{"used_limit":used}}) 62 | 63 | def usertype(chat_id,type): 64 | dbcol.update_one({"_id":chat_id},{"$set":{"usertype":type}}) 65 | 66 | def uploadlimit(chat_id,limit): 67 | dbcol.update_one({"_id":chat_id},{"$set":{"uploadlimit":limit}}) 68 | 69 | def addpre(chat_id): 70 | date = add_date() 71 | dbcol.update_one({"_id":chat_id},{"$set":{"prexdate":date[0]}}) 72 | 73 | def addpredata(chat_id): 74 | dbcol.update_one({"_id":chat_id},{"$set":{"prexdate":None}}) 75 | 76 | 77 | def daily(chat_id,date): 78 | dbcol.update_one({"_id":chat_id},{"$set":{"daily":date}}) 79 | 80 | def find(chat_id): 81 | id = {"_id":chat_id} 82 | x = dbcol.find(id) 83 | for i in x: 84 | file = i["file_id"] 85 | try: 86 | caption = i["caption"] 87 | except: 88 | caption = None 89 | 90 | return [file, caption] 91 | 92 | def getid(): 93 | values = [] 94 | for key in dbcol.find(): 95 | id = key["_id"] 96 | values.append((id)) 97 | return values 98 | 99 | def delete(id): 100 | dbcol.delete_one(id) 101 | 102 | def find_one(id): 103 | return dbcol.find_one({"_id":id}) 104 | -------------------------------------------------------------------------------- /plugins/start.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant 3 | import time 4 | from pyrogram import Client, filters 5 | from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 6 | import humanize 7 | from helper.progress import humanbytes 8 | 9 | from helper.database import insert ,find_one,used_limit,usertype,uploadlimit,addpredata,total_rename,total_size 10 | from pyrogram.file_id import FileId 11 | from helper.database import daily as daily_ 12 | from helper.date import add_date ,check_expi 13 | CHANNEL = os.environ.get('CHANNEL',"") 14 | import datetime 15 | from datetime import date as date_ 16 | STRING = os.environ.get("STRING","") 17 | log_channel = int(os.environ.get("LOG_CHANNEL","")) 18 | token = os.environ.get('TOKEN','') 19 | botid = token.split(':')[0] 20 | 21 | #Part of Day -------------------- 22 | currentTime = datetime.datetime.now() 23 | 24 | if currentTime.hour < 12: 25 | wish = "Good morning." 26 | elif 12 <= currentTime.hour < 12: 27 | wish = 'Good afternoon.' 28 | else: 29 | wish = 'Good evening.' 30 | 31 | #------------------------------- 32 | 33 | @Client.on_message(filters.private & filters.command(["start"])) 34 | async def start(client,message): 35 | old = insert(int(message.chat.id)) 36 | try: 37 | id = message.text.split(' ')[1] 38 | except: 39 | await message.reply_text(text =f""" 40 | Hello {wish} {message.from_user.first_name } 41 | __I am file renamer bot, Please sent any telegram 42 | **Document Or Video** and enter new filename to rename it__ 43 | """,reply_to_message_id = message.id , 44 | reply_markup=InlineKeyboardMarkup( 45 | [[ InlineKeyboardButton("Support 🇮🇳" ,url="https://t.me/WebXBots") ], 46 | [InlineKeyboardButton("Subscribe 🧐", url="https://youtube.com/@Divin_Dass") ] ])) 47 | return 48 | if id: 49 | if old == True: 50 | try: 51 | await client.send_message(id,"Your Friend already Using Our Bot") 52 | await message.reply_text(text =f""" 53 | Hello {wish} {message.from_user.first_name } 54 | __I am file renamer bot, Please sent any telegram 55 | **Document Or Video** and enter new filename to rename it__ 56 | """,reply_to_message_id = message.id , 57 | reply_markup=InlineKeyboardMarkup( 58 | [[ InlineKeyboardButton("Support 🇮🇳" ,url="https://t.me/WebXBots") ], 59 | [InlineKeyboardButton("Subscribe 🧐", url="https://youtube.com/@Divin_Dass") ] ])) 60 | except: 61 | return 62 | else: 63 | await client.send_message(id,"Congrats! You Won 100MB Upload limit") 64 | _user_= find_one(int(id)) 65 | limit = _user_["uploadlimit"] 66 | new_limit = limit + 104857600 67 | uploadlimit(int(id),new_limit) 68 | await message.reply_text(text =f""" 69 | Hello {wish} {message.from_user.first_name } 70 | __I am file renamer bot, Please sent any telegram 71 | **Document Or Video** and enter new filename to rename it__ 72 | """,reply_to_message_id = message.id , 73 | reply_markup=InlineKeyboardMarkup( 74 | [[ InlineKeyboardButton("Support 🇮🇳" ,url="https://t.me/WebXBots") ], 75 | [InlineKeyboardButton("Subscribe 🧐", url="https://youtube.com/@Divin_Dass") ] ])) 76 | 77 | 78 | 79 | 80 | @Client.on_message(filters.private &( filters.document | filters.audio | filters.video )) 81 | async def send_doc(client,message): 82 | update_channel = CHANNEL 83 | user_id = message.from_user.id 84 | if update_channel : 85 | try: 86 | await client.get_chat_member(update_channel, user_id) 87 | except UserNotParticipant: 88 | await message.reply_text("**__You are not subscribed my channel__** ", 89 | reply_to_message_id = message.id, 90 | reply_markup = InlineKeyboardMarkup( 91 | [ [ InlineKeyboardButton("Support 🇮🇳" ,url=f"https://t.me/{update_channel}") ] ])) 92 | return 93 | try: 94 | bot_data = find_one(int(botid)) 95 | prrename = bot_data['total_rename'] 96 | prsize = bot_data['total_size'] 97 | user_deta = find_one(user_id) 98 | except: 99 | await message.reply_text("Use About cmd first /about") 100 | try: 101 | used_date = user_deta["date"] 102 | buy_date= user_deta["prexdate"] 103 | daily = user_deta["daily"] 104 | user_type = user_deta["usertype"] 105 | except: 106 | await message.reply_text("database has been Cleared click on /start") 107 | return 108 | 109 | 110 | c_time = time.time() 111 | 112 | if user_type=="Free": 113 | LIMIT = 600 114 | else: 115 | LIMIT = 50 116 | then = used_date+ LIMIT 117 | left = round(then - c_time) 118 | conversion = datetime.timedelta(seconds=left) 119 | ltime = str(conversion) 120 | if left > 0: 121 | await message.reply_text(f"```Sorry Dude I am not only for YOU \n Flood control is active so please wait for {ltime}```",reply_to_message_id = message.id) 122 | else: 123 | # Forward a single message 124 | 125 | media = await client.get_messages(message.chat.id,message.id) 126 | file = media.document or media.video or media.audio 127 | dcid = FileId.decode(file.file_id).dc_id 128 | filename = file.file_name 129 | value = 2147483648 130 | used_ = find_one(message.from_user.id) 131 | used = used_["used_limit"] 132 | limit = used_["uploadlimit"] 133 | expi = daily - int(time.mktime(time.strptime(str(date_.today()), '%Y-%m-%d'))) 134 | if expi != 0: 135 | today = date_.today() 136 | pattern = '%Y-%m-%d' 137 | epcho = int(time.mktime(time.strptime(str(today), pattern))) 138 | daily_(message.from_user.id,epcho) 139 | used_limit(message.from_user.id,0) 140 | remain = limit- used 141 | if remain < int(file.file_size): 142 | await message.reply_text(f"Sorry! I can't upload files that are larger than {humanbytes(limit)}. File size detected {humanbytes(file.file_size)}\nUsed Daly Limit {humanbytes(used)} If U Want to Rename Large File Upgrade Your Plan ",reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("Upgrade 💰💳",callback_data = "upgrade") ]])) 143 | return 144 | if value < file.file_size: 145 | if STRING: 146 | if buy_date==None: 147 | await message.reply_text(f" You Can't Upload More Then {humanbytes(limit)} Used Daly Limit {humanbytes(used)} ",reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("Upgrade 💰💳",callback_data = "upgrade") ]])) 148 | return 149 | pre_check = check_expi(buy_date) 150 | if pre_check == True: 151 | await message.reply_text(f"""__What do you want me to do with this file?__\n**File Name** :- {filename}\n**File Size** :- {humanize.naturalsize(file.file_size)}\n**Dc ID** :- {dcid}""",reply_to_message_id = message.id,reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📝 Rename",callback_data = "rename"),InlineKeyboardButton("✖️ Cancel",callback_data = "cancel") ]])) 152 | total_rename(int(botid),prrename) 153 | total_size(int(botid),prsize,file.file_size) 154 | else: 155 | uploadlimit(message.from_user.id,2147483648) 156 | usertype(message.from_user.id,"Free") 157 | 158 | await message.reply_text(f'Your Plane Expired On {buy_date}',quote=True) 159 | return 160 | else: 161 | await message.reply_text("Can't upload files bigger than 2GB ") 162 | return 163 | else: 164 | if buy_date: 165 | pre_check = check_expi(buy_date) 166 | if pre_check == False: 167 | uploadlimit(message.from_user.id,2147483648) 168 | usertype(message.from_user.id,"Free") 169 | 170 | filesize = humanize.naturalsize(file.file_size) 171 | fileid = file.file_id 172 | total_rename(int(botid),prrename) 173 | total_size(int(botid),prsize,file.file_size) 174 | await message.reply_text(f"""__What do you want me to do with this file?__\n**File Name** :- {filename}\n**File Size** :- {filesize}\n**Dc ID** :- {dcid}""",reply_to_message_id = message.id,reply_markup = InlineKeyboardMarkup( 175 | [[ InlineKeyboardButton("📝 Rename",callback_data = "rename"), 176 | InlineKeyboardButton("✖️ Cancel",callback_data = "cancel") ]])) 177 | 178 | -------------------------------------------------------------------------------- /plugins/cb_data.py: -------------------------------------------------------------------------------- 1 | from helper.progress import progress_for_pyrogram 2 | from pyrogram import Client, filters 3 | from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply) 4 | from hachoir.metadata import extractMetadata 5 | from hachoir.parser import createParser 6 | from helper.database import * 7 | import os 8 | import random 9 | from PIL import Image 10 | import time 11 | from datetime import date as date_ 12 | from datetime import timedelta,datetime 13 | from helper.ffmpeg import take_screen_shot,fix_thumb 14 | from helper.progress import humanbytes 15 | from helper.set import escape_invalid_curly_brackets 16 | 17 | log_channel = int(os.environ.get("LOG_CHANNEL", "")) 18 | 19 | API_ID = int(os.environ.get("API_ID", "")) 20 | 21 | API_HASH = os.environ.get("API_HASH", "") 22 | 23 | STRING = os.environ.get("STRING", "") 24 | 25 | app = Client("test", api_id=API_ID, api_hash=API_HASH, session_string=STRING) 26 | 27 | @Client.on_callback_query(filters.regex('cancel')) 28 | async def cancel(bot,update): 29 | try: 30 | await update.message.delete() 31 | except: 32 | return 33 | 34 | 35 | @Client.on_callback_query(filters.regex('rename')) 36 | async def rename(bot,update): 37 | date_fa = str(update.message.date) 38 | pattern = '%Y-%m-%d %H:%M:%S' 39 | date = int(time.mktime(time.strptime(date_fa, pattern))) 40 | chat_id = update.message.chat.id 41 | id = update.message.reply_to_message_id 42 | await update.message.delete() 43 | await update.message.reply_text(f"__Please enter the new filename...__\n\nNote:- Extension Not Required",reply_to_message_id = id, 44 | reply_markup=ForceReply(True) ) 45 | dateupdate(chat_id,date) 46 | 47 | 48 | 49 | @Client.on_callback_query(filters.regex("doc")) 50 | async def doc(bot,update): 51 | new_name = update.message.text 52 | used_ = find_one(update.from_user.id) 53 | used = used_["used_limit"] 54 | date = used_["date"] 55 | name = new_name.split(":-") 56 | new_filename = name[1] 57 | file_path = f"downloads/{new_filename}" 58 | message = update.message.reply_to_message 59 | file = message.document or message.video or message.audio 60 | ms = await update.message.edit("```Trying To Download...```") 61 | used_limit(update.from_user.id,file.file_size) 62 | c_time = time.time() 63 | total_used = used + int(file.file_size) 64 | used_limit(update.from_user.id,total_used) 65 | try: 66 | path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) 67 | 68 | except Exception as e: 69 | neg_used = used - int(file.file_size) 70 | used_limit(update.from_user.id,neg_used) 71 | await ms.edit(e) 72 | return 73 | splitpath = path.split("/downloads/") 74 | dow_file_name = splitpath[1] 75 | old_file_name =f"downloads/{dow_file_name}" 76 | os.rename(old_file_name,file_path) 77 | user_id = int(update.message.chat.id) 78 | data = find(user_id) 79 | try: 80 | c_caption = data[1] 81 | except: 82 | pass 83 | thumb = data[0] 84 | if c_caption: 85 | doc_list= ["filename","filesize"] 86 | new_tex = escape_invalid_curly_brackets(c_caption,doc_list) 87 | caption = new_tex.format(filename=new_filename,filesize=humanbytes(file.file_size)) 88 | else: 89 | caption = f"**{new_filename}**" 90 | if thumb: 91 | ph_path = await bot.download_media(thumb) 92 | Image.open(ph_path).convert("RGB").save(ph_path) 93 | img = Image.open(ph_path) 94 | img.resize((320, 320)) 95 | img.save(ph_path, "JPEG") 96 | c_time = time.time() 97 | 98 | else: 99 | ph_path = None 100 | 101 | value = 2090000000 102 | if value < file.file_size: 103 | await ms.edit("```Trying To Upload```") 104 | try: 105 | filw = await app.send_document(log_channel,document = file_path,thumb=ph_path,caption = caption,progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 106 | from_chat = filw.chat.id 107 | mg_id = filw.id 108 | time.sleep(2) 109 | await bot.copy_message(update.from_user.id,from_chat,mg_id) 110 | await ms.delete() 111 | os.remove(file_path) 112 | try: 113 | os.remove(ph_path) 114 | except: 115 | pass 116 | except Exception as e: 117 | neg_used = used - int(file.file_size) 118 | used_limit(update.from_user.id,neg_used) 119 | await ms.edit(e) 120 | os.remove(file_path) 121 | try: 122 | os.remove(ph_path) 123 | except: 124 | return 125 | else: 126 | await ms.edit("```Trying To Upload```") 127 | c_time = time.time() 128 | try: 129 | await bot.send_document(update.from_user.id,document = file_path,thumb=ph_path,caption = caption,progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 130 | await ms.delete() 131 | os.remove(file_path) 132 | except Exception as e: 133 | neg_used = used - int(file.file_size) 134 | used_limit(update.from_user.id,neg_used) 135 | await ms.edit(e) 136 | os.remove(file_path) 137 | return 138 | 139 | 140 | 141 | @Client.on_callback_query(filters.regex("vid")) 142 | async def vid(bot,update): 143 | new_name = update.message.text 144 | used_ = find_one(update.from_user.id) 145 | used = used_["used_limit"] 146 | date = used_["date"] 147 | name = new_name.split(":-") 148 | new_filename = name[1] 149 | file_path = f"downloads/{new_filename}" 150 | message = update.message.reply_to_message 151 | file = message.document or message.video or message.audio 152 | ms = await update.message.edit("```Trying To Download...```") 153 | used_limit(update.from_user.id,file.file_size) 154 | c_time = time.time() 155 | total_used = used + int(file.file_size) 156 | used_limit(update.from_user.id,total_used) 157 | try: 158 | path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) 159 | 160 | except Exception as e: 161 | neg_used = used - int(file.file_size) 162 | used_limit(update.from_user.id,neg_used) 163 | await ms.edit(e) 164 | return 165 | splitpath = path.split("/downloads/") 166 | dow_file_name = splitpath[1] 167 | old_file_name =f"downloads/{dow_file_name}" 168 | os.rename(old_file_name,file_path) 169 | user_id = int(update.message.chat.id) 170 | data = find(user_id) 171 | try: 172 | c_caption = data[1] 173 | except: 174 | pass 175 | thumb = data[0] 176 | 177 | duration = 0 178 | metadata = extractMetadata(createParser(file_path)) 179 | if metadata.has("duration"): 180 | duration = metadata.get('duration').seconds 181 | if c_caption: 182 | vid_list = ["filename","filesize","duration"] 183 | new_tex = escape_invalid_curly_brackets(c_caption,vid_list) 184 | caption = new_tex.format(filename=new_filename,filesize=humanbytes(file.file_size),duration=timedelta(seconds=duration)) 185 | else: 186 | caption = f"**{new_filename}**" 187 | if thumb: 188 | ph_path = await bot.download_media(thumb) 189 | Image.open(ph_path).convert("RGB").save(ph_path) 190 | img = Image.open(ph_path) 191 | img.resize((320, 320)) 192 | img.save(ph_path, "JPEG") 193 | c_time = time.time() 194 | 195 | else: 196 | try: 197 | ph_path_ = await take_screen_shot(file_path,os.path.dirname(os.path.abspath(file_path)), random.randint(0, duration - 1)) 198 | width, height, ph_path = await fix_thumb(ph_path_) 199 | except Exception as e: 200 | ph_path = None 201 | print(e) 202 | 203 | value = 2090000000 204 | if value < file.file_size: 205 | await ms.edit("```Trying To Upload```") 206 | try: 207 | filw = await app.send_video(log_channel,video= file_path,thumb=ph_path,duration=duration ,caption = caption,progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 208 | from_chat = filw.chat.id 209 | mg_id = filw.id 210 | time.sleep(2) 211 | await bot.copy_message(update.from_user.id,from_chat,mg_id) 212 | await ms.delete() 213 | os.remove(file_path) 214 | try: 215 | os.remove(ph_path) 216 | except: 217 | pass 218 | except Exception as e: 219 | neg_used = used - int(file.file_size) 220 | used_limit(update.from_user.id,neg_used) 221 | await ms.edit(e) 222 | os.remove(file_path) 223 | try: 224 | os.remove(ph_path) 225 | except: 226 | return 227 | else: 228 | await ms.edit("```Trying To Upload```") 229 | c_time = time.time() 230 | try: 231 | await bot.send_video(update.from_user.id,video = file_path,thumb=ph_path,duration=duration,caption = caption,progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 232 | await ms.delete() 233 | os.remove(file_path) 234 | except Exception as e: 235 | neg_used = used - int(file.file_size) 236 | used_limit(update.from_user.id,neg_used) 237 | await ms.edit(e) 238 | os.remove(file_path) 239 | return 240 | 241 | 242 | 243 | 244 | @Client.on_callback_query(filters.regex("aud")) 245 | async def aud(bot,update): 246 | new_name = update.message.text 247 | used_ = find_one(update.from_user.id) 248 | used = used_["used_limit"] 249 | name = new_name.split(":-") 250 | new_filename = name[1] 251 | file_path = f"downloads/{new_filename}" 252 | message = update.message.reply_to_message 253 | file = message.document or message.video or message.audio 254 | total_used = used + int(file.file_size) 255 | used_limit(update.from_user.id,total_used) 256 | ms = await update.message.edit("```Trying To Download...```") 257 | c_time = time.time() 258 | try: 259 | path = await bot.download_media(message = file , progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) 260 | except Exception as e: 261 | neg_used = used - int(file.file_size) 262 | used_limit(update.from_user.id,neg_used) 263 | await ms.edit(e) 264 | return 265 | splitpath = path.split("/downloads/") 266 | dow_file_name = splitpath[1] 267 | old_file_name =f"downloads/{dow_file_name}" 268 | os.rename(old_file_name,file_path) 269 | duration = 0 270 | metadata = extractMetadata(createParser(file_path)) 271 | if metadata.has("duration"): 272 | duration = metadata.get('duration').seconds 273 | user_id = int(update.message.chat.id) 274 | data = find(user_id) 275 | c_caption = data[1] 276 | thumb = data[0] 277 | if c_caption: 278 | aud_list = ["filename","filesize","duration"] 279 | new_tex = escape_invalid_curly_brackets(c_caption,aud_list) 280 | caption = new_tex.format(filename=new_filename,filesize=humanbytes(file.file_size),duration=timedelta(seconds=duration)) 281 | else: 282 | caption = f"**{new_filename}**" 283 | 284 | if thumb: 285 | ph_path = await bot.download_media(thumb) 286 | Image.open(ph_path).convert("RGB").save(ph_path) 287 | img = Image.open(ph_path) 288 | img.resize((320, 320)) 289 | img.save(ph_path, "JPEG") 290 | await ms.edit("```Trying To Upload```") 291 | c_time = time.time() 292 | try: 293 | await bot.send_audio(update.message.chat.id,audio = file_path,caption = caption,thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 294 | await ms.delete() 295 | os.remove(file_path) 296 | os.remove(ph_path) 297 | except Exception as e: 298 | neg_used = used - int(file.file_size) 299 | used_limit(update.from_user.id,neg_used) 300 | await ms.edit(e) 301 | os.remove(file_path) 302 | os.remove(ph_path) 303 | else: 304 | await ms.edit("```Trying To Upload```") 305 | c_time = time.time() 306 | try: 307 | await bot.send_audio(update.message.chat.id,audio = file_path,caption = caption,duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) 308 | await ms.delete() 309 | os.remove(file_path) 310 | except Exception as e: 311 | await ms.edit(e) 312 | neg_used = used - int(file.file_size) 313 | used_limit(update.from_user.id,neg_used) 314 | os.remove(file_path) 315 | --------------------------------------------------------------------------------