Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
name: Build and Publish Docker Image

"on":
push:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
10 changes: 8 additions & 2 deletions megadl/helpers/cypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ async def cy_run(client: Client, msg: Message | CallbackQuery):
await _frwded.reply(
f"**#UPLOAD_LOG** \n\n**From:** `{uid}` \n**Get history:** `/info {uid}`"
)


# admin function handling
# if you are modifying this code: Never have a function name start with "admin_" prefix
# unless its indended to be used by one
if _func_name.startswith("admin") or _func_name in self.req_db_fn:
if not self.database:
await self.cyeor(
Expand Down Expand Up @@ -310,7 +313,10 @@ async def full_cleanup(self, path: str = None, user_id: int = None):
# when run_checks gets triggered by the same user
# not mandatory. would've been better to yield before calling this but thats just more work to do
if path:
fs_cleanup(path)
await asyncio.to_thread(fs_cleanup,path)
# no need for anything else
except asyncio.CancelledError::
pass
except Exception as e:
logging.debug(f"Cleanup error: {e}")

Expand Down
7 changes: 7 additions & 0 deletions megadl/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@


class CypherDB:
# use slots for faster var lookups
# usually this isnt needed, like at all
# i cant justify myself for adding this either
# but wait maybe i can?
# i use find_one_and_update in .add(...) maximum efficiency so i guess its not that conflicting
__slots__ = ("mongoc", "coll_users")

def __init__(self) -> None:
self.mongoc = AsyncMongoClient(getenv("MONGO_URI"))
self.coll_users = self.mongoc["mega_nz"]["users"]
Expand Down
13 changes: 4 additions & 9 deletions megadl/helpers/pyros.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ async def track_progress(
elapsed_time = human_time(elapsed_time)
estimated_total_time = human_time(estimated_total_time)

progress = "[{0}{1}] \n**Process**: {2}%\n".format(
"█" * floor(percentage / 5),
"░" * (20 - floor(percentage / 5)),
round(percentage, 2),
)
filled = floor(percentage / 5)
progress = f"[{'█'*filled}{'░'*(20-filled)}]\n**Process**: {round(percentage,2)}%\n"

tmp = f"{progress}{human_bytes(current)} of {human_bytes(total)}\n**Speed:** {human_bytes(speed)}/s\n**ETA:** {estimated_total_time if estimated_total_time != '' else '0 s'}\n"
pmsg = f"{progress}{human_bytes(current)} of {human_bytes(total)}\n**Speed:** {human_bytes(speed)}/s\n**ETA:** {estimated_total_time if estimated_total_time != '' else '0 s'}\n\n\n**Powered by @NexaBotsUpdates**"
try:
await client.edit_message_text(
chat_id, msg_id, f"{tmp}\n\n**Powered by @NexaBotsUpdates**", **kwargs
)
await client.edit_message_text(chat_id, msg_id, pmsg, **kwargs)
except:
pass
3 changes: 2 additions & 1 deletion megadl/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Helper libraries for Mega.nz-Bot

# Extensions
- [`megatools`](megatools.py) - Wrapper for megatools cli with extended features
- [`ddl`](ddl.py) - Downloader for direct download links and gdrive
- [`ddl`](ddl.py) - Downloader for direct download links and ~gdrive~
- [`splitter`](splitter.py) - Optimized async file splitter for resource-constrained environments
10 changes: 6 additions & 4 deletions megadl/lib/ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Downloader:
_session = None
_lock = asyncio.Lock()

# again same comment as the one you'd find in helpers/database.py -> CypherDB
__slots__ = ("tg_client",) # dont remove "," its there for a reason

def __init__(self, client) -> None:
self.tg_client = client

Expand Down Expand Up @@ -174,21 +177,20 @@ async def from_ddl(
total = resp.content_length
curr = 0
st = time()
# for update throttling
last_up = 0
up_interval = 2
can_progress = None not in (chat_id, msg_id, self.tg_client, total)

async with async_open(wpath, mode="wb") as file:
async for chunk in resp.content.iter_chunked(_chunksize):
# yield before write
await asyncio.sleep(0)

# write chunk
await file.write(chunk)
curr += len(chunk)

# Make sure everything is present before calling track_progress
now = time()
if None not in (chat_id, msg_id, self.tg_client, total) and (now - last_up >= up_interval):
if can_progress and (now - last_up >= up_interval):
await track_progress(
curr,
total,
Expand Down