Skip to content

Commit 4b8b14d

Browse files
committed
minor changes
Signed-off-by: anasty17 <[email protected]>
1 parent 4f6ea87 commit 4b8b14d

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

bot/helper/listeners/aria2_listener.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from contextlib import suppress
22
from aiofiles.os import remove, path as aiopath
3-
from asyncio import sleep
3+
from asyncio import sleep, TimeoutError
44
from time import time
5-
from aioaria2.exceptions import Aria2rpcException
65
from aiohttp.client_exceptions import ClientError
76

87
from ... import task_dict_lock, task_dict, LOGGER, intervals
@@ -62,7 +61,7 @@ async def _on_download_complete(api, data):
6261
gid = data["params"][0]["gid"]
6362
download = await api.tellStatus(gid)
6463
options = await api.getOption(gid)
65-
except (Aria2rpcException, ClientError) as e:
64+
except (TimeoutError, ClientError) as e:
6665
LOGGER.error(f"onDownloadComplete: {e}")
6766
return
6867
if options.get("follow-torrent", "") == "false":
@@ -120,14 +119,14 @@ async def _on_bt_download_complete(api, data):
120119
if task.listener.seed:
121120
try:
122121
await api.changeOption(gid, {"max-upload-limit": "0"})
123-
except (Aria2rpcException, ClientError) as e:
122+
except (TimeoutError, ClientError) as e:
124123
LOGGER.error(
125124
f"{e} You are not able to seed because you added global option seed-time=0 without adding specific seed_time for this torrent GID: {gid}"
126125
)
127126
else:
128127
try:
129128
await api.forcePause(gid)
130-
except (Aria2rpcException, ClientError) as e:
129+
except (TimeoutError, ClientError) as e:
131130
LOGGER.error(f"onBtDownloadComplete: {e} GID: {gid}")
132131
await task.listener.on_download_complete()
133132
if intervals["stopAll"]:
@@ -174,7 +173,7 @@ async def _on_download_error(api, data):
174173
await sleep(1)
175174
LOGGER.info(f"onDownloadError: {gid}")
176175
error = "None"
177-
with suppress(Aria2rpcException, ClientError):
176+
with suppress(TimeoutError, ClientError):
178177
download = await api.tellStatus(gid)
179178
options = await api.getOption(gid)
180179
error = download.get("errorMessage", "")

bot/helper/listeners/direct_listener.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from asyncio import sleep
2-
from aioaria2.exceptions import Aria2rpcException
1+
from asyncio import sleep, TimeoutError
32
from aiohttp.client_exceptions import ClientError
43

54
from ... import LOGGER
@@ -41,7 +40,7 @@ async def download(self, contents):
4140
gid = await TorrentManager.aria2.addUri(
4241
uris=[content["url"]], options=self._a2c_opt, position=0
4342
)
44-
except (Aria2rpcException, ClientError) as e:
43+
except (TimeoutError, ClientError) as e:
4544
self._failed += 1
4645
LOGGER.error(f"Unable to download {filename} due to: {e}")
4746
continue

bot/helper/listeners/qbit_listener.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from aiofiles.os import remove, path as aiopath
2-
from asyncio import sleep
2+
from asyncio import sleep, TimeoutError
33
from time import time
4-
from aioqbt.exc import APIError
4+
from aiohttp.client_exceptions import ClientError
55

