@@ -26,9 +26,7 @@ def _url(self, endpoint: str) -> str:
2626 async def auth (self , retry = 3 ):
2727 times = 0
2828 timeout = httpx .Timeout (connect = 3.1 , read = 10.0 , write = 10.0 , pool = 10.0 )
29- self ._client = httpx .AsyncClient (
30- timeout = timeout , verify = self .ssl
31- )
29+ self ._client = httpx .AsyncClient (timeout = timeout , verify = self .ssl )
3230 while times < retry :
3331 try :
3432 resp = await self ._client .post (
@@ -61,8 +59,12 @@ async def logout(self):
6159 if self ._client :
6260 try :
6361 await self ._client .post (self ._url ("auth/logout" ))
64- except Exception :
65- pass
62+ except (
63+ httpx .ConnectError ,
64+ httpx .RequestError ,
65+ httpx .TimeoutException ,
66+ ) as e :
67+ logger .debug (f"[Downloader] Logout request failed (non-critical): { e } " )
6668 await self ._client .aclose ()
6769 self ._client = None
6870
@@ -114,7 +116,9 @@ async def torrents_files(self, torrent_hash: str):
114116 )
115117 return resp .json ()
116118
117- async def add_torrents (self , torrent_urls , torrent_files , save_path , category , tags = None ):
119+ async def add_torrents (
120+ self , torrent_urls , torrent_files , save_path , category , tags = None
121+ ):
118122 data = {
119123 "savepath" : save_path ,
120124 "category" : category ,
@@ -133,9 +137,17 @@ async def add_torrents(self, torrent_urls, torrent_files, save_path, category, t
133137 if torrent_files :
134138 if isinstance (torrent_files , list ):
135139 for i , f in enumerate (torrent_files ):
136- files [f"torrents_{ i } " ] = (f"torrent_{ i } .torrent" , f , "application/x-bittorrent" )
140+ files [f"torrents_{ i } " ] = (
141+ f"torrent_{ i } .torrent" ,
142+ f ,
143+ "application/x-bittorrent" ,
144+ )
137145 else :
138- files ["torrents" ] = ("torrent.torrent" , torrent_files , "application/x-bittorrent" )
146+ files ["torrents" ] = (
147+ "torrent.torrent" ,
148+ torrent_files ,
149+ "application/x-bittorrent" ,
150+ )
139151
140152 max_retries = 3
141153 for attempt in range (max_retries ):
@@ -153,14 +165,14 @@ async def add_torrents(self, torrent_urls, torrent_files, save_path, category, t
153165 )
154166 await asyncio .sleep (2 )
155167 else :
156- logger .error (f"[Downloader] Failed to add torrent after { max_retries } attempts: { e } " )
168+ logger .error (
169+ f"[Downloader] Failed to add torrent after { max_retries } attempts: { e } "
170+ )
157171 raise
158172
159173 async def get_torrents_by_tag (self , tag : str ) -> list [dict ]:
160174 """Get all torrents with a specific tag."""
161- resp = await self ._client .get (
162- self ._url ("torrents/info" ), params = {"tag" : tag }
163- )
175+ resp = await self ._client .get (self ._url ("torrents/info" ), params = {"tag" : tag })
164176 return resp .json ()
165177
166178 async def torrents_delete (self , hash , delete_files : bool = True ):
@@ -191,7 +203,8 @@ async def torrents_rename_file(self, torrent_hash, old_path, new_path) -> bool:
191203 logger .debug (f"Conflict409Error: { old_path } >> { new_path } " )
192204 return False
193205 return resp .status_code == 200
194- except Exception :
206+ except (httpx .ConnectError , httpx .RequestError , httpx .TimeoutException ) as e :
207+ logger .warning (f"[Downloader] Failed to rename file { old_path } : { e } " )
195208 return False
196209
197210 async def rss_add_feed (self , url , item_path ):
@@ -216,6 +229,7 @@ async def rss_get_feeds(self):
216229
217230 async def rss_set_rule (self , rule_name , rule_def ):
218231 import json
232+
219233 await self ._client .post (
220234 self ._url ("rss/setRule" ),
221235 data = {"ruleName" : rule_name , "ruleDef" : json .dumps (rule_def )},
0 commit comments