Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
Fix errors from the last PR.
- Sync MLTB.
- Fix same directory stuck issue.
- Add ability to use different folder names using -sd arg along with the links inside the batch.
- Other minor fixes.
- Fix some bugs in jdowloader while using multi.
- Now you do jd sync while downloading (not while collecting)(not recommended).
- Remove youtube links restriction in jdownloader (i didn't try youtube download with jd yet).
- Minor fix for jdwonloader sync while download and when adding creds from bot settings.
- Some fixes and improvemnts for jdownloader.
- Fix file uplaod name (important).
- Remove offline files auto from jd packages.
- Fix ddl mediafire.
- Trim path for jdownloader incase the path length is more than 255.
- In case you got file error invalid download path then you must rename the file(s).
- I have done the folder rename auto for you but i don't want to fetch all files names, this  will take a lot of time.
  • Loading branch information
Dawn-India committed Oct 11, 2024
1 parent 9c21180 commit c13d146
Show file tree
Hide file tree
Showing 18 changed files with 749 additions and 663 deletions.
32 changes: 19 additions & 13 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self):
self.thumbnail_layout = ""
self.metadata = None
self.m_attachment = None
self.folder_name = ""
self.get_chat = None
self.split_size = 0
self.max_split_size = 0
Expand Down Expand Up @@ -776,7 +777,7 @@ async def get_tag(self, text: list):
self.tag = self.user.id

