Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Dec 27, 2024
1 parent 2d90840 commit acf7f2e
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 92 deletions.
208 changes: 160 additions & 48 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bot/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ async def save_settings():
async def update_variables():
if (
Config.LEECH_SPLIT_SIZE > TgClient.MAX_SPLIT_SIZE
or Config.LEECH_SPLIT_SIZE == 2097152000 or not Config.LEECH_SPLIT_SIZE
or Config.LEECH_SPLIT_SIZE == 2097152000
or not Config.LEECH_SPLIT_SIZE
):
Config.LEECH_SPLIT_SIZE = TgClient.MAX_SPLIT_SIZE

Expand Down
6 changes: 6 additions & 0 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,9 @@ async def proceed_ffmpeg(self, dl_path, gid):
res = await run_ffmpeg_cmd(self, cmd, file_path)
if res and delete_files:
await remove(file_path)
if "ffmpeg." in res:
newres = res.replace("ffmpeg.", "")
await move(res, newres)
else:
for dirpath, _, files in await sync_to_async(
walk, dl_path, topdown=False
Expand Down Expand Up @@ -1214,6 +1217,9 @@ async def proceed_ffmpeg(self, dl_path, gid):
res = await run_ffmpeg_cmd(self, cmd, f_path)
if res and delete_files:
await remove(f_path)
if "ffmpeg." in res:
newres = res.replace("ffmpeg.", "")
await move(res, newres)
if checked:
cpu_eater_lock.release()
return dl_path
60 changes: 38 additions & 22 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ async def get_telegraph_list(telegraph_content):


def arg_parser(items, arg_base):

if not items:
return

arg_start = -1
i = 0
total = len(items)

bool_arg_set = {
"-b",
"-e",
Expand All @@ -106,43 +112,53 @@ def arg_parser(items, arg_base):
"-doc",
"-med",
}
t = len(items)
i = 0
arg_start = -1

while i + 1 <= t:
def process_argument_with_values(start_index):
values = []
for j in range(start_index + 1, total):
if items[j] in arg_base:
break
values.append(items[j])
return values

def process_nested_list(start_index):
values = []
end_index = start_index + 1
while end_index < total and items[end_index] != "]":
values.append(items[end_index])
end_index += 1
return values, end_index - start_index

while i < total:
part = items[i]

if part in arg_base:
if arg_start == -1:
arg_start = i

if (
i + 1 == t
i + 1 == total
and part in bool_arg_set
or part
in ["-s", "-j", "-f", "-fd", "-fu", "-sync", "-ml", "-doc", "-med"]
):
arg_base[part] = True
elif part == "-ff" and i + 1 < total and items[i + 1].startswith("["):
nested_values, skip_count = process_nested_list(i + 1)
arg_base[part] = nested_values
i += skip_count
else:
sub_list = []
for j in range(i + 1, t):
item = items[j]
if item in arg_base:
if part in bool_arg_set and not sub_list:
arg_base[part] = True
break
sub_list.append(item)
i += 1
sub_list = process_argument_with_values(i)
if sub_list:
arg_base[part] = " ".join(sub_list)
i += len(sub_list)

i += 1
if "link" in arg_base and items[0] not in arg_base:
link = []
if arg_start == -1:
link.extend(iter(items))
else:
link.extend(items[r] for r in range(arg_start))
if link:
arg_base["link"] = " ".join(link)

if "link" in arg_base:
link_items = items[:arg_start] if arg_start != -1 else items
if link_items:
arg_base["link"] = " ".join(link_items)


def get_size_bytes(size):
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class MirrorStatus:
"AR": MirrorStatus.STATUS_ARCHIVE,
"EX": MirrorStatus.STATUS_EXTRACT,
"SD": MirrorStatus.STATUS_SEED,
"CL": MirrorStatus.STATUS_CLONE,
"CM": MirrorStatus.STATUS_CONVERT,
"SP": MirrorStatus.STATUS_SPLIT,
"CK": MirrorStatus.STATUS_CHECK,
"SV": MirrorStatus.STATUS_SAMVID,
"FF": MirrorStatus.STATUS_FFMPEG,
"CL": MirrorStatus.STATUS_CLONE,
"PA": MirrorStatus.STATUS_PAUSED,
"CK": MirrorStatus.STATUS_CHECK,
}


Expand Down Expand Up @@ -235,7 +235,7 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
for i in [1, 2, 4, 6, 8, 10, 15]:
buttons.data_button(i, f"status {sid} ps {i}", position="footer")
if status != "All" or tasks_no > 20:
for label, status_value in list(STATUSES.items())[:9]:
for label, status_value in list(STATUSES.items()):
if status_value != status:
buttons.data_button(label, f"status {sid} st {status_value}")
buttons.data_button("♻️", f"status {sid} ref", position="header")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ async def cancel_task(self):
LOGGER.info(
f"Cancelling download on user request: name: {self._listener.name} id: {self._id}"
)
await self._on_download_error("Cancelled by user!")
await self._on_download_error("Stopped by user!")
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def _download(self, path):
if self._listener.is_cancelled:
return
async_to_sync(self._listener.on_download_complete)
except ValueError:
self._on_download_error("Download Stopped by User!")
except:
pass

async def add_download(self, path, qual, playlist, options):
if playlist:
Expand Down Expand Up @@ -334,7 +334,7 @@ async def add_download(self, path, qual, playlist, options):
async def cancel_task(self):
self._listener.is_cancelled = True
LOGGER.info(f"Cancelling Download: {self._listener.name}")
await self._listener.on_download_error("Download Cancelled by User!")
await self._listener.on_download_error("Stopped by User!")

