Skip to content

Commit

Permalink
v1.3.2 🎛 Twick Changez
Browse files Browse the repository at this point in the history
* Added more Docs in BSet
* Added SCREENSHOTS_MODE to enable/disable use of -ss arg
* SAFE_MODE Enhanced.
* Added Logging Pre Check to Tell Proper Error Guides
* Added -t or -thumb for Custom Thumbnail on Every Leech
* Bump to v1.3.2 (Proper)
* Added New Param : {subtitles} for Leech Caption
* Quality param Rounded Off to Nearest video quality
* Fixed Files not Send on BOT PM & some Minor changes...
* GitLab Updated Soon.

# Stable # Fast # Nicer

---------

Co-authored-by: Karan Adhikari <[email protected]>
  • Loading branch information
SilentDemonSD and weebzone authored Sep 16, 2023
1 parent 46dd8ca commit 97bd342
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 49 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ help - All cmds with description
<summary><b>M/L Buttons</b></summary>

- `SHOW_MEDIAINFO`: Mediainfo button of file. Default is `False`. `Bool`
- `SCREENSHOTS_MODE`: Enable or Diable generating Screenshots via -ss arg. Default is `False`. `Bool`
- `SAVE_MSG`: Save Button in each file and link so that every user direcly save it without forwarding. Default is `False`. `Bool`
- `SOURCE_LINK`: Source button of files and links. Default is `False`. `Bool`
</details></li>
Expand Down
34 changes: 19 additions & 15 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ def changetz(*args):
x = x.lstrip('.')
GLOBAL_EXTENSION_FILTER.append(x.strip().lower())

LINKS_LOG_ID = environ.get('LINKS_LOG_ID', '')
LINKS_LOG_ID = '' if len(LINKS_LOG_ID) == 0 else int(LINKS_LOG_ID)

MIRROR_LOG_ID = environ.get('MIRROR_LOG_ID', '')
if len(MIRROR_LOG_ID) == 0:
MIRROR_LOG_ID = ''

LEECH_LOG_ID = environ.get('LEECH_LOG_ID', '')
if len(LEECH_LOG_ID) == 0:
LEECH_LOG_ID = ''

EXCEP_CHATS = environ.get('EXCEP_CHATS', '')
if len(EXCEP_CHATS) == 0:
EXCEP_CHATS = ''

IS_PREMIUM_USER = False
user = ''
USER_SESSION_STRING = environ.get('USER_SESSION_STRING', '')
Expand Down Expand Up @@ -354,6 +369,9 @@ def changetz(*args):
SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '')
SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true'

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

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

Expand Down Expand Up @@ -437,21 +455,6 @@ def changetz(*args):
FSUB_IDS = environ.get('FSUB_IDS', '')
if len(FSUB_IDS) == 0:
FSUB_IDS = ''

LINKS_LOG_ID = environ.get('LINKS_LOG_ID', '')
LINKS_LOG_ID = '' if len(LINKS_LOG_ID) == 0 else int(LINKS_LOG_ID)

MIRROR_LOG_ID = environ.get('MIRROR_LOG_ID', '')
if len(MIRROR_LOG_ID) == 0:
MIRROR_LOG_ID = ''

LEECH_LOG_ID = environ.get('LEECH_LOG_ID', '')
if len(LEECH_LOG_ID) == 0:
LEECH_LOG_ID = ''

EXCEP_CHATS = environ.get('EXCEP_CHATS', '')
if len(EXCEP_CHATS) == 0:
EXCEP_CHATS = ''

