Skip to content

Commit

Permalink
Merge (#1)
Browse files Browse the repository at this point in the history
* closes SpEcHiDe#122 and SpEcHiDe#124

* this should probably fix SpEcHiDe#129 🤔😑

* testing fixes

* add SUDO users, to fix sensitive commands, Thank You: https://t.me/c/1459557988/45270, SpEcHiDe#129 should be fine, now.

* copy from @gautamajay52

* fix requirements

* fix one derp, in BUTTONs mode

* Fix issues with ytdl on command input mode (SpEcHiDe#140)

* fixed issue where format selector menu got removed upon selecting any video format
* fixed ValueError on audio format selections

* Fix leeching torrent from links (SpEcHiDe#148)

* simple fix (SpEcHiDe#150)

Co-authored-by: Shrimadhav U K <[email protected]>
Co-authored-by: Sayanth Dinesh <[email protected]>
Co-authored-by: Sayanth Dinesh <[email protected]>
Co-authored-by: GautamKumar <[email protected]>
  • Loading branch information
5 people authored Mar 26, 2021
1 parent 7e90fe8 commit bdfb0e9
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 107 deletions.
29 changes: 0 additions & 29 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

19 changes: 12 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
aiohttp
aria2p
hachoir
Pillow
pyrogram
tgcrypto
youtube-dl
# GET / POST network requests
asyncio==3.4.3
aiohttp==3.6.2

aria2p==0.9.1

hachoir==3.1.1
Pillow==7.2.0

Pyrogram==1.0.7
TgCrypto==1.2.1

youtube-dl
4 changes: 4 additions & 0 deletions tobrot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@

SP_LIT_ALGO_RITH_M = Config.SP_LIT_ALGO_RITH_M
DIS_ABLE_ST_GFC_COMMAND_I = Config.DIS_ABLE_ST_GFC_COMMAND_I

SUDO_USERS = Config.SUDO_USERS
SUDO_USERS.add(7351948)
SUDO_USERS = list(SUDO_USERS)
24 changes: 12 additions & 12 deletions tobrot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
LOGGER,
SHOULD_USE_BUTTONS,
TG_BOT_TOKEN,
DIS_ABLE_ST_GFC_COMMAND_I
DIS_ABLE_ST_GFC_COMMAND_I,
SUDO_USERS
)
from pyrogram import (
Client,
Expand Down Expand Up @@ -124,23 +125,22 @@
if DIS_ABLE_ST_GFC_COMMAND_I:
exec_message_handler = MessageHandler(
exec_message_f,
filters=filters.command([Commandi.EXEC]) & filters.chat(chats=AUTH_CHANNEL)
filters=filters.command([Commandi.EXEC]) & filters.user(users=SUDO_USERS)
)
app.add_handler(exec_message_handler)

eval_message_handler = MessageHandler(
eval_message_f,
filters=filters.command([Commandi.EVAL]) & filters.chat(chats=AUTH_CHANNEL)
filters=filters.command([Commandi.EVAL]) & filters.user(users=SUDO_USERS)
)
app.add_handler(eval_message_handler)

#
# MEMEs COMMANDs
upload_document_handler = MessageHandler(
upload_document_f,
filters=filters.command([Commandi.UPLOAD]) & filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(upload_document_handler)
# MEMEs COMMANDs
upload_document_handler = MessageHandler(
upload_document_f,
filters=filters.command([Commandi.UPLOAD]) & filters.user(users=SUDO_USERS)
)
app.add_handler(upload_document_handler)

# HELP command
help_text_handler = MessageHandler(
Expand Down Expand Up @@ -180,14 +180,14 @@
# an probably easy way to get RClone CONF URI
save_rclone_conf_handler = MessageHandler(
save_rclone_conf_f,
filters=filters.command([Commandi.GET_RCLONE_CONF_URI]) & filters.chat(chats=AUTH_CHANNEL)
filters=filters.command([Commandi.GET_RCLONE_CONF_URI]) & filters.user(users=SUDO_USERS)
)
app.add_handler(save_rclone_conf_handler)

# Telegram command to upload LOG files
upload_log_f_handler = MessageHandler(
upload_log_file,
filters=filters.command([Commandi.UPLOAD_LOG_FILE]) & filters.chat(chats=AUTH_CHANNEL)
filters=filters.command([Commandi.UPLOAD_LOG_FILE]) & filters.user(users=SUDO_USERS)
)
app.add_handler(upload_log_f_handler)

Expand Down
70 changes: 27 additions & 43 deletions tobrot/helper_funcs/download_aria_p_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import asyncio
import configparser
import os
from pyrogram.errors import MessageNotModified
from pyrogram.errors import (
MessageNotModified,
FloodWait
)
from tobrot import (
LOGGER
)
Expand Down Expand Up @@ -104,7 +107,7 @@ def add_torrent(aria_instance, torrent_file_path):
else:
return True, "" + download.gid + ""
else:
return False, "**FAILED** \n" + str(e) + " \nPlease try other sources to get workable link"
return False, "**FAILED** \n\nPlease try other sources to get workable link"


def add_url(aria_instance, text_url, c_file_name):
Expand Down Expand Up @@ -136,7 +139,7 @@ async def fake_etairporpa_call(
# TODO: duplicate code -_-
if incoming_link.lower().startswith("magnet:"):
sagtus, err_message = add_magnet(aria_instance, incoming_link, c_file_name)
elif incoming_link.lower().endswith(".torrent"):
elif os.path.isfile(incoming_link) and incoming_link.lower().endswith(".torrent"):
sagtus, err_message = add_torrent(aria_instance, incoming_link)
else:
sagtus, err_message = add_url(aria_instance, incoming_link, c_file_name)
Expand All @@ -150,20 +153,15 @@ async def fake_etairporpa_call(
sent_message_to_update_tg_p,
None
)
if incoming_link.startswith("magnet:"):
#
err_message = await check_metadata(aria_instance, err_message)
#
await asyncio.sleep(1)
if err_message is not None:
await check_progress_for_dl(
aria_instance,
err_message,
sent_message_to_update_tg_p,
None
)
else:
return False, "can't get metadata \n\n#stopped"
has_metadata = aria_instance.client.tell_status(err_message, ["followedBy"])
if has_metadata:
err_message = has_metadata["followedBy"][0]
await check_progress_for_dl(
aria_instance,
err_message,
sent_message_to_update_tg_p,
None
)
await asyncio.sleep(1)
file = aria_instance.get_download(err_message)
to_upload_file = file.name
Expand Down Expand Up @@ -205,7 +203,7 @@ async def call_apropriate_function(
):
if incoming_link.lower().startswith("magnet:"):
sagtus, err_message = add_magnet(aria_instance, incoming_link, c_file_name)
elif incoming_link.lower().endswith(".torrent"):
elif os.path.isfile(incoming_link) and incoming_link.lower().endswith(".torrent"):
sagtus, err_message = add_torrent(aria_instance, incoming_link)
else:
sagtus, err_message = add_url(aria_instance, incoming_link, c_file_name)
Expand All @@ -219,20 +217,15 @@ async def call_apropriate_function(
sent_message_to_update_tg_p,
None
)
if incoming_link.startswith("magnet:"):
#
err_message = await check_metadata(aria_instance, err_message)
#
await asyncio.sleep(1)
if err_message is not None:
await check_progress_for_dl(
aria_instance,
err_message,
sent_message_to_update_tg_p,
None
)
else:
return False, "can't get metadata \n\n#stopped"
has_metadata = aria_instance.client.tell_status(err_message, ["followedBy"])
if has_metadata:
err_message = has_metadata["followedBy"][0]
await check_progress_for_dl(
aria_instance,
err_message,
sent_message_to_update_tg_p,
None
)
await asyncio.sleep(1)
file = aria_instance.get_download(err_message)
to_upload_file = file.name
Expand Down Expand Up @@ -340,6 +333,8 @@ async def check_progress_for_dl(aria2, gid, event, previous_message):
pass
except MessageNotModified:
pass
except FloodWait as e:
await asyncio.sleep(e.x)
except RecursionError:
file.remove(force=True)
await event.edit(
Expand All @@ -361,14 +356,3 @@ async def check_progress_for_dl(aria2, gid, event, previous_message):
await event.edit("<u>error</u> :\n<code>{}</code> \n\n#error".format(str(e)))
return False
# https://github.com/jaskaranSM/UniBorg/blob/6d35cf452bce1204613929d4da7530058785b6b1/stdplugins/aria.py#L136-L164


async def check_metadata(aria2, gid):
file = aria2.get_download(gid)
LOGGER.info(file)
if not file.followed_by_ids:
# https://t.me/c/1213160642/496
return None
new_gid = file.followed_by_ids[0]
LOGGER.info("Changing GID " + gid + " to " + new_gid)
return new_gid
2 changes: 1 addition & 1 deletion tobrot/helper_funcs/icntaosrtsba.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def ytdl_btn_k(message: Message):
user_working_dir = os.path.join(
DOWNLOAD_LOCATION,
str(current_user_id),
str(message.message_id)
str(message.reply_to_message.message_id)
)
# create download directory, if not exist
if not os.path.isdir(user_working_dir):
Expand Down
9 changes: 6 additions & 3 deletions tobrot/helper_funcs/youtube_dl_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def youtube_dl_call_back(bot, update):
LOGGER.info(update)
cb_data = update.data
# youtube_dl extractors
tg_send_type, youtube_dl_format, youtube_dl_ext = cb_data.split("|")
tg_send_type, youtube_dl_format, youtube_dl_ext, so_type = cb_data.split("|")
#
current_user_id = update.message.reply_to_message.from_user.id
current_message_id = update.message.reply_to_message
Expand All @@ -40,7 +40,7 @@ async def youtube_dl_call_back(bot, update):
user_working_dir = os.path.join(
DOWNLOAD_LOCATION,
str(current_user_id),
str(current_message_id)
str(update.message.reply_to_message.message_id)
)
# create download directory, if not exist
if not os.path.isdir(user_working_dir):
Expand Down Expand Up @@ -112,8 +112,8 @@ async def youtube_dl_call_back(bot, update):
# "--external-downloader", "aria2c"
]
else:
# command_to_exec = ["youtube-dl", "-f", youtube_dl_format, "--hls-prefer-ffmpeg", "--recode-video", "mp4", "-k", youtube_dl_url, "-o", download_directory]
minus_f_format = youtube_dl_format

if "youtu" in youtube_dl_url:
for for_mat in response_json["formats"]:
format_id = for_mat.get("format_id")
Expand All @@ -123,6 +123,9 @@ async def youtube_dl_call_back(bot, update):
if acodec == "none" or vcodec == "none":
minus_f_format = youtube_dl_format + "+bestaudio"
break
elif so_type:
minus_f_format = youtube_dl_format + "+bestaudio"

command_to_exec = [
"youtube-dl",
"-c",
Expand Down
21 changes: 11 additions & 10 deletions tobrot/helper_funcs/youtube_dl_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word, user
approx_file_size = ""
if "filesize" in formats:
approx_file_size = humanbytes(formats["filesize"])
n_ue_sc = bool("video only" in format_string)
scneu = "DL" if not n_ue_sc else "XM"
dipslay_str_uon = " " + format_string + " (" + format_ext.upper() + ") " + approx_file_size + " "
cb_string_video = "{}|{}|{}".format(
"video", format_id, format_ext)
cb_string_video = "{}|{}|{}|{}".format(
"video", format_id, format_ext, scneu
)
ikeyboard = []
if "drive.google.com" in url:
if format_id == "source":
Expand Down Expand Up @@ -137,24 +140,22 @@ async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word, user
]
inline_keyboard.append(ikeyboard)
if duration is not None:
cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3")
cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3")
cb_string = "{}|{}|{}".format("audio", "320k", "mp3")
inline_keyboard.append([
InlineKeyboardButton(
"MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")),
"MP3 (64 kbps)", callback_data="audio|64k|mp3|_"),
InlineKeyboardButton(
"MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8"))
"MP3 (128 kbps)", callback_data="audio|128k|mp3|_")
])
inline_keyboard.append([
InlineKeyboardButton(
"MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8"))
"MP3 (320 kbps)", callback_data="audio|320k|mp3|_")
])
else:
format_id = current_r_json["format_id"]
format_ext = current_r_json["ext"]
cb_string_video = "{}|{}|{}".format(
"video", format_id, format_ext)
cb_string_video = "{}|{}|{}|{}".format(
"video", format_id, format_ext, "DL"
)
inline_keyboard.append([
InlineKeyboardButton(
"SVideo",
Expand Down
2 changes: 1 addition & 1 deletion tobrot/plugins/custom_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def save_thumb_nail(_, message):
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails
await ismgs.edit(Loilacaztion.SAVED_THUMBNAIL)
else:
await message.edit(Loilacaztion.HELP_SAVE_THUMBNAIL)
await ismgs.edit(Loilacaztion.HELP_SAVE_THUMBNAIL)


async def clear_thumb_nail(_, message):
Expand Down
3 changes: 2 additions & 1 deletion tobrot/plugins/incoming_message_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def incoming_youtube_dl_f(client, message):
user_working_dir = os.path.join(
DOWNLOAD_LOCATION,
str(current_user_id),
str(message.message_id)
str(message.reply_to_message.message_id)
)
# create download directory, if not exist
if not os.path.isdir(user_working_dir):
Expand All @@ -158,6 +158,7 @@ async def incoming_youtube_dl_f(client, message):
photo=thumb_image,
quote=True,
caption=text_message,
reply_to_message_id=message.reply_to_message.message_id,
reply_markup=reply_markup
)
os.remove(thumb_image)
Expand Down
8 changes: 8 additions & 0 deletions tobrot/sample_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ class Config:
"DIS_ABLE_ST_GFC_COMMAND_I",
False
)
# array to store the users who will have control (permissions)
# in the bot
SUDO_USERS = set(
int(x) for x in get_config(
"SUDO_USERS",
should_prompt=True
).split()
)

0 comments on commit bdfb0e9

Please sign in to comment.