Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit b800e1b

Browse files
rk-shajuDawn-India
authored andcommitted
Minor fix
Handel name_sub exceptions.
1 parent b3b089b commit b800e1b

File tree

10 files changed

+70
-30
lines changed

10 files changed

+70
-30
lines changed

bot/helper/common.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,16 +1753,24 @@ async def substitute(self, dl_path):
17531753
res = substitution[1]
17541754
else:
17551755
res = ""
1756-
name = sub(
1757-
rf"{pattern}",
1758-
res,
1759-
name,
1760-
flags=I
1761-
if sen
1762-
else 0
1763-
)
1756+
try:
1757+
name = sub(
1758+
rf"{pattern}",
1759+
res,
1760+
name,
1761+
flags=I
1762+
if sen
1763+
else 0
1764+
)
1765+
except Exception as e:
1766+
LOGGER.error(
1767+
f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}"
1768+
)
1769+
return dl_path
17641770
if len(name.encode()) > 255:
1765-
LOGGER.error(f"Substitute: {name} is too long")
1771+
LOGGER.error(
1772+
f"Substitute: {name} is too long"
1773+
)
17661774
return dl_path
17671775
new_path = ospath.join(
17681776
up_dir,
@@ -1801,16 +1809,24 @@ async def substitute(self, dl_path):
18011809
res = substitution[1]
18021810
else:
18031811
res = ""
1804-
file_ = sub(
1805-
rf"{pattern}",
1806-
res,
1807-
file_,
1808-
flags=I
1809-
if sen
1810-
else 0
1811-
)
1812+
try:
1813+
file_ = sub(
1814+
rf"{pattern}",
1815+
res,
1816+
file_,
1817+
flags=I
1818+
if sen
1819+
else 0
1820+
)
1821+
except Exception as e:
1822+
LOGGER.error(
1823+
f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}"
1824+
)
1825+
continue
18121826
if len(file_.encode()) > 255:
1813-
LOGGER.error(f"Substitute: {file_} is too long")
1827+
LOGGER.error(
1828+
f"Substitute: {file_} is too long"
1829+
)
18141830
continue
18151831
await move(
18161832
f_path,

bot/helper/ext_utils/db_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ async def trunc_table(self, name):
310310
async def add_download_url(self, url: str, tag: str):
311311
if self._return :
312312
return
313+
suffix = config_dict["CMD_SUFFIX"]
313314
download = {
314315
"_id": url,
315316
"tag": tag,
316-
"botname": bot_name
317+
"botname": bot_name,
318+
"suffix": suffix
317319
}
318320
await self._db.download_links.update_one( # type: ignore
319321
{"_id": url},

bot/helper/task_utils/download_utils/direct_downloader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ async def add_direct_download(listener, path):
6161
)
6262
return
6363

64-
gid = token_urlsafe(10)
64+
gid = token_urlsafe(10).replace(
65+
"-",
66+
""
67+
)
6568
(
6669
add_to_queue,
6770
event

bot/helper/task_utils/download_utils/gd_download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ async def add_gd_download(listener, path):
4242
return
4343

4444
listener.name = listener.name or name
45-
gid = token_urlsafe(12)
45+
gid = token_urlsafe(12).replace(
46+
"-",
47+
""
48+
)
4649

4750
(
4851
msg,

bot/helper/task_utils/download_utils/jd_download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ async def add_jd_download(listener, path):
194194
]:
195195
await jdownloader.device.linkgrabber.remove_links(package_ids=odl_list)
196196

197-
gid = token_urlsafe(12)
197+
gid = token_urlsafe(12).replace(
198+
"-",
199+
""
200+
)
198201
jd_downloads[gid] = {
199202
"status": "collect",
200203
"path": path

bot/helper/task_utils/download_utils/rclone_download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ async def add_rclone_download(listener, path):
131131
1
132132
)[-1]
133133
listener.size = rsize["bytes"]
134-
gid = token_urlsafe(12)
134+
gid = token_urlsafe(12).replace(
135+
"-",
136+
""
137+
)
135138

136139
if not rclone_select:
137140
(

bot/helper/task_utils/download_utils/telegram_download.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ async def _on_download_progress(self, current, total):
7373

7474
async def _on_download_error(self, error):
7575
async with global_lock:
76-
try:
76+
if self._id in GLOBAL_GID:
7777
GLOBAL_GID.remove(self._id)
78-
except:
79-
pass
8078
await self._listener.on_download_error(error)
8179

8280
async def _on_download_complete(self):
@@ -195,6 +193,9 @@ async def add_download(self, message, path, session):
195193
await send_status_message(self._listener.message)
196194
await event.wait() # type: ignore
197195
if self._listener.is_cancelled:
196+
async with global_lock:
197+
if self._id in GLOBAL_GID:
198+
GLOBAL_GID.remove(self._id)
198199
return
199200

200201
await self._on_download_start(gid, add_to_queue)

bot/helper/task_utils/download_utils/yt_dlp_download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ async def add_download(self, path, qual, playlist, options):
259259
self.opts["ignoreerrors"] = True
260260
self.is_playlist = True
261261

262-
self._gid = token_urlsafe(8)
262+
self._gid = token_urlsafe(8).replace(
263+
"-",
264+
""
265+
)
263266

264267
await self._on_download_start()
265268

bot/helper/z_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def stop_duplicate_tasks(message, link, file_=None):
9292
exist = await database.check_download(raw_url) # type: ignore
9393
if exist:
9494
_msg = f'<b>Download is already added by {exist["tag"]}</b>\n'
95-
_msg += f'Check the download status in @{exist["botname"]}\n\n'
95+
_msg += f'Check the download status in /status{exist["suffix"]}@{exist["botname"]}\n\n'
9696
_msg += f'<b>Link</b>: <code>{exist["_id"]}</code>'
9797
reply_message = await send_message(
9898
message,

bot/modules/clone.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ async def _proceed_to_clone(self, sync):
273273
await delete_links(self.message)
274274
else:
275275
msg = ""
276-
gid = token_urlsafe(12)
276+
gid = token_urlsafe(12).replace(
277+
"-",
278+
""
279+
)
277280
async with task_dict_lock:
278281
task_dict[self.mid] = GoogleDriveStatus(
279282
self,
@@ -385,7 +388,10 @@ async def _proceed_to_clone(self, sync):
385388
LOGGER.info(
386389
f"Clone Started: Name: {self.name} - Source: {self.link} - Destination: {self.up_dest}"
387390
)
388-
gid = token_urlsafe(12)
391+
gid = token_urlsafe(12).replace(
392+
"-",
393+
""
394+
)
389395
async with task_dict_lock:
390396
task_dict[self.mid] = RcloneStatus(
391397
self,

0 commit comments

Comments
 (0)