BOT_PM = environ.get('BOT_PM', '')
BOT_PM = BOT_PM.lower() == 'true'
Expand Down Expand Up @@ -671,6 +674,7 @@ def changetz(*args):
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SET_COMMANDS': SET_COMMANDS,
'SHOW_MEDIAINFO': SHOW_MEDIAINFO,
'SCREENSHOTS_MODE': SCREENSHOTS_MODE,
'CLEAN_LOG_MSG': CLEAN_LOG_MSG,
'SHOW_EXTRA_CMDS': SHOW_EXTRA_CMDS,
'SOURCE_LINK': SOURCE_LINK,
Expand Down
31 changes: 29 additions & 2 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from aiofiles.os import path as aiopath, remove as aioremove
from aiofiles import open as aiopen
from pyrogram import idle
from pyrogram.enums import ChatMemberStatus, ChatType
from pyrogram.handlers import MessageHandler, CallbackQueryHandler
from pyrogram.filters import command, private, regex
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
Expand Down Expand Up @@ -211,8 +212,34 @@ async def send_incompelete_task_message(cid, msg):
await aioremove(".restartmsg")


async def log_check():
if config_dict['LEECH_LOG_ID']:
for chat_id in config_dict['LEECH_LOG_ID'].split():
chat_id, *topic_id = chat_id.split(":")
try:
chat = await bot.get_chat(int(chat_id))
except Exception:
LOGGER.error(f"Not Connected Chat ID : {chat_id}, Make sure the Bot is Added!")
continue
if chat.type == ChatType.CHANNEL:
if not (await chat.get_member(bot.me.id)).privileges.can_post_messages:
LOGGER.error(f"Not Connected Chat ID : {chat_id}, Make the Bot is Admin in Channel to Connect!")
continue
if user and not (await chat.get_member(user.me.id)).privileges.can_post_messages:
LOGGER.error(f"Not Connected Chat ID : {chat_id}, Make the User is Admin in Channel to Connect!")
continue
elif chat.type == ChatType.SUPERGROUP:
if not (await chat.get_member(bot.me.id)).status in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]:
LOGGER.error(f"Not Connected Chat ID : {chat_id}, Make the Bot is Admin in Group to Connect!")
continue
if user and not (await chat.get_member(user.me.id)).status in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]:
LOGGER.error(f"Not Connected Chat ID : {chat_id}, Make the User is Admin in Group to Connect!")
continue
LOGGER.info(f"Connected Chat ID : {chat_id}")


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(), search_images(), set_commands(bot), log_check())
await sync_to_async(start_aria2_listener, wait=False)

bot.add_handler(MessageHandler(
Expand All @@ -233,7 +260,7 @@ async def main():
BotCommands.StatsCommand) & CustomFilters.authorized & ~CustomFilters.blacklisted))
LOGGER.info(f"WZML-X Bot [@{bot_name}] Started!")
if user:
LOGGER.info(f"WZ's User [@{user.me.first_name}] Ready!")
LOGGER.info(f"WZ's User [@{user.me.username}] Ready!")
signal(SIGINT, exit_clean_up)