@new_task
async def run_multi(self, input_list, folder_name, obj):
async def run_multi(self, input_list, obj):
if (
config_dict["DISABLE_MULTI"]
and self.multi > 1
Expand Down Expand Up @@ -816,6 +817,9 @@ async def run_multi(self, input_list, folder_name, obj):
self.message, # type: ignore
smsg
)
async with task_dict_lock:
for fd_name in self.same_dir: # type: ignore
self.same_dir[fd_name]["total"] -= self.multi # type: ignore
return
if len(self.bulk) != 0:
msg = input_list[:1]
Expand Down Expand Up @@ -850,8 +854,6 @@ async def run_multi(self, input_list, folder_name, obj):
chat_id=self.message.chat.id, # type: ignore
message_ids=nextmsg.id # type: ignore
)
if folder_name:
self.same_dir["tasks"].add(nextmsg.id) # type: ignore
if self.message.from_user: # type: ignore
nextmsg.from_user = self.user
else:
Expand Down Expand Up @@ -901,9 +903,14 @@ async def init_bulk(self, input_list, bulk_start, bulk_end, obj):
del self.options[index + 1]
self.options = " ".join(self.options)
b_msg.append(f"{self.bulk[0]} -m {len(self.bulk)} {self.options}")
msg = " ".join(b_msg)
if len(self.bulk) > 2:
self.multi_tag = token_urlsafe(3)
multi_tags.add(self.multi_tag)
msg += f"\nCancel Multi: <code>/{BotCommands.CancelTaskCommand[1]} {self.multi_tag}</code>"
nextmsg = await send_message(
self.message, # type: ignore
" ".join(b_msg)
msg
)
nextmsg = await self.client.get_messages( # type: ignore
chat_id=self.message.chat.id, # type: ignore
Expand Down Expand Up @@ -1352,15 +1359,14 @@ async def generate_sample_video(self, dl_path, gid, unwanted_files, ft_delete):
if await aiopath.isfile(dl_path):
if (await get_document_type(dl_path))[0]:
checked = True
await cpu_eater_lock.acquire()
LOGGER.info(f"Creating Sample video: {self.name}")
res = await create_sample_video(
self,
dl_path,
sample_duration,
part_duration
)
cpu_eater_lock.release()
async with cpu_eater_lock:
LOGGER.info(f"Creating Sample video: {self.name}")
res = await create_sample_video(
self,
dl_path,
sample_duration,
part_duration
)
if res:
newfolder = ospath.splitext(dl_path)[0]
name = dl_path.rsplit(
Expand Down
1 change: 1 addition & 0 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def retry_function(func, *args, **kwargs):
**kwargs
)
except:
await sleep(0.2)
return await retry_function(
func,
*args,
Expand Down
39 changes: 30 additions & 9 deletions bot/helper/ext_utils/help_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,27 @@
"""

same_dir = """
<b>Multi links within the same upload directory only by replying to the first link/file</b>: -sd
<b>Move file(s)/folder(s) to new folder</b>: -sd
/cmd -m 10(number of links/files) -sd folder name (multi message)
/cmd -b -sd folder name (bulk-message/file)
You can use this arg also to move multiple links/torrents contents to the same directory, so all links will be uploaded together as one task
/cmd link -sd new folder (only one link inside new folder)
/cmd -m 10(number of links/files) -sd folder name (all links contents in one folder)
/cmd -b -sd folder name (reply to batch of message/file(each link on new line))
While using bulk you can also use this arg with different folder name along with the links in message or file batch
Example:
link1 -sd folder1
link2 -sd folder1
link3 -sd folder2
link4 -sd folder2
link5 -sd folder3
link6
so link1 and link2 content will be uploaded from same folder which is folder1
link3 and link4 content will be uploaded from same folder also which is folder2
link5 will uploaded alone inside new folder named folder3
link6 will get uploaded normally alone
"""

thumb = """
Expand Down Expand Up @@ -102,16 +119,20 @@
bulk = """
<b>Bulk Download</b>: -b
Bulk can be used by text message and by replying to a text file containing links separated by a new line.
You can use it only by replying to a message(text/file).
Bulk can be used only by replying to text message or text file contains links separated by new line.
Example:
link1 -n new name -up remote1:path1 -rcf |key:value|key:value
link2 -z -n new name -up remote2:path2
link3 -e -n new name -up remote2:path2
Reply to this example by this cmd -> /cmd -b(bulk) or /cmd -b -sd folder name
You can set the start and end of the links from the bulk like seed, with -b start:end or only end by -b :end or only start by -b start.
The default start is from zero(first link) to infinity.
"""
Reply to this example by this cmd -> /cmd -b(bulk)
Note: Any arg along with the cmd will be setted to all links
/cmd -b -up remote: -z -sd folder name (all links contents in one zipped folder uploaded to one destination)
so you can't set different upload destinations along with link incase you have added -sd along with cmd
You can set start and end of the links from the bulk like seed, with -b start:end or only end by -b :end or only start by -b start.
The default start is from zero(first link) to inf."""

rlone_dl = """
<b>Rclone Download</b>:
Expand Down
15 changes: 14 additions & 1 deletion bot/helper/ext_utils/jdownloader_booter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aioshutil import rmtree
from json import dump
from random import randint
from asyncio import sleep
from asyncio import sleep, wait_for
from re import match

from bot import (
Expand All @@ -19,6 +19,7 @@
from .bot_utils import (
cmd_exec,
new_task,
retry_function
)
from myjd import MyJdApi
from myjd.exception import (
Expand Down Expand Up @@ -169,5 +170,17 @@ async def connectToDevice(self):
LOGGER.info("JDownloader is ready to use!")
return True

async def check_jdownloader_state(self):
try:
await wait_for(retry_function(self.device.jd.version), timeout=10)
except:
is_connected = await self.jdconnect()
if not is_connected:
raise MYJDException(self.error)
await self.boot()
isDeviceConnected = await self.connectToDevice()
if not isDeviceConnected:
raise MYJDException(self.error)


jdownloader = JDownloader()
48 changes: 31 additions & 17 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ async def convert_video(listener, video_file, ext, retry=False):
]
if listener.is_cancelled:
return False
listener.suproc = await create_subprocess_exec(
*cmd,
stderr=PIPE
)
_, stderr = await listener.suproc.communicate()
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(
*cmd,
stderr=PIPE
)
(
_,
stderr
) = await listener.suproc.communicate()
if listener.is_cancelled:
return False
code = listener.suproc.returncode
Expand Down Expand Up @@ -130,10 +134,11 @@ async def convert_audio(listener, audio_file, ext):
]
if listener.is_cancelled:
return False
listener.suproc = await create_subprocess_exec(
*cmd,
stderr=PIPE
)
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(
*cmd,
stderr=PIPE
)
(
_,
stderr
Expand Down Expand Up @@ -863,10 +868,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
)
async with subprocess_lock:
listener.suproc = await create_subprocess_exec(
*cmd,
stderr=PIPE
)
(
_,
stderr
Expand Down Expand Up @@ -897,7 +903,10 @@ async def edit_video_metadata(listener, dir):
data = listener.metadata
dir_path = Path(dir)

if not dir_path.lower().endswith(("mkv", "mp4")):
if not dir_path.suffix.lower().endswith((
"mkv",
"mp4"
)):
return dir

file_name = dir_path.name
Expand Down Expand Up @@ -1070,17 +1079,22 @@ async def add_attachment(listener, dir):
data = listener.m_attachment
dir_path = Path(dir)

if not dir_path.lower().endswith(("mkv", "mp4")):
if not dir_path.suffix.lower().endswith((
"mkv",
"mp4"
)):
return dir

file_name = dir_path.name
work_path = dir_path.with_suffix(".temp.mkv")

if data:
if is_telegram_link(data):
msg = (await get_tg_link_message(data))[0]
msg = (await get_tg_link_message(data))[0] # type: ignore
data = (
await create_thumb(msg) if msg.photo or msg.document else ""
await create_thumb(msg)
if msg.photo or msg.document # type: ignore
else ""
)

data_ext = data.split(".")[-1].lower()
Expand Down
Loading

0 comments on commit c13d146

Please sign in to comment.