Some minor changes

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2024-12-04 05:18:00 +02:00
parent f0205ef78e
commit b58b633862
No known key found for this signature in database
GPG Key ID: EAAC8A2DF2861DE4
23 changed files with 174 additions and 312 deletions

View File

@ -54,15 +54,7 @@ from .ext_utils.media_utils import (
)
from .mirror_leech_utils.gdrive_utils.list import GoogleDriveList
from .mirror_leech_utils.rclone_utils.list import RcloneList
from .mirror_leech_utils.status_utils.extract_status import ExtractStatus
from .mirror_leech_utils.status_utils.sample_video_status import (
SampleVideoStatus,
)
from .mirror_leech_utils.status_utils.media_convert_status import (
MediaConvertStatus,
)
from .mirror_leech_utils.status_utils.split_status import SplitStatus
from .mirror_leech_utils.status_utils.zip_status import ZipStatus
from .mirror_leech_utils.status_utils.sevenz_status import SevenZStatus
from .mirror_leech_utils.status_utils.ffmpeg_status import FFmpegStatus
from .telegram_helper.bot_commands import BotCommands
from .telegram_helper.message_utils import (
@ -123,7 +115,7 @@ class TaskConfig:
self.as_doc = False
self.ffmpeg_cmds = None
self.chat_thread_id = None
self.suproc = None
self.subproc = None
self.thumb = None
self.extension_filter = []
self.is_super_chat = self.message.chat.type.name in ["SUPERGROUP", "CHANNEL"]
@ -557,13 +549,13 @@ class TaskConfig:
if self.is_cancelled:
return ""
async with subprocess_lock:
self.suproc = await create_subprocess_exec(
self.subproc = await create_subprocess_exec(
*cmd, stderr=PIPE
)
_, stderr = await self.suproc.communicate()
_, stderr = await self.subproc.communicate()
if self.is_cancelled:
return ""
code = self.suproc.returncode
code = self.subproc.returncode
if code != 0:
try:
stderr = stderr.decode().strip()
@ -581,11 +573,11 @@ class TaskConfig:
if self.is_cancelled:
return ""
async with subprocess_lock:
self.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.suproc.communicate()
self.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.subproc.communicate()
if self.is_cancelled:
return ""
code = self.suproc.returncode
code = self.subproc.returncode
if code != 0:
try:
stderr = stderr.decode().strip()
@ -602,7 +594,7 @@ class TaskConfig:
try:
LOGGER.info(f"Extracting: {self.name}")
async with task_dict_lock:
task_dict[self.mid] = ExtractStatus(self, gid)
task_dict[self.mid] = SevenZStatus(self, gid, "Extract")
if await aiopath.isdir(dl_path):
if self.seed:
self.new_dir = f"{self.dir}10000"
@ -640,13 +632,13 @@ class TaskConfig:
if self.is_cancelled:
return ""
async with subprocess_lock:
self.suproc = await create_subprocess_exec(
self.subproc = await create_subprocess_exec(
*cmd, stderr=PIPE
)
_, stderr = await self.suproc.communicate()
_, stderr = await self.subproc.communicate()
if self.is_cancelled:
return ""
code = self.suproc.returncode
code = self.subproc.returncode
if code != 0:
try:
stderr = stderr.decode().strip()
@ -657,8 +649,8 @@ class TaskConfig:
)
if (
not self.seed
and self.suproc is not None
and self.suproc.returncode == 0
and self.subproc is not None
and self.subproc.returncode == 0
):
for file_ in files:
if is_archive_split(file_) or is_archive(file_):
@ -688,11 +680,11 @@ class TaskConfig:
if self.is_cancelled:
return ""
async with subprocess_lock:
self.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.suproc.communicate()
self.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.subproc.communicate()
if self.is_cancelled:
return ""
code = self.suproc.returncode
code = self.subproc.returncode
if code == -9:
self.is_cancelled = True
return ""
@ -731,7 +723,7 @@ class TaskConfig:
up_path = f"{dl_path}.7z"
delete = True
async with task_dict_lock:
task_dict[self.mid] = ZipStatus(self, gid)
task_dict[self.mid] = SevenZStatus(self, gid, "Zip")
size = await get_path_size(dl_path)
if self.equal_splits:
parts = -(-size // self.split_size)
@ -768,11 +760,11 @@ class TaskConfig:
if self.is_cancelled:
return ""
async with subprocess_lock:
self.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.suproc.communicate()
self.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await self.subproc.communicate()
if self.is_cancelled:
return ""
code = self.suproc.returncode
code = self.subproc.returncode
if code == -9:
self.is_cancelled = True
return ""
@ -810,7 +802,7 @@ class TaskConfig:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = SplitStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "Split")
LOGGER.info(f"Splitting: {self.name}")
res = await split_file(
f_path, f_size, dirpath, file_, self.split_size, self
@ -849,7 +841,7 @@ class TaskConfig:
part_duration = 4
async with task_dict_lock:
task_dict[self.mid] = SampleVideoStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "Sample Video")
checked = False
if await aiopath.isfile(dl_path):
@ -962,7 +954,7 @@ class TaskConfig:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = MediaConvertStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "Convert")
await cpu_eater_lock.acquire()
LOGGER.info(f"Converting: {self.name}")
else:
@ -985,7 +977,7 @@ class TaskConfig:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = MediaConvertStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "Convert")
await cpu_eater_lock.acquire()
LOGGER.info(f"Converting: {self.name}")
else:
@ -1133,7 +1125,12 @@ class TaskConfig:
async def proceed_ffmpeg(self, dl_path, gid):
checked = False
for ffmpeg_cmd in self.ffmpeg_cmds:
cmd = ["ffmpeg"] + ffmpeg_cmd
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
] + ffmpeg_cmd
if "-del" in cmd:
cmd.remove("-del")
delete_files = True
@ -1168,7 +1165,7 @@ class TaskConfig:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "FFmpeg")
await cpu_eater_lock.acquire()
LOGGER.info(f"Running ffmpeg cmd for: {file_path}")
cmd[index + 1] = file_path
@ -1197,7 +1194,7 @@ class TaskConfig:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(self, gid)
task_dict[self.mid] = FFmpegStatus(self, gid, "FFmpeg")
await cpu_eater_lock.acquire()
LOGGER.info(f"Running ffmpeg cmd for: {f_path}")
res = await run_ffmpeg_cmd(self, cmd, f_path)