async def stop_signals():
Expand Down
42 changes: 35 additions & 7 deletions bot/helper/ext_utils/help_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
11. <b>-index:</b> Index url for gdrive_arg
12. <b>-c or -category :</b> Gdrive category to Upload, Specific Name (case insensitive)
13. <b>-ud or -dump :</b> Dump category to Upload, Specific Name (case insensitive) or chat_id or chat_username
14. <b>-ss or -screenshots :</b> Generate Screenshots for Leeched Files
15. <b>-t or -thumb :</b> Custom Thumb for Specific Leech
""", """
➲ <b><i>Send link along with command line</i></b>:
<code>/cmd</code> link -s -n new name -opt x:y|x1:y1
Expand All @@ -29,6 +31,14 @@
<code>/cmd</code> link -n new name
<b>Note:</b> Don't add file extension
➲ <b><i>Screenshot Generation</b>: -ss or -screenshots
<code>/cmd</code> link -ss number ,Screenshots for each Video File
➲ <b><i>Custom Thumbnail</b>: -t or -thumb
<code>/cmd</code> link -t tglink|dl_link
<b>Direct Link:</b> dl_link specifies download link, where it is Image url
<b>Tg Link:</b> Give Public/Private/Super Link to download Image from Tg
➲ <b><i>Quality Buttons</i></b>: -s or -select
Incase default quality added from yt-dlp options using format option and you need to select quality for specific link or links with multi links feature.
<code>/cmd</code> link -s
Expand Down Expand Up @@ -119,7 +129,8 @@
17. <b>-index:</b> Index url for gdrive_arg
18. <b>-c or -category :</b> Gdrive category to Upload, Specific Name (case insensitive)
19. <b>-ud or -dump :</b> Dump category to Upload, Specific Name (case insensitive) or chat_id or chat_username
20. <b>-ss or -screenshots :</b> Generate Screenshots for Leeched Files, Specify 1, 3, .. after this.
20. <b>-ss or -screenshots :</b> Generate Screenshots for Leeched Files
21. <b>-t or -thumb :</b> Custom Thumb for Specific Leech
""", """
➲ <b><i>By along the cmd</i></b>:
<code>/cmd</code> link -n new name
Expand All @@ -134,12 +145,17 @@
➲ <b><i>Direct Link Authorization</i></b>: -u -p or -user -pass
<code>/cmd</code> link -u username -p password
➲ <b>Direct link custom headers</b>: -h or -headers
➲ <b><i>Direct link custom headers</i></b>: -h or -headers
<code>/cmd</code> link -h key: value key1: value1
➲ <b>Screenshot Generation</b>: -ss or -screenshots
➲ <b><i>Screenshot Generation</b>: -ss or -screenshots
<code>/cmd</code> link -ss number ,Screenshots for each Video File
➲ <b><i>Custom Thumbnail</b>: -t or -thumb
<code>/cmd</code> link -t tglink|dl_link
<b>Direct Link:</b> dl_link specifies download link, where it is Image url
<b>Tg Link:</b> Give Public/Private/Super Link to download Image from Tg
➲ <b><i>Extract / Zip</i></b>: -uz -z or -zip -unzip or -e -extract
<code>/cmd</code> link -e password (extract password protected)
<code>/cmd</code> link -z password (zip password protected)
Expand Down Expand Up @@ -418,6 +434,8 @@
'AUTO_DELETE_MESSAGE_DURATION': "Interval of time (in seconds), after which the bot deletes it's message and command message which is expected to be viewed instantly.\n\n <b>NOTE:</b> Set to -1 to disable auto message deletion.",
'BASE_URL': 'Valid BASE URL where the bot is deployed to use torrent web files selection. Format of URL should be http://myip, where myip is the IP/Domain(public) of your bot or if you have chosen port other than 80 so write it in this format http://myip:port (http and not https). Str',
'BASE_URL_PORT': 'Which is the BASE_URL Port. Default is 80. Int',
'BLACKLIST_USERS': 'Restrict User from Using the Bot. It will Display a BlackListed Msg. USER_ID separated by space. Str',
'BOT_MAX_TASKS': 'Maximum number of Task Bot will Run parallel. (Queue Tasks Included). Int',
'STORAGE_THRESHOLD': 'To leave specific storage free and any download will lead to leave free storage less than this value will be cancelled the default unit is GB. Int',
'LEECH_LIMIT': 'To limit the Torrent/Direct/ytdlp leech size. the default unit is GB. Int',
'CLONE_LIMIT': 'To limit the size of Google Drive folder/file which you can clone. the default unit is GB. Int',
Expand All @@ -430,11 +448,17 @@
'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',
'IMDB_TEMPLATE': 'Set Bot Default IMDB Template. HTML Tags, Emojis supported. str',
'AUTHOR_NAME': 'Author name for Telegraph pages',
'AUTHOR_URL': 'Author URL for Telegraph page',
'AUTHOR_NAME': 'Author name for Telegraph pages, Shown in Telegraph Page as by AUTHOR_NAME',
'AUTHOR_URL': 'Author URL for Telegraph page, Put Channel URL to Show Join Channel. Str',
'COVER_IMAGE': 'Cover Image for Telegraph Page. Put Telegraph Photo Link',
'TITLE_NAME': 'Title name for Telegraph pages (while using /list command)',
'GD_INFO': 'Description of file uploaded to gdrive using bot',
'BOT_THEME': 'Change the theme of bot. For now theme availabe is minimal. You can make your own theme checkout this link https://t.ly/9rVXq',
'DELETE_LINKS': 'Delete TgLink/Magnet/File on Start of Task to Auto Clean Group. Default is False',
'EXCEP_CHATS': 'Exception Chats which will not use Logging, chat_id separated by space. Str',
'SAFE_MODE': 'Hide Task Name, Source Link and Indexing of Leech Link for Safety Precautions. Default is False',
'SOURCE_LINK': 'Add a Extra Button of Source Link whether it is Magnet Link or File Link or DL Link. Default is False',
'SHOW_EXTRA_CMDS': 'Add Extra Commands beside Arg Format for -z or -e. \n\n<b>COMMANDS: </b> /unzipxxx or /zipxxx or /uzx or /zx',
'BOT_THEME': 'Theme of the Bot to Switch. For now Deafault Theme Availabe is minimal. You can make your own Theme and Add in BSet. \n\n<b>Sample Format</b>: https://t.ly/9rVXq',
'USER_MAX_TASKS': 'Limit the Maximum task for users of group at a time. use the Int',
'DAILY_TASK_LIMIT': 'Maximum task a user can do in one day. use the Int',
'DISABLE_DRIVE_LINK': 'Disable drive link button. Default is False. Bool',
Expand All @@ -445,11 +469,12 @@
'FSUB_IDS': 'Fill chat_id(-100xxxxxx) of groups/channel you want to force subscribe. Separate them by space. Int\n\nNote: Bot should be added in the filled chat_id as admin',
'BOT_PM': 'File/links send to the BOT PM also. Default is False',
'BOT_TOKEN': 'The Telegram Bot Token that you got from @BotFather',
'CMD_SUFFIX': 'commands index number. This number will added at the end all commands.',
'CMD_SUFFIX': 'Telegram Bot Command Index number or Custom Text. This will added at the end all commands except Global Commands. Str',
'DATABASE_URL': "Your Mongo Database URL (Connection string). Follow this Generate Database to generate database. Data will be saved in Database: auth and sudo users, users settings including thumbnails for each user, rss data and incomplete tasks.\n\n <b>NOTE:</b> You can always edit all settings that saved in database from the official site -> (Browse collections)",
'DEFAULT_UPLOAD': 'Whether rc to upload to RCLONE_PATH or gd to upload to GDRIVE_ID or ddl to upload to DDLserver. Default is gd.',
'DOWNLOAD_DIR': 'The path to the local folder where the downloads should be downloaded to. ',
'MDL_TEMPLATE': 'Set Bot Custom Default MyDramaList Template. HTML Tags, Emojis Supported',
'CLEAN_LOG_MSG': 'Clean Leech Log & Bot PM Task Start Message. Default is False',
'LEECH_LOG_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.',
Expand All @@ -459,6 +484,7 @@
'INDEX_URL': 'Refer to https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index.',
'IS_TEAM_DRIVE': 'Set True if uploading to TeamDrive using google-api-python-client. Default is False',
'SHOW_MEDIAINFO': 'Add Button to Show MediaInfo in Leeched file. Bool',
'SCREENSHOTS_MODE': 'Enable or Diable generating Screenshots via -ss arg. Default is False. Bool',
'CAP_FONT': 'Add Custom Caption Font to Leeched Files, Available Values : b, i, u, s, code, spoiler. Reset Var to use Regular ( No Format )',
'LEECH_FILENAME_PREFIX': 'Add custom word prefix to leeched file name. Str',
'LEECH_FILENAME_SUFFIX': 'Add custom word suffix to leeched file name. Str',
Expand Down Expand Up @@ -500,6 +526,8 @@
'UPGRADE_PACKAGES': 'Install New Requirements File without thinking of Crash. Bool',
'SAVE_MSG': 'Add button of save message. Bool',
'SET_COMMANDS': 'Set bot command automatically. Bool',
'USER_TD_MODE': 'Enable User GDrive TD to Use. Default is False',
'USER_TD_SA': 'Add Global SA mail for User to give Permissions to Bot for UserTD Upload. Like [email protected]. Str',
'UPTOBOX_TOKEN': 'Uptobox token to mirror uptobox links. Get it from <a href="https://uptobox.com/my_account">Uptobox Premium Account</a>.',
'USER_SESSION_STRING': "To download/upload from your telegram account and to send rss. To generate session string use this command <code>python3 generate_string_session.py</code> after mounting repo folder for sure.\n\n<b>NOTE:</b> You can't use bot with private message. Use it with superGroup.",
'USE_SERVICE_ACCOUNTS': 'Whether to use Service Accounts or not, with google-api-python-client. For this to work see Using Service Accounts section below. Default is False',
Expand Down
13 changes: 9 additions & 4 deletions bot/helper/ext_utils/leech_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ async def get_media_info(path, metadata=False):
artist = tags.get('artist') or tags.get('ARTIST') or tags.get("Artist")
title = tags.get('title') or tags.get('TITLE') or tags.get("Title")
if metadata:
lang, qual = "", ""
lang, qual, stitles = "", "", ""
if (streams := ffresult.get('streams')) and streams[0].get('codec_type') == 'video':
qual = f"{streams[0].get('height')}p"
qual = streams[0].get('height')
qual = f"{480 if qual <= 480 else 540 if qual <= 540 else 720 if qual <= 720 else 1080 if qual <= 1080 else 2160 if qual <= 2160 else 4320 if qual <= 4320 else 8640}p"
for stream in streams:
if stream.get('codec_type') == 'audio' and (lc := stream.get('tags', {}).get('language')):
lang += Language.get(lc).display_name() + ", "
return duration, qual, lang[:-2]
if stream.get('codec_type') == 'subtitle' and (st := stream.get('tags', {}).get('language')):
stitles += Language.get(st).display_name() + ", "
return duration, qual, lang[:-2], stitles[:-2]
return duration, artist, title


