Skip to content

Commit

Permalink
Ytdlp Issue Resolution, File Press Reversion, and Code Cleanup
Browse files Browse the repository at this point in the history
- Resolved the Ytdlp issue.[Major]
- Reverted the file press function to its previous state.
- Removed unnecessary code.
  • Loading branch information
5hojib authored Sep 27, 2023
1 parent 24a3f79 commit b7f2837
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 317 deletions.
32 changes: 6 additions & 26 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
else:
config_dict = {}

USER_TD_SA = environ.get('USER_TD_SA', '')
if len(USER_TD_SA) != 0:
USER_TD_SA = USER_TD_SA.lower()
GROUPS_EMAIL = environ.get('GROUPS_EMAIL', '')
if len(GROUPS_EMAIL) != 0:
GROUPS_EMAIL = GROUPS_EMAIL.lower()

OWNER_ID = environ.get('OWNER_ID', '')
if len(OWNER_ID) == 0:
Expand Down Expand Up @@ -174,6 +174,8 @@
log_error(f"Failed making client from USER_SESSION_STRING : {e}")
user = ''

MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000

MEGA_EMAIL = environ.get('MEGA_EMAIL', '')
MEGA_PASSWORD = environ.get('MEGA_PASSWORD', '')
if len(MEGA_EMAIL) == 0 or len(MEGA_PASSWORD) == 0:
Expand All @@ -197,14 +199,6 @@
if len(STREAMWISH_API) == 0:
STREAMWISH_API = ''

MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000

LEECH_SPLIT_SIZE = environ.get('LEECH_SPLIT_SIZE', '')
if str(LEECH_SPLIT_SIZE) in ["4194304000", "2097152000"] or len(LEECH_SPLIT_SIZE) == 0 or int(LEECH_SPLIT_SIZE) > MAX_SPLIT_SIZE:
LEECH_SPLIT_SIZE = MAX_SPLIT_SIZE
else:
LEECH_SPLIT_SIZE = int(LEECH_SPLIT_SIZE)

BOT_MAX_TASKS = environ.get('BOT_MAX_TASKS', '')
BOT_MAX_TASKS = int(BOT_MAX_TASKS) if BOT_MAX_TASKS.isdigit() else ''

Expand Down Expand Up @@ -257,9 +251,6 @@
SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '')
SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true'

EQUAL_SPLITS = environ.get('EQUAL_SPLITS', '')
EQUAL_SPLITS = EQUAL_SPLITS.lower() == 'true'

MEDIA_GROUP = environ.get('MEDIA_GROUP', '')
MEDIA_GROUP = MEDIA_GROUP.lower() == 'true'

Expand Down Expand Up @@ -336,13 +327,6 @@
'[', '').replace(']', '').replace(",", "")).split()


IMG_SEARCH = environ.get('IMG_SEARCH', '')
IMG_SEARCH = (IMG_SEARCH.replace("'", '').replace('"', '').replace(
'[', '').replace(']', '').replace(",", "")).split()

IMG_PAGE = environ.get('IMG_PAGE', '')
IMG_PAGE = 1 if not IMG_PAGE else int(IMG_PAGE)

SET_COMMANDS = environ.get('SET_COMMANDS', '')
SET_COMMANDS = SET_COMMANDS.lower() == 'true'