View File

@ -18,6 +18,9 @@ async def convert_video(listener, video_file, ext, retry=False):
if retry:
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-i",
video_file,
"-c:v",
@ -35,15 +38,27 @@ async def convert_video(listener, video_file, ext, retry=False):
else:
cmd[7:7] = ["-c:s", "copy"]
else:
cmd = ["ffmpeg", "-i", video_file, "-map", "0", "-c", "copy", output]
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-i",
video_file,
"-map",
"0",
"-c",
"copy",
output,
]
if listener.is_cancelled:
return False
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == 0:
return output
elif code == -9:
@ -70,6 +85,9 @@ async def convert_audio(listener, audio_file, ext):
output = f"{base_name}.{ext}"
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-i",
audio_file,
"-threads",
@ -79,11 +97,11 @@ async def convert_audio(listener, audio_file, ext):
if listener.is_cancelled:
return False
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == 0:
return output
elif code == -9:
@ -450,11 +468,11 @@ async def split_file(
if listener.is_cancelled:
return False
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == -9:
listener.is_cancelled = True
return False
@ -526,7 +544,7 @@ async def split_file(
async with subprocess_lock:
if listener.is_cancelled:
return False
listener.suproc = await create_subprocess_exec(
listener.subproc = await create_subprocess_exec(
"split",
"--numeric-suffixes=1",
"--suffix-length=3",
@ -535,10 +553,10 @@ async def split_file(
out_path,
stderr=PIPE,
)
_, stderr = await listener.suproc.communicate()
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == -9:
listener.is_cancelled = True
return False
@ -581,6 +599,9 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-i",
video_file,
"-filter_complex",
@ -601,11 +622,11 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
if listener.is_cancelled:
return False
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == -9:
listener.is_cancelled = True
return False
@ -630,6 +651,9 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
output_seg = f"{dir}/mltb_segments/segment{index}.{ext}"
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-i",
video_file,
"-ss",
@ -642,11 +666,11 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
]
if listener.is_cancelled:
return False
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == -9:
listener.is_cancelled = True
return False
@ -671,6 +695,9 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
cmd = [
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-f",
"concat",
"-safe",
@ -687,11 +714,11 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
]
if listener.is_cancelled:
return False
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == -9:
listener.is_cancelled = True
return False
@ -728,11 +755,11 @@ async def run_ffmpeg_cmd(listener, ffmpeg, path):
if listener.is_cancelled:
return False
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(*ffmpeg, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
listener.subproc = await create_subprocess_exec(*ffmpeg, stderr=PIPE)
_, stderr = await listener.subproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
code = listener.subproc.returncode
if code == 0:
return output
elif code == -9:

View File

@ -18,37 +18,37 @@ SIZE_UNITS = ["B", "KB", "MB", "GB", "TB", "PB"]
class MirrorStatus:
STATUS_UPLOADING = "Upload"
STATUS_DOWNLOADING = "Download"
STATUS_CLONING = "Clone"
STATUS_UPLOAD = "Upload"
STATUS_DOWNLOAD = "Download"
STATUS_CLONE = "Clone"
STATUS_QUEUEDL = "QueueDl"
STATUS_QUEUEUP = "QueueUp"
STATUS_PAUSED = "Pause"
STATUS_ARCHIVING = "Archive"
STATUS_EXTRACTING = "Extract"
STATUS_SPLITTING = "Split"
STATUS_CHECKING = "CheckUp"
STATUS_SEEDING = "Seed"
STATUS_ARCHIVE = "Archive"
STATUS_EXTRACT = "Extract"
STATUS_SPLIT = "Split"
STATUS_CHECK = "CheckUp"
STATUS_SEED = "Seed"
STATUS_SAMVID = "SamVid"
STATUS_CONVERTING = "Convert"
STATUS_CONVERT = "Convert"
STATUS_FFMPEG = "FFmpeg"
STATUSES = {
"ALL": "All",
"DL": MirrorStatus.STATUS_DOWNLOADING,
"UP": MirrorStatus.STATUS_UPLOADING,
"DL": MirrorStatus.STATUS_DOWNLOAD,
"UP": MirrorStatus.STATUS_UPLOAD,
"QD": MirrorStatus.STATUS_QUEUEDL,
"QU": MirrorStatus.STATUS_QUEUEUP,
"AR": MirrorStatus.STATUS_ARCHIVING,
"EX": MirrorStatus.STATUS_EXTRACTING,
"SD": MirrorStatus.STATUS_SEEDING,
"CM": MirrorStatus.STATUS_CONVERTING,
"SP": MirrorStatus.STATUS_SPLITTING,
"CK": MirrorStatus.STATUS_CHECKING,
"AR": MirrorStatus.STATUS_ARCHIVE,
"EX": MirrorStatus.STATUS_EXTRACT,
"SD": MirrorStatus.STATUS_SEED,
"CM": MirrorStatus.STATUS_CONVERT,
"SP": MirrorStatus.STATUS_SPLIT,
"CK": MirrorStatus.STATUS_CHECK,
"SV": MirrorStatus.STATUS_SAMVID,
"FF": MirrorStatus.STATUS_FFMPEG,
"CL": MirrorStatus.STATUS_CLONING,
"CL": MirrorStatus.STATUS_CLONE,
"PA": MirrorStatus.STATUS_PAUSED,
}
@ -77,7 +77,7 @@ def get_specific_tasks(status, user_id):
and (
(st := tk.status())
and st == status
or status == MirrorStatus.STATUS_DOWNLOADING
or status == MirrorStatus.STATUS_DOWNLOAD
and st not in STATUSES.values()
)
]
@ -87,7 +87,7 @@ def get_specific_tasks(status, user_id):
for tk in task_dict.values()
if (st := tk.status())
and st == status
or status == MirrorStatus.STATUS_DOWNLOADING
or status == MirrorStatus.STATUS_DOWNLOAD
and st not in STATUSES.values()
]
@ -190,10 +190,10 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
msg += f"<b>{index + start_position}.{tstatus}: </b>"
msg += f"<code>{escape(f'{task.name()}')}</code>"
if tstatus not in [
MirrorStatus.STATUS_SPLITTING,
MirrorStatus.STATUS_SEEDING,
MirrorStatus.STATUS_SPLIT,
MirrorStatus.STATUS_SEED,
MirrorStatus.STATUS_SAMVID,
MirrorStatus.STATUS_CONVERTING,
MirrorStatus.STATUS_CONVERT,
MirrorStatus.STATUS_FFMPEG,
MirrorStatus.STATUS_QUEUEUP,
]:
@ -210,7 +210,7 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
msg += f"\n<b>Seeders:</b> {task.seeders_num()} | <b>Leechers:</b> {task.leechers_num()}"
except:
pass
elif tstatus == MirrorStatus.STATUS_SEEDING:
elif tstatus == MirrorStatus.STATUS_SEED:
msg += f"\n<b>Size: </b>{task.size()}"
msg += f"\n<b>Speed: </b>{task.seed_speed()}"
msg += f" | <b>Uploaded: </b>{task.uploaded_bytes()}"

View File

@ -9,7 +9,7 @@ from ...ext_utils.bot_utils import sync_to_async, async_to_sync
from ...ext_utils.task_manager import check_running_tasks, stop_duplicate_check
from ...mirror_leech_utils.status_utils.queue_status import QueueStatus
from ...telegram_helper.message_utils import send_status_message
from ..status_utils.yt_dlp_download_status import YtDlpStatus
from ..status_utils.yt_dlp_status import YtDlpStatus
LOGGER = getLogger(__name__)

View File

@ -121,7 +121,7 @@ class RcloneTransferHelper:
if return_code == 0:
await self._listener.on_download_complete()
elif return_code != -9:
error = (await self._proc.stderr.read()).decode().strip() or "Use <code>/shell cat rlog.txt</code> to see more information"
error = (await self._proc.stderr.read()).decode().strip() or "Use <code>/shell cat rlog.txt</code> to see more information"
if not error and remote_type == "drive" and self._use_service_accounts:
error = "Mostly your service accounts don't have access to this drive!"
elif not error:
@ -239,7 +239,7 @@ class RcloneTransferHelper:
if return_code == -9:
return False
elif return_code != 0:
error = (await self._proc.stderr.read()).decode().strip() or "Use <code>/shell cat rlog.txt</code> to see more information"
error = (await self._proc.stderr.read()).decode().strip() or "Use <code>/shell cat rlog.txt</code> to see more information"
if not error and remote_type == "drive" and self._use_service_accounts:
error = "Mostly your service accounts don't have access to this drive or RATE_LIMIT_EXCEEDED"
elif not error:

View File

@ -60,9 +60,9 @@ class Aria2Status:
elif self._download.is_paused:
return MirrorStatus.STATUS_PAUSED
elif self._download.seeder and self.seeding:
return MirrorStatus.STATUS_SEEDING
return MirrorStatus.STATUS_SEED
else:
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
def seeders_num(self):
return self._download.num_seeders

View File

@ -42,7 +42,7 @@ class DirectStatus:
def status(self):
if self._obj.download_task and self._obj.download_task.is_waiting:
return MirrorStatus.STATUS_QUEUEDL
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
def processed_bytes(self):
return get_readable_file_size(self._obj.processed_bytes)

View File

@ -3,10 +3,11 @@ from ...ext_utils.status_utils import get_readable_file_size, MirrorStatus
class FFmpegStatus:
def __init__(self, listener, gid):
def __init__(self, listener, gid, status=""):
self.listener = listener
self._gid = gid
self._size = self.listener.size
self.cstatus = status
def gid(self):
return self._gid
@ -18,18 +19,25 @@ class FFmpegStatus:
return get_readable_file_size(self._size)
def status(self):
return MirrorStatus.STATUS_FFMPEG
if self.cstatus == "Convert":
return MirrorStatus.STATUS_CONVERT
elif self.cstatus == "Split":
return MirrorStatus.STATUS_SPLIT
elif self.cstatus == "Sample Video":
return MirrorStatus.STATUS_SAMVID
else:
return MirrorStatus.STATUS_FFMPEG
def task(self):
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling ffmpeg_cmd: {self.listener.name}")
LOGGER.info(f"Cancelling {self.cstatus}: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if (
self.listener.suproc is not None
and self.listener.suproc.returncode is None
self.listener.subproc is not None
and self.listener.subproc.returncode is None
):
self.listener.suproc.kill()
await self.listener.on_upload_error("ffmpeg cmd stopped by user!")
self.listener.subproc.kill()
await self.listener.on_upload_error(f"{self.cstatus} stopped by user!")

View File

@ -21,11 +21,11 @@ class GoogleDriveStatus:
def status(self):
if self._status == "up":
return MirrorStatus.STATUS_UPLOADING
return MirrorStatus.STATUS_UPLOAD
elif self._status == "dl":
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
else:
return MirrorStatus.STATUS_CLONING
return MirrorStatus.STATUS_CLONE
def name(self):
return self.listener.name

View File

@ -1,32 +0,0 @@
from bot import LOGGER, subprocess_lock
from ...ext_utils.status_utils import get_readable_file_size, MirrorStatus
class MediaConvertStatus:
def __init__(self, listener, gid):
self.listener = listener
self._gid = gid
self._size = self.listener.size
def gid(self):
return self._gid
def name(self):
return self.listener.name
def size(self):
return get_readable_file_size(self._size)
def status(self):
return MirrorStatus.STATUS_CONVERTING
def task(self):
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling Converting: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if self.listener.suproc is not None and self.listener.suproc.returncode is None:
self.listener.suproc.kill()
await self.listener.on_upload_error("Converting stopped by user!")

View File

@ -75,7 +75,7 @@ class SabnzbdStatus:
elif state == "Paused":
return MirrorStatus.STATUS_PAUSED
else:
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
def task(self):
return self

View File

@ -59,11 +59,11 @@ class QbittorrentStatus:
elif state in ["pausedDL", "pausedUP"]:
return MirrorStatus.STATUS_PAUSED
elif state in ["checkingUP", "checkingDL"]:
return MirrorStatus.STATUS_CHECKING
return MirrorStatus.STATUS_CHECK
elif state in ["stalledUP", "uploading"] and self.seeding:
return MirrorStatus.STATUS_SEEDING
return MirrorStatus.STATUS_SEED
else:
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
def seeders_num(self):
return self._info.num_seeds

View File

@ -28,11 +28,11 @@ class RcloneStatus:
def status(self):
if self._status == "dl":
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
elif self._status == "up":
return MirrorStatus.STATUS_UPLOADING
return MirrorStatus.STATUS_UPLOAD
else:
return MirrorStatus.STATUS_CLONING
return MirrorStatus.STATUS_CLONE
def processed_bytes(self):
return self._obj.transferred_size

View File

@ -1,32 +0,0 @@
from bot import LOGGER, subprocess_lock
from ...ext_utils.status_utils import get_readable_file_size, MirrorStatus
class SampleVideoStatus:
def __init__(self, listener, gid):
self.listener = listener
self._gid = gid
self._size = self.listener.size
def gid(self):
return self._gid
def name(self):
return self.listener.name
def size(self):
return get_readable_file_size(self._size)
def status(self):
return MirrorStatus.STATUS_SAMVID
def task(self):
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling Sample Video: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if self.listener.suproc is not None and self.listener.suproc.returncode is None:
self.listener.suproc.kill()
await self.listener.on_upload_error("Creating sample video stopped by user!")

View File

@ -9,13 +9,14 @@ from ...ext_utils.status_utils import (
)
class ExtractStatus:
def __init__(self, listener, gid):
class SevenZStatus:
def __init__(self, listener, gid, status=""):
self.listener = listener
self._size = self.listener.size
self._gid = gid
self._start_time = time()
self._proccessed_bytes = 0
self.cstatus = status
def gid(self):
return self._gid
@ -50,7 +51,10 @@ class ExtractStatus:
return "-"
def status(self):
return MirrorStatus.STATUS_EXTRACTING
if self.cstatus == "Extract":
return MirrorStatus.STATUS_EXTRACT
else:
return MirrorStatus.STATUS_ARCHIVE
def processed_bytes(self):
return get_readable_file_size(self._proccessed_bytes)
@ -65,12 +69,12 @@ class ExtractStatus:
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling Extract: {self.listener.name}")
LOGGER.info(f"Cancelling {self.cstatus}: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if (
self.listener.suproc is not None
and self.listener.suproc.returncode is None
self.listener.subproc is not None
and self.listener.subproc.returncode is None
):
self.listener.suproc.kill()
await self.listener.on_upload_error("extracting stopped by user!")
self.listener.subproc.kill()
await self.listener.on_upload_error(f"{self.cstatus} stopped by user!")

View File

@ -1,35 +0,0 @@
from bot import LOGGER, subprocess_lock
from ...ext_utils.status_utils import get_readable_file_size, MirrorStatus
class SplitStatus:
def __init__(self, listener, gid):
self.listener = listener
self._gid = gid
self._size = self.listener.size
def gid(self):
return self._gid
def name(self):
return self.listener.name
def size(self):
return get_readable_file_size(self._size)
def status(self):
return MirrorStatus.STATUS_SPLITTING
def task(self):
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling Split: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if (
self.listener.suproc is not None
and self.listener.suproc.returncode is None
):
self.listener.suproc.kill()
await self.listener.on_upload_error("splitting stopped by user!")

View File

@ -21,8 +21,8 @@ class TelegramStatus:
def status(self):
if self._status == "up":
return MirrorStatus.STATUS_UPLOADING
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_UPLOAD
return MirrorStatus.STATUS_DOWNLOAD
def name(self):
return self.listener.name

View File

@ -29,7 +29,7 @@ class YtDlpStatus:
return get_readable_file_size(self._obj.size)
def status(self):
return MirrorStatus.STATUS_DOWNLOADING
return MirrorStatus.STATUS_DOWNLOAD
def name(self):
return self.listener.name

View File

@ -1,76 +0,0 @@
from time import time
from bot import LOGGER, subprocess_lock
from ...ext_utils.files_utils import get_path_size
from ...ext_utils.status_utils import (
get_readable_file_size,
MirrorStatus,
get_readable_time,
)
class ZipStatus:
def __init__(self, listener, gid):
self.listener = listener
self._size = self.listener.size
self._gid = gid
self._start_time = time()
self._proccessed_bytes = 0
def gid(self):
return self._gid
def speed_raw(self):
return self._proccessed_bytes / (time() - self._start_time)
async def progress_raw(self):
await self.processed_raw()
try:
return self._proccessed_bytes / self._size * 100
except:
return 0
async def progress(self):
return f"{round(await self.progress_raw(), 2)}%"
def speed(self):
return f"{get_readable_file_size(self.speed_raw())}/s"
def name(self):
return self.listener.name
def size(self):
return get_readable_file_size(self._size)
def eta(self):
try:
seconds = (self._size - self._proccessed_bytes) / self.speed_raw()
return get_readable_time(seconds)
except:
return "-"
def status(self):
return MirrorStatus.STATUS_ARCHIVING
async def processed_raw(self):
if self.listener.new_dir:
self._proccessed_bytes = await get_path_size(self.listener.new_dir)
else:
self._proccessed_bytes = await get_path_size(self.listener.dir) - self._size
def processed_bytes(self):
return get_readable_file_size(self._proccessed_bytes)
def task(self):
return self
async def cancel_task(self):
LOGGER.info(f"Cancelling Archive: {self.listener.name}")
self.listener.is_cancelled = True
async with subprocess_lock:
if (
self.listener.suproc is not None
and self.listener.suproc.returncode is None
):
self.listener.suproc.kill()
await self.listener.on_upload_error("archiving stopped by user!")

View File

@ -89,21 +89,21 @@ async def cancel_all(status, user_id):
def create_cancel_buttons(is_sudo, user_id=""):
buttons = button_build.ButtonMaker()
buttons.data_button(
"Downloading", f"canall ms {MirrorStatus.STATUS_DOWNLOADING} {user_id}"
"Downloading", f"canall ms {MirrorStatus.STATUS_DOWNLOAD} {user_id}"
)
buttons.data_button(
"Uploading", f"canall ms {MirrorStatus.STATUS_UPLOADING} {user_id}"
"Uploading", f"canall ms {MirrorStatus.STATUS_UPLOAD} {user_id}"
)
buttons.data_button("Seeding", f"canall ms {MirrorStatus.STATUS_SEEDING} {user_id}")
buttons.data_button("Seeding", f"canall ms {MirrorStatus.STATUS_SEED} {user_id}")
buttons.data_button(
"Spltting", f"canall ms {MirrorStatus.STATUS_SPLITTING} {user_id}"
"Spltting", f"canall ms {MirrorStatus.STATUS_SPLIT} {user_id}"
)
buttons.data_button("Cloning", f"canall ms {MirrorStatus.STATUS_CLONING} {user_id}")
buttons.data_button("Cloning", f"canall ms {MirrorStatus.STATUS_CLONE} {user_id}")
buttons.data_button(
"Extracting", f"canall ms {MirrorStatus.STATUS_EXTRACTING} {user_id}"
"Extracting", f"canall ms {MirrorStatus.STATUS_EXTRACT} {user_id}"
)
buttons.data_button(
"Archiving", f"canall ms {MirrorStatus.STATUS_ARCHIVING} {user_id}"
"Archiving", f"canall ms {MirrorStatus.STATUS_ARCHIVE} {user_id}"
)
buttons.data_button(
"QueuedDl", f"canall ms {MirrorStatus.STATUS_QUEUEDL} {user_id}"
@ -115,7 +115,7 @@ def create_cancel_buttons(is_sudo, user_id=""):
"SampleVideo", f"canall ms {MirrorStatus.STATUS_SAMVID} {user_id}"
)
buttons.data_button(
"ConvertMedia", f"canall ms {MirrorStatus.STATUS_CONVERTING} {user_id}"
"ConvertMedia", f"canall ms {MirrorStatus.STATUS_CONVERT} {user_id}"
)
buttons.data_button("FFmpeg", f"canall ms {MirrorStatus.STATUS_FFMPEG} {user_id}")
buttons.data_button("Paused", f"canall ms {MirrorStatus.STATUS_PAUSED} {user_id}")

View File

@ -64,7 +64,7 @@ async def select(_, message):
await send_message(message, "This task is not for you!")
return
if await sync_to_async(task.status) not in [
MirrorStatus.STATUS_DOWNLOADING,
MirrorStatus.STATUS_DOWNLOAD,
MirrorStatus.STATUS_PAUSED,
MirrorStatus.STATUS_QUEUEDL,
]:

View File

@ -107,34 +107,34 @@ async def status_pages(_, query):
async with task_dict_lock:
for download in task_dict.values():
match await sync_to_async(download.status):
case MirrorStatus.STATUS_DOWNLOADING:
case MirrorStatus.STATUS_DOWNLOAD:
tasks["Download"] += 1
dl_speed += speed_string_to_bytes(download.speed())
case MirrorStatus.STATUS_UPLOADING:
case MirrorStatus.STATUS_UPLOAD:
tasks["Upload"] += 1
up_speed += speed_string_to_bytes(download.speed())
case MirrorStatus.STATUS_SEEDING:
case MirrorStatus.STATUS_SEED:
tasks["Seed"] += 1
seed_speed += speed_string_to_bytes(download.seed_speed())
case MirrorStatus.STATUS_ARCHIVING:
case MirrorStatus.STATUS_ARCHIVE:
tasks["Archive"] += 1
case MirrorStatus.STATUS_EXTRACTING:
case MirrorStatus.STATUS_EXTRACT:
tasks["Extract"] += 1
case MirrorStatus.STATUS_SPLITTING:
case MirrorStatus.STATUS_SPLIT:
tasks["Split"] += 1
case MirrorStatus.STATUS_QUEUEDL:
tasks["QueueDl"] += 1
case MirrorStatus.STATUS_QUEUEUP:
tasks["QueueUp"] += 1
case MirrorStatus.STATUS_CLONING:
case MirrorStatus.STATUS_CLONE:
tasks["Clone"] += 1
case MirrorStatus.STATUS_CHECKING:
case MirrorStatus.STATUS_CHECK:
tasks["CheckUp"] += 1
case MirrorStatus.STATUS_PAUSED:
tasks["Pause"] += 1
case MirrorStatus.STATUS_SAMVID:
tasks["SamVid"] += 1
case MirrorStatus.STATUS_CONVERTING:
case MirrorStatus.STATUS_CONVERT:
tasks["ConvertMedia"] += 1
case MirrorStatus.STATUS_FFMPEG:
tasks["FFMPEG"] += 1