Expand Down Expand Up @@ -140,6 +143,7 @@ async def take_ss(video_file, duration=None, total=1, gen_ss=False):
if await task.wait() != 0 or not await aiopath.exists(ospath.join(des_dir, f"wz_thumb_{eq_thumb}.jpg")):
err = (await task.stderr.read()).decode().strip()
LOGGER.error(f'Error while extracting thumbnail no. {eq_thumb} from video. Name: {video_file} stderr: {err}')
await aiormtree(des_dir)
return None
return (des_dir, tstamps) if gen_ss else ospath.join(des_dir, "wz_thumb_1.jpg")

Expand Down Expand Up @@ -284,13 +288,14 @@ async def format_filename(file_, user_id, dirpath=None, isMirror=False):
lcaption = lcaption.replace('\|', '%%').replace('\s', ' ')
slit = lcaption.split("|")
up_path = ospath.join(dirpath, prefile_)
dur, qual, lang = await get_media_info(up_path, True)
dur, qual, lang, subs = await get_media_info(up_path, True)
cap_mono = slit[0].format(
filename = nfile_,
size = get_readable_file_size(await aiopath.getsize(up_path)),
duration = get_readable_time(dur),
quality = qual,
languages = lang,
subtitles = subs,
md5_hash = get_md5_hash(up_path)
)
if len(slit) > 1:
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def task_utils(message):
if _msg:
msg.append(_msg)
user_dict = user_data.get(user_id, {})
if config_dict['BOT_PM'] or user_dict.get('bot_pm'):
if config_dict['BOT_PM'] or user_dict.get('bot_pm') or config_dict['SAFE_MODE']:
_msg, button = await check_botpm(message, button)
if _msg:
msg.append(_msg)
Expand Down
Loading

0 comments on commit 97bd342

Please sign in to comment.