Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Handel name_sub exceptions.
  • Loading branch information
rk-shaju authored and Dawn-India committed Nov 29, 2024
1 parent b3b089b commit b800e1b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 30 deletions.
52 changes: 34 additions & 18 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,16 +1753,24 @@ async def substitute(self, dl_path):
res = substitution[1]
else:
res = ""
name = sub(
rf"{pattern}",
res,
name,
flags=I
if sen
else 0
)
try:
name = sub(
rf"{pattern}",
res,
name,
flags=I
if sen
else 0
)
except Exception as e:
LOGGER.error(
f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}"
)
return dl_path
if len(name.encode()) > 255:
LOGGER.error(f"Substitute: {name} is too long")
LOGGER.error(
f"Substitute: {name} is too long"
)
return dl_path
new_path = ospath.join(
up_dir,
Expand Down Expand Up @@ -1801,16 +1809,24 @@ async def substitute(self, dl_path):
res = substitution[1]
else:
res = ""
file_ = sub(
rf"{pattern}",
res,
file_,
flags=I
if sen
else 0
)
try:
file_ = sub(
rf"{pattern}",
res,
file_,
flags=I
if sen
else 0
)
except Exception as e:
LOGGER.error(
f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}"
)
continue
if len(file_.encode()) > 255:
LOGGER.error(f"Substitute: {file_} is too long")
LOGGER.error(
f"Substitute: {file_} is too long"
)
continue
await move(
f_path,
Expand Down
4 changes: 3 additions & 1 deletion bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ async def trunc_table(self, name):
async def add_download_url(self, url: str, tag: str):
if self._return :
return
suffix = config_dict["CMD_SUFFIX"]
download = {
"_id": url,
"tag": tag,
"botname": bot_name
"botname": bot_name,
"suffix": suffix
}
await self._db.download_links.update_one( # type: ignore
{"_id": url},
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 @@ -61,7 +61,10 @@ async def add_direct_download(listener, path):
)
return

gid = token_urlsafe(10)
gid = token_urlsafe(10).replace(
"-",
""
)
(
add_to_queue,
event
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/task_utils/download_utils/gd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ async def add_gd_download(listener, path):
return

listener.name = listener.name or name
gid = token_urlsafe(12)
gid = token_urlsafe(12).replace(
"-",
""
)

(
msg,
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/task_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ async def add_jd_download(listener, path):
]:
await jdownloader.device.linkgrabber.remove_links(package_ids=odl_list)

gid = token_urlsafe(12)
gid = token_urlsafe(12).replace(
"-",
""
)
jd_downloads[gid] = {
"status": "collect",
"path": path
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/task_utils/download_utils/rclone_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ async def add_rclone_download(listener, path):
1
)[-1]
listener.size = rsize["bytes"]
gid = token_urlsafe(12)
gid = token_urlsafe(12).replace(
"-",
""
)

if not rclone_select:
(
Expand Down
7 changes: 4 additions & 3 deletions bot/helper/task_utils/download_utils/telegram_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ async def _on_download_progress(self, current, total):

async def _on_download_error(self, error):
async with global_lock:
try:
if self._id in GLOBAL_GID:
GLOBAL_GID.remove(self._id)
except:
pass
await self._listener.on_download_error(error)

async def _on_download_complete(self):
Expand Down Expand Up @@ -195,6 +193,9 @@ async def add_download(self, message, path, session):
await send_status_message(self._listener.message)
await event.wait() # type: ignore
if self._listener.is_cancelled:
async with global_lock:
if self._id in GLOBAL_GID:
GLOBAL_GID.remove(self._id)
return

await self._on_download_start(gid, add_to_queue)
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/task_utils/download_utils/yt_dlp_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ async def add_download(self, path, qual, playlist, options):
self.opts["ignoreerrors"] = True
self.is_playlist = True

self._gid = token_urlsafe(8)
self._gid = token_urlsafe(8).replace(
"-",
""
)

await self._on_download_start()

Expand Down
2 changes: 1 addition & 1 deletion bot/helper/z_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def stop_duplicate_tasks(message, link, file_=None):
exist = await database.check_download(raw_url) # type: ignore
if exist:
_msg = f'<b>Download is already added by {exist["tag"]}</b>\n'
_msg += f'Check the download status in @{exist["botname"]}\n\n'
_msg += f'Check the download status in /status{exist["suffix"]}@{exist["botname"]}\n\n'
_msg += f'<b>Link</b>: <code>{exist["_id"]}</code>'
reply_message = await send_message(
message,
Expand Down
10 changes: 8 additions & 2 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ async def _proceed_to_clone(self, sync):
await delete_links(self.message)
else:
msg = ""
gid = token_urlsafe(12)
gid = token_urlsafe(12).replace(
"-",
""
)
async with task_dict_lock:
task_dict[self.mid] = GoogleDriveStatus(
self,
Expand Down Expand Up @@ -385,7 +388,10 @@ async def _proceed_to_clone(self, sync):
LOGGER.info(
f"Clone Started: Name: {self.name} - Source: {self.link} - Destination: {self.up_dest}"
)
gid = token_urlsafe(12)
gid = token_urlsafe(12).replace(
"-",
""
)
async with task_dict_lock:
task_dict[self.mid] = RcloneStatus(
self,
Expand Down

0 comments on commit b800e1b

Please sign in to comment.