66
from ... import (
77
task_dict,
@@ -184,7 +184,7 @@ async def _qb_listener():
184184
qb_torrents[tag]["seeding"] = False
185185
await _on_seed_finish(tor_info)
186186
await sleep(0.5)
187-
except APIError as e:
187+
except (ClientError, TimeoutError) as e:
188188
LOGGER.error(str(e))
189189
await sleep(3)
190190

bot/helper/mirror_leech_utils/download_utils/aria2_download.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from aiofiles.os import remove, path as aiopath
22
from aiofiles import open as aiopen
33
from base64 import b64encode
4-
from aioaria2.exceptions import Aria2rpcException
54
from aiohttp.client_exceptions import ClientError
5+
from asyncio import TimeoutError
66

77
from .... import task_dict_lock, task_dict, LOGGER
88
from ....core.config_manager import Config
@@ -45,7 +45,7 @@ async def add_aria2_download(listener, dpath, header, ratio, seed_time):
4545
gid = await TorrentManager.aria2.addUri(
4646
uris=[listener.link], options=a2c_opt
4747
)
48-
except (Aria2rpcException, ClientError) as e:
48+
except (TimeoutError, ClientError) as e:
4949
LOGGER.info(f"Aria2c Download Error: {e}")
5050
await listener.on_download_error(f"{e}")
5151
return

bot/helper/mirror_leech_utils/download_utils/qbit_download.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from aiofiles.os import remove, path as aiopath
22
from aiofiles import open as aiopen
3-
from asyncio import sleep
3+
from asyncio import sleep, TimeoutError
44
from aioqbt.api import AddFormBuilder
5-
from aioqbt.exc import APIError
5+
from aiohttp.client_exceptions import ClientError
66

77
from .... import (
88
task_dict,
@@ -60,7 +60,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
6060
form = form.seeding_time_limit(int(seed_time))
6161
try:
6262
await TorrentManager.qbittorrent.torrents.add(form.build())
63-
except APIError as e:
63+
except (ClientError, TimeoutError) as e:
6464
LOGGER.error(
6565
f"{e}. {listener.mid}. Already added torrent or unsupported link/file type!"
6666
)
@@ -139,7 +139,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
139139
)
140140
await on_download_start(f"{listener.mid}")
141141
await TorrentManager.qbittorrent.torrents.start([ext_hash])
142-
except APIError as e:
142+
except (ClientError, TimeoutError) as e:
143143
if f"{listener.mid}" in qb_torrents:
144144
del qb_torrents[f"{listener.mid}"]
145145
await listener.on_download_error(f"{e}")

web/wserver.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ async def re_verify(paused, resumed, hash_id):
7171
await qbittorrent.torrents.file_prio(
7272
hash=hash_id, id=paused, priority=0
7373
)
74-
except ClientError as e:
74+
except (ClientError, TimeoutError) as e:
7575
LOGGER.error(f"{e} Errored in reverification paused!")
7676
if resumed:
7777
try:
7878
await qbittorrent.torrents.file_prio(
7979
hash=hash_id, id=resumed, priority=1
8080
)
81-
except ClientError as e:
81+
except (ClientError, TimeoutError) as e:
8282
LOGGER.error(f"{e} Errored in reverification resumed!")
8383
k += 1
8484
if k > 5:
@@ -184,7 +184,7 @@ async def handle_torrent(request: Request):
184184
op = await aria2.getOption(gid)
185185
fpath = f"{op['dir']}/"
186186
content = make_tree(res, "aria2", fpath)
187-
except (Exception, ClientError) as e:
187+
except (ClientError, TimeoutError) as e:
188188
LOGGER.error(str(e))
189189
content = {
190190
"files": [],
@@ -203,7 +203,7 @@ async def handle_rename(gid, data):
203203
await qbittorrent.torrents.rename_file(hash=gid, **data)
204204
else:
205205
await qbittorrent.torrents.rename_folder(hash=gid, **data)
206-
except ClientError as e:
206+
except (ClientError, TimeoutError) as e:
207207
LOGGER.error(f"{e} Errored in renaming")
208208

209209

@@ -218,14 +218,14 @@ async def set_qbittorrent(gid, selected_files, unselected_files):
218218
await qbittorrent.torrents.file_prio(
219219
hash=gid, id=unselected_files, priority=0
220220
)
221-
except ClientError as e:
221+
except (ClientError, TimeoutError) as e:
222222
LOGGER.error(f"{e} Errored in paused")
223223
if selected_files:
224224
try:
225225
await qbittorrent.torrents.file_prio(
226226
hash=gid, id=selected_files, priority=1
227227
)
228-
except ClientError as e:
228+
except (ClientError, TimeoutError) as e:
229229
LOGGER.error(f"{e} Errored in resumed")
230230
await sleep(0.5)
231231
if not await re_verify(unselected_files, selected_files, gid):

0 commit comments

Comments
 (0)