Expand Down Expand Up @@ -372,15 +356,11 @@
'MIRROR_LOG_ID': MIRROR_LOG_ID,
'LEECH_DUMP_ID': LEECH_DUMP_ID,
'IMAGES': IMAGES,
'IMG_SEARCH': IMG_SEARCH,
'IMG_PAGE': IMG_PAGE,
'EQUAL_SPLITS': EQUAL_SPLITS,
'EXTENSION_FILTER': EXTENSION_FILTER,
'GDRIVE_ID': GDRIVE_ID,
'INDEX_URL': INDEX_URL,
'JIODRIVE_TOKEN': JIODRIVE_TOKEN,
'LEECH_LOG_ID': LEECH_LOG_ID,
'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE,
'TOKEN_TIMEOUT': TOKEN_TIMEOUT,
'MEDIA_GROUP': MEDIA_GROUP,
'MEGA_EMAIL': MEGA_EMAIL,
Expand Down Expand Up @@ -410,7 +390,7 @@
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'USER_SESSION_STRING': USER_SESSION_STRING,
'USER_TD_SA': USER_TD_SA,
'GROUPS_EMAIL': GROUPS_EMAIL,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'WEB_PINCODE': WEB_PINCODE,
'YT_DLP_OPTIONS': YT_DLP_OPTIONS}
Expand Down
82 changes: 18 additions & 64 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ async def stats(_, message):
cpuUsage = cpu_percent(interval=0.5)
quote = Quote.print().split('―', 1)[0].strip().replace("“", "").replace("”", "")
limit_mapping = {
'Torrent': config_dict.get('TORRENT_LIMIT', '∞'),
'Gdrive': config_dict.get('GDRIVE_LIMIT', '∞'),
'Ytdlp': config_dict.get('YTDLP_LIMIT', '∞'),
'Direct': config_dict.get('DIRECT_LIMIT', '∞'),
'Leech': config_dict.get('LEECH_LIMIT', '∞'),
'Clone': config_dict.get('CLONE_LIMIT', '∞'),
'Mega': config_dict.get('MEGA_LIMIT', '∞'),
'User tasks': config_dict.get('USER_MAX_TASKS', '∞'),
}
'Torrent' : config_dict.get('TORRENT_LIMIT', '∞'),
'Gdrive' : config_dict.get('GDRIVE_LIMIT', '∞'),
'Ytdlp' : config_dict.get('YTDLP_LIMIT', '∞'),
'Direct' : config_dict.get('DIRECT_LIMIT', '∞'),
'Leech' : config_dict.get('LEECH_LIMIT', '∞'),
'Clone' : config_dict.get('CLONE_LIMIT', '∞'),
'Mega' : config_dict.get('MEGA_LIMIT', '∞'),
'User task': config_dict.get('USER_MAX_TASKS', '∞')}
system_info = f'<b>{quote}</b>\n\n'\
f'<code>• Bot uptime :</code> {currentTime}\n'\
f'<code>• Sys uptime :</code> {osUptime}\n'\
Expand All @@ -65,7 +64,7 @@ async def stats(_, message):
for k, v in limit_mapping.items():
if v == '':
v = '∞'
elif k != 'User tasks':
elif k != 'User task':
v = f'{v}GB/Link'
else:
v = f'{v} Tasks/user'
Expand Down Expand Up @@ -204,30 +203,6 @@ async def log(_, message):
await deleteMessage(message)
await five_minute_del(reply_message)

async def search_images():
if not config_dict['IMG_SEARCH']:
return
try:
query_list = config_dict['IMG_SEARCH']
total_pages = config_dict['IMG_PAGE']
base_url = "https://www.wallpaperflare.com/search"

for query in query_list:
query = query.strip().replace(" ", "+")
for page in range(1, total_pages + 1):
url = f"{base_url}?wallpaper={query}&width=1280&height=720&page={page}"
r = rget(url)
soup = BeautifulSoup(r.text, "html.parser")
images = soup.select('img[data-src^="https://c4.wallpaperflare.com/wallpaper"]')
for img in images:
img_url = img['data-src']
if img_url not in config_dict['IMAGES']:
config_dict['IMAGES'].append(img_url)
if DATABASE_URL:
await DbManager().update_config({'IMAGES': config_dict['IMAGES']})
except Exception as e:
LOGGER.error(f"An error occurred: {e}")