def _set_options(self, options):
options = options.split("|")
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/gdrive_utils/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ async def cancel_task(self):
self.listener.is_cancelled = True
if self.is_downloading:
LOGGER.info(f"Cancelling Download: {self.listener.name}")
await self.listener.on_download_error("Download stopped by user!")
await self.listener.on_download_error("Stopped by user!")
elif self.is_cloning:
LOGGER.info(f"Cancelling Clone: {self.listener.name}")
await self.listener.on_upload_error(
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/rclone_utils/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ async def cancel_task(self):
pass
if self._is_download:
LOGGER.info(f"Cancelling Download: {self._listener.name}")
await self._listener.on_download_error("Download stopped by user!")
await self._listener.on_download_error("Stopped by user!")
elif self._is_upload:
LOGGER.info(f"Cancelling Upload: {self._listener.name}")
await self._listener.on_upload_error("your upload has been stopped!")
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/status_utils/aria2_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def cancel_task(self):
await sync_to_async(aria2.remove, [self._download], force=True, files=True)
elif downloads := self._download.followed_by:
LOGGER.info(f"Cancelling Download: {self.name()}")
await self.listener.on_download_error("Download cancelled by user!")
await self.listener.on_download_error("Cancelled by user!")
downloads.append(self._download)
await sync_to_async(aria2.remove, downloads, force=True, files=True)
else:
Expand All @@ -108,6 +108,6 @@ async def cancel_task(self):
msg = "task have been removed from queue/download"
else:
LOGGER.info(f"Cancelling Download: {self.name()}")
msg = "Download stopped by user!"
msg = "Stopped by user!"
await self.listener.on_download_error(msg)
await sync_to_async(aria2.remove, [self._download], force=True, files=True)
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ async def cancel_task(self):
)
async with jd_lock:
del jd_downloads[self._gid]
await self.listener.on_download_error("Download cancelled by user!")
await self.listener.on_download_error("Cancelled by user!")
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/status_utils/nzb_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def cancel_task(self):
await self.update()
LOGGER.info(f"Cancelling Download: {self.name()}")
await gather(
self.listener.on_download_error("Download stopped by user!"),
self.listener.on_download_error("Stopped by user!"),
sabnzbd_client.delete_job(self._gid, delete_files=True),
sabnzbd_client.delete_category(f"{self.listener.mid}"),
)
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/status_utils/qbit_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def cancel_task(self):
msg = "task have been removed from queue/download"
else:
LOGGER.info(f"Cancelling Download: {self._info.name}")
msg = "Download stopped by user!"
msg = "Stopped by user!"
await sleep(0.3)
await gather(
self.listener.on_download_error(msg),
Expand Down
1 change: 0 additions & 1 deletion bot/modules/chat_permission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .. import user_data
from ..core.config_manager import Config
from ..helper.ext_utils.bot_utils import update_user_ldata, new_task
from ..helper.ext_utils.db_handler import database
from ..helper.telegram_helper.message_utils import send_message
Expand Down
21 changes: 16 additions & 5 deletions bot/modules/force_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ..helper.ext_utils.bot_utils import new_task
from ..helper.ext_utils.status_utils import get_task_by_gid
from ..helper.telegram_helper.bot_commands import BotCommands
from ..helper.telegram_helper.filters import CustomFilters
from ..helper.telegram_helper.message_utils import send_message
from ..helper.ext_utils.task_manager import start_dl_from_queued, start_up_from_queued

Expand All @@ -33,10 +32,16 @@ async def remove_from_queue(_, message):
await send_message(message, "This is not an active task!")
return
elif len(msg) in {1, 2}:
msg = (
"Reply to an active Command message which was used to start the download"
f" or send <code>/{BotCommands.ForceStartCommand[0]} GID</code> to force start download and upload! Add you can use /cmd <b>fd</b> to force downlaod only or /cmd <b>fu</b> to force upload only!"
)
msg = f"""Reply to an active Command message which was used to start the download/upload.
<code>/{BotCommands.ForceStartCommand[0]}</code> fd (to remove it from download queue) or fu (to remove it from upload queue) or nothing to start remove it from both download and upload queue.
Also send <code>/{BotCommands.ForceStartCommand[0]} GID</code> fu|fd or obly gid to force start by removeing the task rom queue!
Examples:
<code>/{BotCommands.ForceStartCommand[1]}</code> GID fu (force upload)
<code>/{BotCommands.ForceStartCommand[1]}</code> GID (force download and upload)
By reply to task cmd:
<code>/{BotCommands.ForceStartCommand[1]}</code> (force download and upload)
<code>/{BotCommands.ForceStartCommand[1]}</code> fd (force download)
"""
await send_message(message, msg)
return
if (
Expand All @@ -54,11 +59,15 @@ async def remove_from_queue(_, message):
if listener.mid in queued_up:
await start_up_from_queued(listener.mid)
msg = "Task have been force started to upload!"
else:
msg = "Force upload enabled for this task!"
elif status == "fd":
listener.force_download = True
if listener.mid in queued_dl:
await start_dl_from_queued(listener.mid)
msg = "Task have been force started to download only!"
else:
msg = "This task not in download queue!"
else:
listener.force_download = True
listener.force_upload = True
Expand All @@ -68,5 +77,7 @@ async def remove_from_queue(_, message):
elif listener.mid in queued_dl:
await start_dl_from_queued(listener.mid)
msg = "Task have been force started to download and upload will start once download finish!"
else:
msg = "This task not in queue!"
if msg:
await send_message(message, msg)
1 change: 0 additions & 1 deletion bot/modules/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..helper.telegram_helper.message_utils import (
send_message,
delete_message,
edit_message,
)
from ..helper.ext_utils.db_handler import database
from ..helper.ext_utils.files_utils import clean_all
Expand Down

0 comments on commit acf7f2e

Please sign in to comment.