Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
N/A

Signed-off-by: Dawn India <[email protected]>
  • Loading branch information
Dawn-India committed Oct 13, 2024
1 parent efcef43 commit 8d075ce
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 155 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ RUN pip3 install --break-system-packages --no-cache-dir -r requirements.txt

COPY . .

RUN rm -rf py_generators config_sample.env Dockerfile LICENSE README.md requirements.txt

CMD ["bash", "start.sh"]
13 changes: 6 additions & 7 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from asyncio import (
Lock,
get_running_loop,
new_event_loop,
set_event_loop
)
Expand All @@ -15,21 +14,21 @@
dotenv_values
)
from logging import (
INFO,
ERROR,
getLogger,
FileHandler,
StreamHandler,
INFO,
basicConfig,
error as log_error,
FileHandler,
getLogger,
info as log_info,
StreamHandler,
warning as log_warning,
)
from nekozee import Client as TgClient
from os import (
remove,
environ,
path as ospath,
environ
remove
)
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
Expand Down
9 changes: 6 additions & 3 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from nekozee.filters import command
from nekozee.handlers import MessageHandler
from os import execl as osexecl
from signal import SIGINT, signal
from signal import (
SIGINT,
signal
)
from sys import executable
from time import time

Expand Down Expand Up @@ -41,9 +44,9 @@
from .helper.telegram_helper.filters import CustomFilters
from .helper.telegram_helper.message_utils import (
auto_delete_message,
send_message,
edit_message,
send_file
send_file,
send_message
)
from .modules import (
anonymous,
Expand Down
61 changes: 32 additions & 29 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
from aiofiles.os import (
makedirs,
path as aiopath,
remove,
makedirs
remove
)
from asyncio import (
sleep,
create_subprocess_exec,
gather
gather,
sleep
)
from asyncio.subprocess import PIPE
from os import (
walk,
path as ospath
path as ospath,
walk
)
from secrets import token_urlsafe
from aioshutil import (
move,
copy2
copy2,
move
)
from nekozee.enums import ChatAction
from re import sub, I
from re import (
sub,
I
)

from bot import (
bot,
DOWNLOAD_DIR,
LOGGER,
IS_PREMIUM_USER,
MAX_SPLIT_SIZE,
bot,
config_dict,
user_data,
IS_PREMIUM_USER,
user,
cpu_eater_lock,
global_extension_filter,
intervals,
multi_tags,
LOGGER,
subprocess_lock,
task_dict_lock,
task_dict,
global_extension_filter,
cpu_eater_lock,
subprocess_lock,
intervals,
user_data,
user
)
from .ext_utils.bot_utils import (
get_size_bytes,
new_task,
sync_to_async,
get_size_bytes
sync_to_async
)
from .ext_utils.bulk_links import extract_bulk_links
from .ext_utils.exceptions import NotSupportedExtractionArchive
from .ext_utils.files_utils import (
clean_target,
get_base_name,
get_path_size,
is_first_archive_split,
is_archive,
is_archive_split,
get_path_size,
clean_target,
is_archive_split
)
from .ext_utils.links_utils import (
is_gdrive_id,
is_rclone_path,
is_gdrive_link,
is_telegram_link,
is_telegram_link
)
from .ext_utils.media_utils import (
add_attachment,
create_thumb,
create_sample_video,
edit_video_metadata,
take_ss,
take_ss
)
from .ext_utils.media_utils import (
split_file,
get_document_type,
convert_video,
convert_audio,
split_file,
get_document_type
)
from .task_utils.gdrive_utils.list import GoogleDriveList
from .task_utils.rclone_utils.list import RcloneList
Expand All @@ -91,14 +94,14 @@
delete_links,
delete_message,
edit_message,
get_tg_link_message,
is_admin,
is_bot_can_dm,
request_limiter,
send_to_chat,
send_message,
send_log_message,
send_status_message,
get_tg_link_message,
send_status_message
)
from .z_utils import (
none_admin_utils,
Expand Down
19 changes: 6 additions & 13 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ async def _on_download_started(api, gid):
await sync_to_async(download.update)
task.listener.name = download.name
task.listener.is_torrent = download.is_torrent
msg, button = await stop_duplicate_check(task.listener)
(
msg,
button
) = await stop_duplicate_check(task.listener)
if msg:
await task.listener.on_download_error(
msg,
Expand Down Expand Up @@ -111,18 +114,13 @@ async def _on_download_started(api, gid):
if not task.listener.select:
if limit_exceeded := await limit_checker(task.listener):
LOGGER.info(f"Aria2 Limit Exceeded: {task.listener.name} | {get_readable_file_size(task.listener.size)}")
amsg = await task.listener.on_download_error(limit_exceeded)
await task.listener.on_download_error(limit_exceeded)
await sync_to_async(
api.remove,
[download],
force=True,
files=True
)
await delete_links(task.listener.message)
await auto_delete_message(
task.listener.message,
amsg
)
if config_dict["AVG_SPEED"]:
start_time = time()
total_speed = 0
Expand All @@ -140,18 +138,13 @@ async def _on_download_started(api, gid):
LOGGER.info(
f"Task is slower than minimum download speed: {task.listener.name} | {get_readable_file_size(dl_speed)}ps"
)
smsg = await task.listener.on_download_error(min_speed)
await task.listener.on_download_error(min_speed)
await sync_to_async(
api.remove,
[download],
force=True,
files=True
)
await delete_links(task.listener.message)
await auto_delete_message(
task.listener.message,
smsg
)


@loop_thread
Expand Down
6 changes: 1 addition & 5 deletions bot/helper/listeners/jdownloader_listener.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from asyncio import (
sleep,
wait_for
)
from asyncio import sleep

from bot import (
LOGGER,
jd_lock,
jd_downloads,
intervals
Expand Down
13 changes: 5 additions & 8 deletions bot/helper/listeners/nzb_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,18 @@ async def _size_checker(nzo_id):
task = await get_task_by_gid(nzo_id)
await task.update() # type: ignore
task.listener.size = speed_string_to_bytes(task.size()) # type: ignore
if limit_exceeded := await limit_checker(
limit_exceeded = await limit_checker(
task.listener, # type: ignore
is_nzb=True
):
)
if limit_exceeded:
LOGGER.info(
f"NZB Limit Exceeded: {task.name()} | {task.size()}" # type: ignore
)
nmsg = _on_download_error(
_on_download_error(
limit_exceeded,
nzo_id
)
await auto_delete_message(
None,
nmsg
)
) # type: ignore


@new_task
Expand Down
28 changes: 10 additions & 18 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,18 @@ async def _stop_duplicate(tor):
async def _size_checked(tor):
if task := await get_task_by_gid(tor.hash[:12]):
task.listener.size = tor.size
if limit_exceeded := await limit_checker(
limit_exceeded = await limit_checker(
task.listener,
is_torrent=True
):
)
if limit_exceeded:
LOGGER.info(
f"qBit Limit Exceeded: {task.listener.name} | {get_readable_file_size(task.listener.size)}"
)
qmsg = _on_download_error(
_on_download_error(
limit_exceeded,
tor
)
await delete_links(task.listener.message)
await auto_delete_message(
task.listener.message,
qmsg
)
) # type: ignore


@new_task
Expand All @@ -150,22 +146,18 @@ async def _avg_speed_check(tor):
total_speed += dl_speed
count += 1
await sleep(10)
if min_speed := await check_avg_speed(
min_speed = await check_avg_speed(
total_speed,
count
):
)
if min_speed:
LOGGER.info(
f"Task is slower than minimum download speed: {task.listener.name} | {get_readable_file_size(dl_speed)}ps"
)
qmsg = _on_download_error(
_on_download_error(
min_speed,
tor
)
await delete_links(task.listener.message)
await auto_delete_message(
task.listener.message,
qmsg
)
) # type: ignore


@new_task
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/task_utils/download_utils/direct_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ async def add_direct_download(listener, path):
return

gid = token_urlsafe(10)
add_to_queue, event = await check_running_tasks(listener)
(
add_to_queue,
event
) = await check_running_tasks(listener)
if add_to_queue:
LOGGER.info(f"Added to Queue/Download: {listener.name}")
async with task_dict_lock:
Expand Down
7 changes: 1 addition & 6 deletions bot/helper/task_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,9 @@ async def add_jd_download(listener, path):
package_ids=online_packages
)
LOGGER.info(f"JDownloader Limit Exceeded: {listener.name} | {listener.size}")
jdmsg = await listener.on_download_error(limit_exceeded)
await listener.on_download_error(limit_exceeded)
async with jd_lock:
del jd_downloads[gid]
await delete_links(listener.message)
await auto_delete_message(
listener.message,
jdmsg
)
return

if listener.select:
Expand Down
Loading

0 comments on commit 8d075ce

Please sign in to comment.