Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Aug 29, 2024
1 parent 5edff02 commit 11318b4
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 58 deletions.
38 changes: 19 additions & 19 deletions bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ async def split_file(
return True


async def process_file(file_, user_id, dirpath=None, isMirror=False):
async def process_file(file_, user_id, dirpath=None, is_mirror=False):
user_dict = user_data.get(user_id, {})
prefix = user_dict.get("prefix", "")
remname = user_dict.get("remname", "")
Expand All @@ -455,16 +455,16 @@ async def process_file(file_, user_id, dirpath=None, isMirror=False):
remname = f"|{remname}"
remname = remname.replace(r"\s", " ")
slit = remname.split("|")
__newFileName = ospath.splitext(file_)[0]
__new_file_name = ospath.splitext(file_)[0]
for rep in range(1, len(slit)):
args = slit[rep].split(":")
if len(args) == 3:
__newFileName = re_sub(args[0], args[1], __newFileName, int(args[2]))
__new_file_name = re_sub(args[0], args[1], __new_file_name, int(args[2]))
elif len(args) == 2:
__newFileName = re_sub(args[0], args[1], __newFileName)
__new_file_name = re_sub(args[0], args[1], __new_file_name)
elif len(args) == 1:
__newFileName = re_sub(args[0], "", __newFileName)
file_ = __newFileName + ospath.splitext(file_)[1]
__new_file_name = re_sub(args[0], "", __new_file_name)
file_ = __new_file_name + ospath.splitext(file_)[1]
LOGGER.info(f"New Filename : {file_}")

nfile_ = file_
Expand All @@ -474,18 +474,18 @@ async def process_file(file_, user_id, dirpath=None, isMirror=False):
if not file_.startswith(prefix):
file_ = f"{prefix}{file_}"

if suffix and not isMirror:
if suffix and not is_mirror:
suffix = suffix.replace(r"\s", " ")
sufLen = len(suffix)
fileDict = file_.split(".")
_extIn = 1 + len(fileDict[-1])
_extOutName = ".".join(fileDict[:-1]).replace(".", " ").replace("-", " ")
_newExtFileName = f"{_extOutName}{suffix}.{fileDict[-1]}"
if len(_extOutName) > (64 - (sufLen + _extIn)):
_newExtFileName = (
_extOutName[: 64 - (sufLen + _extIn)] + f"{suffix}.{fileDict[-1]}"
suf_len = len(suffix)
file_dict = file_.split(".")
_ext_in = 1 + len(file_dict[-1])
_ext_out_name = ".".join(file_dict[:-1]).replace(".", " ").replace("-", " ")
_new_ext_file_name = f"{_ext_out_name}{suffix}.{file_dict[-1]}"
if len(_ext_out_name) > (64 - (suf_len + _ext_in)):
_new_ext_file_name = (
_ext_out_name[: 64 - (suf_len + _ext_in)] + f"{suffix}.{file_dict[-1]}"
)
file_ = _newExtFileName
file_ = _new_ext_file_name
elif suffix:
suffix = suffix.replace(r"\s", " ")
file_ = (
Expand All @@ -495,9 +495,9 @@ async def process_file(file_, user_id, dirpath=None, isMirror=False):
)

cap_mono = nfile_
if lcaption and dirpath and not isMirror:
if lcaption and dirpath and not is_mirror:

def lowerVars(match):
def lower_vars(match):
return f"{{{match.group(1).lower()}}}"

lcaption = (
Expand All @@ -507,7 +507,7 @@ def lowerVars(match):
.replace(r"\s", " ")
)
slit = lcaption.split("|")
slit[0] = re_sub(r"\{([^}]+)\}", lowerVars, slit[0])
slit[0] = re_sub(r"\{([^}]+)\}", lower_vars, slit[0])
up_path = ospath.join(dirpath, prefile_)
dur, qual, lang, subs = await get_media_info(up_path, True)
cap_mono = slit[0].format(
Expand Down
26 changes: 13 additions & 13 deletions bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ async def start_from_queued():
async def limit_checker(
size,
listener,
isTorrent=False,
isMega=False,
isDriveLink=False,
isYtdlp=False,
isPlayList=None,
is_torrent=False,
is_mega=False,
is_drive_link=False,
is_ytdlp=False,
is_playlist=None,
):
LOGGER.info("Checking limit")
user_id = listener.message.from_user.id
Expand All @@ -161,30 +161,30 @@ async def limit_checker(
limit = CLONE_LIMIT * 1024**3
if size > limit:
limit_exceeded = f"Clone limit is {get_readable_file_size(limit)}."
elif isMega:
elif is_mega:
if MEGA_LIMIT := config_dict["MEGA_LIMIT"]:
limit = MEGA_LIMIT * 1024**3
if size > limit:
limit_exceeded = f"Mega limit is {get_readable_file_size(limit)}"
elif isDriveLink:
elif is_drive_link:
if GDRIVE_LIMIT := config_dict["GDRIVE_LIMIT"]:
limit = GDRIVE_LIMIT * 1024**3
if size > limit:
limit_exceeded = (
f"Google drive limit is {get_readable_file_size(limit)}"
)
elif isYtdlp:
elif is_ytdlp:
if YTDLP_LIMIT := config_dict["YTDLP_LIMIT"]:
limit = YTDLP_LIMIT * 1024**3
if size > limit:
limit_exceeded = f"Ytdlp limit is {get_readable_file_size(limit)}"
if (
isPlayList != 0
is_playlist != 0
and (PLAYLIST_LIMIT := config_dict["PLAYLIST_LIMIT"])
and isPlayList > PLAYLIST_LIMIT
and is_playlist > PLAYLIST_LIMIT
):
limit_exceeded = f"Playlist limit is {PLAYLIST_LIMIT}"
elif isTorrent:
elif is_torrent:
if TORRENT_LIMIT := config_dict["TORRENT_LIMIT"]:
limit = TORRENT_LIMIT * 1024**3
if size > limit:
Expand All @@ -207,8 +207,8 @@ async def limit_checker(
if limit_exceeded:
if size:
return f"{limit_exceeded}.\nYour file or folder size is {get_readable_file_size(size)}."
if isPlayList != 0:
return f"{limit_exceeded}.\nYour playlist has {isPlayList} files."
if is_playlist != 0:
return f"{limit_exceeded}.\nYour playlist has {is_playlist} files."
return None
return None

Expand Down
12 changes: 6 additions & 6 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@new_thread
async def __onDownloadStarted(api, gid):
async def __on_download_started(api, gid):
download = await sync_to_async(api.get_download, gid)
if download.options.follow_torrent == "false":
return
Expand Down Expand Up @@ -123,7 +123,7 @@ async def __onDownloadStarted(api, gid):


@new_thread
async def __onDownloadComplete(api, gid):
async def __on_download_complete(api, gid):
try:
download = await sync_to_async(api.get_download, gid)
except Exception:
Expand All @@ -138,9 +138,9 @@ async def __onDownloadComplete(api, gid):
if config_dict["BASE_URL"] and listener.select:
if not dl.queued:
await sync_to_async(api.client.force_pause, new_gid)
SBUTTONS = bt_selection_buttons(new_gid)
s_buttons = bt_selection_buttons(new_gid)
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
await send_message(listener.message, msg, SBUTTONS)
await send_message(listener.message, msg, s_buttons)
elif download.is_torrent:
if (
(dl := await get_task_by_gid(gid))
Expand Down Expand Up @@ -248,10 +248,10 @@ async def __onDownloadError(api, gid):
def start_aria2_listener():
aria2.listen_to_notifications(
threaded=False,
on_download_start=__onDownloadStarted,
on_download_start=__on_download_started,
on_download_error=__onDownloadError,
on_download_stop=__onDownloadStopped,
on_download_complete=__onDownloadComplete,
on_download_complete=__on_download_complete,
on_bt_download_complete=__onBtDownloadComplete,
timeout=60,
)
4 changes: 2 additions & 2 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def __size_checked(tor):


@new_task
async def __onDownloadComplete(tor):
async def __on_download_complete(tor):
ext_hash = tor.hash
tag = tor.tags
await sleep(2)
Expand Down Expand Up @@ -192,7 +192,7 @@ async def __qb_listener():
not in ["checkingUP", "checkingDL", "checkingResumeData"]
):
QbTorrents[tag]["uploaded"] = True
__onDownloadComplete(tor_info)
__on_download_complete(tor_info)
elif (
state in ["pausedUP", "pausedDL"]
and QbTorrents[tag]["seeding"]
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/listeners/tasks_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
upPath=None,
isClone=False,
join=False,
isYtdlp=False,
is_ytdlp=False,
drive_id=None,
index_link=None,
attachment=None,
Expand All @@ -102,7 +102,7 @@ def __init__(
self.isQbit = isQbit
self.isLeech = isLeech
self.isClone = isClone
self.isYtdlp = isYtdlp
self.is_ytdlp = is_ytdlp
self.tag = tag
self.seed = seed
self.newDir = ""
Expand Down Expand Up @@ -465,7 +465,7 @@ async def onUploadComplete(
self, link, size, files, folders, mime_type, name, rclonePath=""
):
user_id = self.message.from_user.id
name, _ = await process_file(name, user_id, isMirror=not self.isLeech)
name, _ = await process_file(name, user_id, is_mirror=not self.isLeech)
msg = f"{escape(name)}\n\n"
msg += f"<blockquote><b>• Size: </b>{get_readable_file_size(size)}\n"
msg += f"<b>• Elapsed: </b>{get_readable_time(time() - self.message.date.timestamp())}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ async def add_aria2c_download(
elif listener.select and download.is_torrent and not download.is_metadata:
if not added_to_queue:
await sync_to_async(aria2.client.force_pause, gid)
SBUTTONS = bt_selection_buttons(gid)
s_buttons = bt_selection_buttons(gid)
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
await send_message(listener.message, msg, SBUTTONS)
await send_message(listener.message, msg, s_buttons)

if added_to_queue:
await event.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def add_gd_download(link, path, listener, newname):
if msg:
await send_message(listener.message, msg, button)
return
if limit_exceeded := await limit_checker(size, listener, isDriveLink=True):
if limit_exceeded := await limit_checker(size, listener, is_drive_link=True):
await listener.onDownloadError(limit_exceeded)
return
added_to_queue, event = await is_queued(listener.uid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def add_mega_download(mega_link, path, listener, name):

gid = token_hex(4)
size = api.getSize(node)
if limit_exceeded := await limit_checker(size, listener, isMega=True):
if limit_exceeded := await limit_checker(size, listener, is_mega=True):
await listener.onDownloadError(limit_exceeded)
return

Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/download_utils/qbit_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ async def add_qb_torrent(link, path, listener, ratio, seed_time):
await sync_to_async(
xnox_client.torrents_pause, torrent_hashes=ext_hash
)
SBUTTONS = bt_selection_buttons(ext_hash)
s_buttons = bt_selection_buttons(ext_hash)
msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
await send_message(listener.message, msg, SBUTTONS)
await send_message(listener.message, msg, s_buttons)
else:
await sendStatusMessage(listener.message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def __onDownloadError(self, error):
GLOBAL_GID.remove(self.__id)
await self.__listener.onDownloadError(error)

async def __onDownloadComplete(self):
async def __on_download_complete(self):
await self.__listener.onDownloadComplete()
async with global_lock:
GLOBAL_GID.remove(self.__id)
Expand All @@ -100,7 +100,7 @@ async def __download(self, message, path):
await self.__onDownloadError(str(e))
return
if download is not None:
await self.__onDownloadComplete()
await self.__on_download_complete()
elif not self.__is_cancelled:
await self.__onDownloadError("Internal error occurred")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ async def add_download(self, link, path, name, qual, playlist, options):
if limit_exceeded := await limit_checker(
self.__size,
self.__listener,
isYtdlp=True,
isPlayList=self.playlist_count,
is_ytdlp=True,
is_playlist=self.playlist_count,
):
await self.__listener.onDownloadError(limit_exceeded)
return
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def __upload_dir(self, input_directory, dest_id):
)
def __create_directory(self, directory_name, dest_id):
directory_name, _ = async_to_sync(
process_file, directory_name, self.__user_id, isMirror=True
process_file, directory_name, self.__user_id, is_mirror=True
)
file_metadata = {
"name": directory_name,
Expand Down Expand Up @@ -531,7 +531,7 @@ def __cloneFolder(self, name, local_path, folder_id, dest_id):
)
def __copyFile(self, file_id, dest_id, file_name):
file_name, _ = async_to_sync(
process_file, file_name, self.__user_id, isMirror=True
process_file, file_name, self.__user_id, is_mirror=True
)
body = {"name": file_name, "parents": [dest_id]}
try:
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ async def __run_multi():
upPath=up,
drive_id=drive_id,
index_link=index_link,
isYtdlp=True,
is_ytdlp=True,
files_utils={"screenshots": sshots, "thumb": thumb},
)

Expand Down
5 changes: 3 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ target-version = "py310"
length-sort = true

[lint.pylint]
max-branches = 30
max-statements = 75
max-branches = 50
max-statements = 100
max-returns = 15

[lint]
select = [
Expand Down

0 comments on commit 11318b4

Please sign in to comment.