diff --git a/Dockerfile b/Dockerfile index 8282c2c56b93..f0035bb989a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/bot/__init__.py b/bot/__init__.py index 5007dab19e99..a27b8c414711 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,7 +1,6 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler from asyncio import ( Lock, - get_running_loop, new_event_loop, set_event_loop ) @@ -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 diff --git a/bot/__main__.py b/bot/__main__.py index 5ef6a04a2b18..838b6c2d9572 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -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 @@ -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, diff --git a/bot/helper/common.py b/bot/helper/common.py index 853baa47dca5..7dd159e67eeb 100644 --- a/bot/helper/common.py +++ b/bot/helper/common.py @@ -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 @@ -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, diff --git a/bot/helper/listeners/aria2_listener.py b/bot/helper/listeners/aria2_listener.py index 7067b3f77c28..4ebb264e82b7 100644 --- a/bot/helper/listeners/aria2_listener.py +++ b/bot/helper/listeners/aria2_listener.py @@ -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, @@ -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 @@ -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 diff --git a/bot/helper/listeners/jdownloader_listener.py b/bot/helper/listeners/jdownloader_listener.py index 071c877f795a..4aee2232a9dd 100644 --- a/bot/helper/listeners/jdownloader_listener.py +++ b/bot/helper/listeners/jdownloader_listener.py @@ -1,10 +1,6 @@ -from asyncio import ( - sleep, - wait_for -) +from asyncio import sleep from bot import ( - LOGGER, jd_lock, jd_downloads, intervals diff --git a/bot/helper/listeners/nzb_listener.py b/bot/helper/listeners/nzb_listener.py index 947332637aa0..afd7a0b2f0ef 100644 --- a/bot/helper/listeners/nzb_listener.py +++ b/bot/helper/listeners/nzb_listener.py @@ -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 diff --git a/bot/helper/listeners/qbit_listener.py b/bot/helper/listeners/qbit_listener.py index 2d72563fe094..d4b17a3a6b88 100644 --- a/bot/helper/listeners/qbit_listener.py +++ b/bot/helper/listeners/qbit_listener.py @@ -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 @@ -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 diff --git a/bot/helper/task_utils/download_utils/direct_downloader.py b/bot/helper/task_utils/download_utils/direct_downloader.py index c7b9b32204de..955126cc1894 100644 --- a/bot/helper/task_utils/download_utils/direct_downloader.py +++ b/bot/helper/task_utils/download_utils/direct_downloader.py @@ -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: diff --git a/bot/helper/task_utils/download_utils/jd_download.py b/bot/helper/task_utils/download_utils/jd_download.py index 5e1c37b6ee98..b00ea18df56b 100644 --- a/bot/helper/task_utils/download_utils/jd_download.py +++ b/bot/helper/task_utils/download_utils/jd_download.py @@ -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: diff --git a/bot/helper/task_utils/download_utils/nzb_downloader.py b/bot/helper/task_utils/download_utils/nzb_downloader.py index 6b497a12e6db..1ce04c6ce35d 100644 --- a/bot/helper/task_utils/download_utils/nzb_downloader.py +++ b/bot/helper/task_utils/download_utils/nzb_downloader.py @@ -1,24 +1,24 @@ from aiofiles.os import ( - remove, - path as aiopath + path as aiopath, + remove ) from asyncio import ( gather, sleep ) from sabnzbdapi.exception import ( - NotLoggedIn, - LoginFailed + LoginFailed, + NotLoggedIn ) from bot import ( - task_dict, - task_dict_lock, - sabnzbd_client, LOGGER, config_dict, non_queued_dl, - queue_dict_lock + queue_dict_lock, + sabnzbd_client, + task_dict, + task_dict_lock ) from ...ext_utils.bot_utils import bt_selection_buttons from ...ext_utils.task_manager import check_running_tasks @@ -26,9 +26,9 @@ from ...ext_utils.db_handler import database from ...task_utils.status_utils.nzb_status import SabnzbdStatus from ...telegram_helper.message_utils import ( - send_message, - send_status_message, delete_message, + send_message, + send_status_message ) diff --git a/bot/helper/task_utils/download_utils/rclone_download.py b/bot/helper/task_utils/download_utils/rclone_download.py index 85a303b45424..ee9dbe4c0bb4 100644 --- a/bot/helper/task_utils/download_utils/rclone_download.py +++ b/bot/helper/task_utils/download_utils/rclone_download.py @@ -1,14 +1,14 @@ from asyncio import gather +from aiofiles.os import remove from json import loads from secrets import token_urlsafe -from aiofiles.os import remove from bot import ( - task_dict, - task_dict_lock, - queue_dict_lock, + LOGGER, non_queued_dl, - LOGGER + queue_dict_lock, + task_dict, + task_dict_lock ) from ...ext_utils.bot_utils import cmd_exec from ...ext_utils.status_utils import get_readable_file_size diff --git a/bot/helper/task_utils/download_utils/telegram_download.py b/bot/helper/task_utils/download_utils/telegram_download.py index 71366bc42bb8..541430855b32 100644 --- a/bot/helper/task_utils/download_utils/telegram_download.py +++ b/bot/helper/task_utils/download_utils/telegram_download.py @@ -6,14 +6,14 @@ from nekozee.errors import FloodWait from bot import ( - config_dict, LOGGER, - task_dict, - task_dict_lock, + bot, + config_dict, non_queued_dl, queue_dict_lock, - bot, - user, + task_dict, + task_dict_lock, + user ) from ...ext_utils.task_manager import ( check_running_tasks, diff --git a/bot/helper/task_utils/download_utils/yt_dlp_download.py b/bot/helper/task_utils/download_utils/yt_dlp_download.py index 8d9b7c942436..af0a3a1c45d6 100644 --- a/bot/helper/task_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/task_utils/download_utils/yt_dlp_download.py @@ -1,7 +1,7 @@ from logging import getLogger from os import ( - path as ospath, - listdir + listdir, + path as ospath ) from re import search as re_search from secrets import token_urlsafe @@ -18,8 +18,8 @@ ) from ...ext_utils.status_utils import get_readable_file_size from yt_dlp import ( - YoutubeDL, - DownloadError + DownloadError, + YoutubeDL ) from ...ext_utils.task_manager import ( check_running_tasks, @@ -175,7 +175,10 @@ async def _on_download_start(self, from_queue=False): def _on_download_error(self, error): self._listener.is_cancelled = True - async_to_sync(self._listener.on_download_error, error) + async_to_sync( + self._listener.on_download_error, + error + ) def _extract_meta_data(self): if self._listener.link.startswith(( @@ -251,9 +254,7 @@ def _download(self, path): not ospath.exists(path) or len(listdir(path)) == 0 ): - self._on_download_error( - "No video available to download from this playlist. Check logs for more details" - ) + self._on_download_error("No video available to download from this playlist. Check logs for more details") return if self._listener.is_cancelled: raise ValueError @@ -403,29 +404,20 @@ async def add_download(self, path, qual, playlist, options): return self._listener.is_playlist = self.is_playlist self._listener.playlist_count = self.playlist_count - if limit_exceeded := await limit_checker(self._listener): + limit_exceeded = await limit_checker(self._listener) + if limit_exceeded: LOGGER.info( f"Yt-Dlp Limit Exceeded: {self._listener.name} | {get_readable_file_size(self._listener.size)} | {self.playlist_count}" ) - ymsg = await self._listener.on_download_error(limit_exceeded) - await delete_links(self._listener.message) - await auto_delete_message( - self._listener.message, - ymsg - ) + await self._listener.on_download_error(limit_exceeded) return - if list_exceeded := await list_checker(self._listener): + list_exceeded = await list_checker(self._listener) + if list_exceeded: LOGGER.info( f"Yt-Dlp Limit Exceeded: {self._listener.name} | {get_readable_file_size(self._listener.size)} | {self.playlist_count}" ) - ymsg = await self._listener.on_download_error(list_exceeded) - await delete_links(self._listener.message) - await auto_delete_message( - self._listener.message, - ymsg - ) + await self._listener.on_download_error(list_exceeded) return - ( add_to_queue, event diff --git a/bot/helper/task_utils/gdrive_utils/helper.py b/bot/helper/task_utils/gdrive_utils/helper.py index e47150a705ce..8e97a2d84d33 100644 --- a/bot/helper/task_utils/gdrive_utils/helper.py +++ b/bot/helper/task_utils/gdrive_utils/helper.py @@ -2,16 +2,22 @@ from googleapiclient.discovery import build from google_auth_httplib2 import AuthorizedHttp from googleapiclient.http import build_http -from logging import getLogger, ERROR -from os import path as ospath, listdir +from logging import ( + ERROR, + getLogger +) +from os import ( + listdir, + path as ospath +) from pickle import load as pload from random import randrange from re import search as re_search from tenacity import ( retry, - wait_exponential, - stop_after_attempt, retry_if_exception_type, + stop_after_attempt, + wait_exponential ) from urllib.parse import ( parse_qs, @@ -28,12 +34,10 @@ class GoogleDriveHelper: def __init__(self): - self._OAUTH_SCOPE = ["https://www.googleapis.com/auth/drive"] + self._OAUTH_SCOPE = "https://www.googleapis.com/auth/drive" self.token_path = "token.pickle" self.G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder" - self.G_DRIVE_BASE_DOWNLOAD_URL = ( - "https://drive.google.com/uc?id={}&export=download" - ) + self.G_DRIVE_BASE_DOWNLOAD_URL = "https://drive.google.com/uc?id={}&export=download" self.G_DRIVE_DIR_BASE_DOWNLOAD_URL = "https://drive.google.com/drive/folders/{}" self.is_uploading = False self.is_downloading = False diff --git a/bot/helper/task_utils/gdrive_utils/list.py b/bot/helper/task_utils/gdrive_utils/list.py index 6b1d4a7d36d4..eb4f9eac239c 100644 --- a/bot/helper/task_utils/gdrive_utils/list.py +++ b/bot/helper/task_utils/gdrive_utils/list.py @@ -28,10 +28,10 @@ from ...task_utils.gdrive_utils.helper import GoogleDriveHelper from ...telegram_helper.button_build import ButtonMaker from ...telegram_helper.message_utils import ( - send_message, - edit_message, - delete_message, auto_delete_message, + delete_message, + edit_message, + send_message ) LOGGER = getLogger(__name__) diff --git a/update.py b/update.py index f5923570a5ad..b6be1019ef62 100644 --- a/update.py +++ b/update.py @@ -3,19 +3,23 @@ dotenv_values ) from logging import ( - FileHandler, - StreamHandler, + ERROR, INFO, basicConfig, error as log_error, - info as log_info, + FileHandler, getLogger, - ERROR, + info as log_info, + StreamHandler, +) +from os import ( + environ, + path, + remove ) -from os import path, environ, remove from pymongo.mongo_client import MongoClient from pymongo.server_api import ServerApi -from subprocess import run as srun +from subprocess import run as urun from sys import exit getLogger("pymongo").setLevel(ERROR) @@ -109,16 +113,16 @@ if UPSTREAM_REPO is not None: if path.exists(".git"): - srun([ + urun([ "rm", "-rf", ".git" ]) - update = srun( + update = urun( [ f"git init -q \ - && git config --global user.email support@zee-mirror.in \ + && git config --global user.email support@z-mirror.com \ && git config --global user.name zee \ && git add . \ && git commit -sm update -q \ @@ -135,3 +139,16 @@ else: log_error("Error while getting latest updates.") log_error("Check if entered UPSTREAM_REPO is valid or not!") + +urun( + [ + "rm", + "-rf", + "py_generators", + "config_sample.env", + "Dockerfile", + "LICENSE", + "README.md", + "requirements.txt" + ] +) \ No newline at end of file