help_string = f'''
NOTE: Try each command without any arguments to see more details.
Expand All @@ -243,8 +218,7 @@ async def search_images():
/{BotCommands.UserSetCommand} [query]: User settings.
/{BotCommands.BotSetCommand} [query]: Bot settings.
/{BotCommands.BtSelectCommand}: Select files from torrents by gid or reply.
/{BotCommands.CancelMirror}: Cancels task by gid or reply.
/{BotCommands.CancelAllCommand} [query]: Cancels all [status] tasks.
/{BotCommands.CancelAllCommand} [query]: Cancel all [status] tasks.
/{BotCommands.ListCommand} [query]: Searches in Google Drive(s).
/{BotCommands.SearchCommand} [query]: Searches for torrents with API.
/{BotCommands.StatusCommand}: Shows status of all downloads.
Expand Down Expand Up @@ -272,27 +246,13 @@ async def bot_help(client, message):


async def restart_notification():
now = datetime.now(timezone('Asia/Dhaka'))
date = now.strftime('%d/%m/%y')
time = now.strftime('%I:%M:%S %p')
rmsg = f'Restarted Successfully!\n\n<b>Date:</b> {date}\n<b>Time:</b> {time}'
if await aiopath.isfile(".restartmsg"):
with open(".restartmsg") as f:
chat_id, msg_id = map(int, f)
else:
chat_id, msg_id = 0, 0

async def send_incompelete_task_message(cid, msg):
try:
if msg.startswith(rmsg):
await bot.edit_message_text(chat_id=chat_id, message_id=msg_id, text=msg)
await aioremove(".restartmsg")
else:
await bot.send_message(chat_id=cid, text=msg, disable_web_page_preview=True, disable_notification=True)
except Exception as e:
LOGGER.error(e)

if await aiopath.isfile(".restartmsg"):
rmsg = 'Restarted Successfully!'
try:
await bot.edit_message_text(chat_id=chat_id, message_id=msg_id, text=rmsg)
except:
Expand All @@ -301,21 +261,15 @@ async def send_incompelete_task_message(cid, msg):


async def main():
await gather(start_cleanup(), torrent_search.initiate_search_tools(), restart_notification(), search_images(), set_commands(bot))
await gather(start_cleanup(), torrent_search.initiate_search_tools(), restart_notification(), set_commands(bot))
await sync_to_async(start_aria2_listener, wait=False)

bot.add_handler(MessageHandler(start, filters=command(
BotCommands.StartCommand)))
bot.add_handler(MessageHandler(log, filters=command(
BotCommands.LogCommand) & CustomFilters.sudo))
bot.add_handler(MessageHandler(restart, filters=command(
BotCommands.RestartCommand) & CustomFilters.sudo))
bot.add_handler(MessageHandler(ping, filters=command(
BotCommands.PingCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(bot_help, filters=command(
BotCommands.HelpCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(stats, filters=command(
BotCommands.StatsCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(start, filters=command(BotCommands.StartCommand)))
bot.add_handler(MessageHandler(log, filters=command(BotCommands.LogCommand) & CustomFilters.sudo))
bot.add_handler(MessageHandler(restart, filters=command(BotCommands.RestartCommand) & CustomFilters.sudo))
bot.add_handler(MessageHandler(ping, filters=command(BotCommands.PingCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(bot_help, filters=command(BotCommands.HelpCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(stats, filters=command(BotCommands.StatsCommand) & CustomFilters.authorized))
bot.add_handler(CallbackQueryHandler(aeoncb, filters=regex(r'^aeon')))
LOGGER.info("Bot Started!")
signal(SIGINT, exit_clean_up)
Expand Down
46 changes: 21 additions & 25 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ def get_readable_message():
else:
msg += f"\nSize: {download.size()}"
msg += f"\nElapsed: {get_readable_time(time() - download.message.date.timestamp())}"
msg += f"\nMode: {download.upload_details['mode']}"
msg += f"\n/{BotCommands.CancelMirror}_{download.gid()[:8]}\n\n"
msg += f"\n/stop_{download.gid()[:8]}\n\n"
if len(msg) == 0:
return None, None
dl_speed = 0
Expand Down Expand Up @@ -284,7 +283,7 @@ def is_telegram_link(url):

def is_share_link(url):
domain = urlparse(url).hostname
return any(x in domain for x in ['appdirve', 'hubdrive', 'jiodrive'])
return any(x in domain for x in ['appdirve', 'hubdrive', 'jiodrive', 'filepress'])


def is_mega_link(url):
Expand Down Expand Up @@ -459,25 +458,22 @@ def extra_btns(buttons):
async def set_commands(client):
if config_dict['SET_COMMANDS']:
await client.set_bot_commands(
[
BotCommand(f'{BotCommands.MirrorCommand[0]}', f'or /{BotCommands.MirrorCommand[1]} Mirror'),
BotCommand(f'{BotCommands.LeechCommand[0]}', f'or /{BotCommands.LeechCommand[1]} Leech'),
BotCommand(f'{BotCommands.QbMirrorCommand[0]}', f'or /{BotCommands.QbMirrorCommand[1]} Mirror torrent using qBittorrent'),
BotCommand(f'{BotCommands.QbLeechCommand[0]}', f'or /{BotCommands.QbLeechCommand[1]} Leech torrent using qBittorrent'),
BotCommand(f'{BotCommands.YtdlCommand[0]}', f'or /{BotCommands.YtdlCommand[1]} Mirror yt-dlp supported link'),
BotCommand(f'{BotCommands.YtdlLeechCommand[0]}', f'or /{BotCommands.YtdlLeechCommand[1]} Leech through yt-dlp supported link'),
BotCommand(f'{BotCommands.CloneCommand}', 'Copy file/folder to Drive'),
BotCommand(f'{BotCommands.CountCommand}', '[drive_url]: Count file/folder of Google Drive.'),
BotCommand(f'{BotCommands.StatusCommand[0]}', f'or /{BotCommands.StatusCommand[1]} Get mirror status message'),
BotCommand(f'{BotCommands.StatsCommand}', 'Check Bot & System stats'),
BotCommand(f'{BotCommands.CancelAllCommand[0]}', 'Cancel all tasks which added by you to in bots.'),
BotCommand(f'{BotCommands.ListCommand}', 'Search in Drive'),
BotCommand(f'{BotCommands.SearchCommand}', 'Search in Torrent'),
BotCommand(f'{BotCommands.UserSetCommand[0]}', 'Users settings'),
BotCommand(f'{BotCommands.HelpCommand}', 'Get detailed help'),
BotCommand(f'{BotCommands.BotSetCommand}', 'Open Bot settings'),
BotCommand(f'{BotCommands.LogCommand}', 'View log'),
BotCommand(f'{BotCommands.RestartCommand[0]}', 'Restart bot'),
BotCommand(f'{BotCommands.MediaInfoCommand}', 'Get MediaInfo')
]
)
[BotCommand(f'{BotCommands.MirrorCommand[0]}', f'or /{BotCommands.MirrorCommand[1]} Mirror'),
BotCommand(f'{BotCommands.LeechCommand[0]}', f'or /{BotCommands.LeechCommand[1]} Leech'),
BotCommand(f'{BotCommands.QbMirrorCommand[0]}', f'or /{BotCommands.QbMirrorCommand[1]} Mirror torrent using qBittorrent'),
BotCommand(f'{BotCommands.QbLeechCommand[0]}', f'or /{BotCommands.QbLeechCommand[1]} Leech torrent using qBittorrent'),
BotCommand(f'{BotCommands.YtdlCommand[0]}', f'or /{BotCommands.YtdlCommand[1]} Mirror yt-dlp supported link'),
BotCommand(f'{BotCommands.YtdlLeechCommand[0]}', f'or /{BotCommands.YtdlLeechCommand[1]} Leech through yt-dlp supported link'),
BotCommand(f'{BotCommands.CloneCommand}', 'Copy file/folder to Drive'),
BotCommand(f'{BotCommands.StatusCommand[0]}', f'or /{BotCommands.StatusCommand[1]} Get mirror status message'),
BotCommand(f'{BotCommands.StatsCommand[0]}', 'Check Bot & System stats'),
BotCommand(f'{BotCommands.CancelAllCommand[0]}', 'Cancel all tasks which added by you to in bots.'),
BotCommand(f'{BotCommands.ListCommand}', 'Search in Drive'),
BotCommand(f'{BotCommands.SearchCommand}', 'Search in Torrent'),
BotCommand(f'{BotCommands.UserSetCommand[0]}', 'Users settings'),
BotCommand(f'{BotCommands.HelpCommand}', 'Get detailed help'),
BotCommand(f'{BotCommands.BotSetCommand}', 'Open Bot settings'),
BotCommand(f'{BotCommands.LogCommand}', 'View log'),
BotCommand(f'{BotCommands.MediaInfoCommand}', 'Get MediaInfo'),
BotCommand(f'{BotCommands.CountCommand}', 'Count file/folder of Google Drive.'),
BotCommand(f'{BotCommands.RestartCommand[0]}', 'Restart bot')])
3 changes: 0 additions & 3 deletions bot/helper/ext_utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ class DirectDownloadLinkException(Exception):


class NotSupportedExtractionArchive(Exception):
"""The archive format use is trying to extract is not supported"""
pass


class RssShutdownException(Exception):
"""This exception should be raised when shutdown is called to stop the montior"""
pass


class TgLinkException(Exception):
"""No Access granted for this chat"""
pass
4 changes: 1 addition & 3 deletions bot/helper/ext_utils/leech_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ async def split_file(path, size, file_, dirpath, split_size, listener, start_tim
await mkdir(dirpath)
user_id = listener.message.from_user.id
user_dict = user_data.get(user_id, {})
leech_split_size = user_dict.get('split_size') or config_dict['LEECH_SPLIT_SIZE']
leech_split_size = MAX_SPLIT_SIZE
parts = -(-size // leech_split_size)
if (user_dict.get('equal_splits') or config_dict['EQUAL_SPLITS'] and 'equal_splits' not in user_dict) and not inLoop:
split_size = ((size + parts - 1) // parts) + 1000
if (await get_document_type(path))[0]:
if multi_streams:
multi_streams = await is_multi_streams(path)
Expand Down
6 changes: 1 addition & 5 deletions bot/helper/ext_utils/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
'YTDLP_LIMIT': 'To limit the size of ytdlp download. the default unit is GB. Int',
'PLAYLIST_LIMIT': 'To limit Maximum Playlist Number. Int',
'IMAGES': 'Add multiple telgraph(graph.org) image links that are seperated by spaces.',
'IMG_SEARCH': 'Put Keyword to Download Images. Sperarte each name by , like anime, iron man, god of war',
'IMG_PAGE': 'Set the page value for downloading a image. Each page have approx 70 images. Deafult is 1. Int',
'USER_MAX_TASKS': 'Limit the Maximum task for users of group at a time. use the Int',
'GDRIVE_LIMIT': 'To limit the size of Google Drive folder/file link for leech, Zip, Unzip. the default unit is GB. Int',
'USER_TASKS_LIMIT': 'The maximum limit on every users for all tasks. Int',
Expand All @@ -25,13 +23,11 @@
'DEFAULT_UPLOAD': 'Whether rc to upload to RCLONE_PATH or gd to upload to GDRIVE_ID. Default is gd.',
'LEECH_DUMP_ID': "Chat ID to where leeched files would be uploaded. Int. NOTE: Only available for superGroup/channel. Add -100 before channel/superGroup id. In short don't add bot id or your id!",
'MIRROR_LOG_ID': "Chat ID to where Mirror files would be Send. Int. NOTE: Only available for superGroup/channel. Add -100 before channel/superGroup id. In short don't add bot id or your id!. For Multiple id Separate them by space.",
'EQUAL_SPLITS': 'Split files larger than LEECH_SPLIT_SIZE into equal parts size (Not working with zip cmd). Default is False.',
'EXTENSION_FILTER': "File extensions that won't upload/clone. Separate them by space.",
'GDRIVE_ID': 'This is the Folder/TeamDrive ID of the Google Drive OR root to which you want to upload all the mirrors using google-api-python-client.',
'INDEX_URL': 'Refer to https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index.',
'SHOW_MEDIAINFO': 'Add Button to Show MediaInfo in Leeched file. Bool',
'TOKEN_TIMEOUT': 'Token timeout for each group member in sec. Int',
'LEECH_SPLIT_SIZE': 'Size of split in bytes. Default is 2GB. Default is 4GB if your account is premium.',
'MEDIA_GROUP': 'View Uploaded splitted file parts in media group. Default is False.',
'MEGA_EMAIL': 'E-Mail used to sign-in on mega.nz for using premium account. Str',
'MEGA_PASSWORD': 'Password for mega.nz account. Str',
Expand Down Expand Up @@ -73,7 +69,7 @@
'thumb': ['Custom Thumbnail to appear on the Leeched files uploaded by the bot', 'Send a photo to save it as custom thumbnail. Timeout: 60 sec'],
'yt_opt': ['YT-DLP Options is the Custom Quality for the extraction of videos from the yt-dlp supported sites.', 'Send YT-DLP Options. Timeout: 60 sec\nFormat: key:value|key:value|key:value.\nExample: format:bv*+mergeall[vcodec=none]|nocheckcertificate:True\nCheck all yt-dlp api options from this <a href="https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L184">FILE</a> or use this <a href="https://t.me/mltb_official/177">script</a> to convert cli arguments to api options.'],
'split_size': ['Leech Splits Size is the size to split the Leeched File before uploading', f'Send Leech split size in bytes. IS_PREMIUM_USER: {IS_PREMIUM_USER}. Timeout: 60 sec'],
'user_tds': [f'UserTD helps to upload files via Bot to your Custom Drive Destination through Global SA Mail.\n\n<b>SA Mail:</b> {SA if (SA := config_dict["USER_TD_SA"]) else "Not Specified"}','Send User TD details for use while Mirror/Clone.\n<b>Format:</b> \nname drive_id/link index(optional)\n\n<b>NOTE:</b> \n1. Must add our sa mail in your drive with write permission\n2. Names can have spaces.\n3. Drive ID must be valid for acceptance.\n\n<b>Timeout:</b> 60 sec.'],
'user_tds': [f'UserTD helps to upload files via Bot to your Custom Drive Destination through Global SA Mail.\n\n<b>SA Mail:</b> {SA if (SA := config_dict["GROUPS_EMAIL"]) else "Not Specified"}','Send User TD details for use while Mirror/Clone.\n<b>Format:</b> \nname drive_id/link index(optional)\n\n<b>NOTE:</b> \n1. Must add our sa mail in your drive with write permission\n2. Names can have spaces.\n3. Drive ID must be valid for acceptance.\n\n<b>Timeout:</b> 60 sec.'],
}

nsfw_keywords = [
Expand Down
Loading

0 comments on commit b7f2837

Please sign in to comment.