@@ -47,8 +47,10 @@ def __init__(
4747 username : str = None ,
4848 password : str = None ,
4949 name : str = None ,
50+ timeout : int | None = None ,
5051 ):
5152 self .settings = settings
53+ self ._timeout = timeout
5254 if not base_url :
5355 logger .error ("Skipping qBittorrent client entry: 'base_url' is required." )
5456 error = "qBittorrent client must have a 'base_url'."
@@ -68,6 +70,13 @@ def __init__(
6870
6971 self ._remove_none_attributes ()
7072
73+ @property
74+ def timeout (self ):
75+ instance_timeout = getattr (self , "_timeout" , None )
76+ if instance_timeout is not None :
77+ return instance_timeout
78+ return getattr (getattr (self .settings , "general" , None ), "request_timeout" , 15 )
79+
7180 def _remove_none_attributes (self ):
7281 """Remove attributes that are None to keep the object clean."""
7382 for attr in list (vars (self )):
@@ -95,6 +104,7 @@ def _connection_error():
95104 "post" ,
96105 endpoint ,
97106 self .settings ,
107+ timeout = self .timeout ,
98108 data = data ,
99109 headers = headers ,
100110 ignore_test_run = True ,
@@ -133,6 +143,7 @@ async def fetch_version(self):
133143 "get" ,
134144 endpoint ,
135145 self .settings ,
146+ timeout = self .timeout ,
136147 cookies = self .cookie ,
137148 )
138149 self .version = response .text [1 :] # Remove the '_v' prefix
@@ -161,7 +172,7 @@ async def create_tag(self, tag: str):
161172 "_download_clients_qBit.py/create_tag: Checking if tag '{tag}' exists (and creating it if not)" ,
162173 )
163174 url = f"{ self .api_url } /torrents/tags"
164- response = await make_request ("get" , url , self .settings , cookies = self .cookie )
175+ response = await make_request ("get" , url , self .settings , timeout = self . timeout , cookies = self .cookie )
165176 current_tags = response .json ()
166177
167178 if tag not in current_tags :
@@ -171,6 +182,7 @@ async def create_tag(self, tag: str):
171182 "post" ,
172183 self .api_url + "/torrents/createTags" ,
173184 self .settings ,
185+ timeout = self .timeout ,
174186 data = data ,
175187 cookies = self .cookie ,
176188 )
@@ -196,6 +208,7 @@ async def set_unwanted_folder(self):
196208 "get" ,
197209 endpoint ,
198210 self .settings ,
211+ timeout = self .timeout ,
199212 cookies = self .cookie ,
200213 )
201214 qbit_settings = response .json ()
@@ -209,6 +222,7 @@ async def set_unwanted_folder(self):
209222 "post" ,
210223 self .api_url + "/app/setPreferences" ,
211224 self .settings ,
225+ timeout = self .timeout ,
212226 data = data ,
213227 cookies = self .cookie ,
214228 )
@@ -229,6 +243,7 @@ async def check_qbit_reachability(self):
229243 "post" ,
230244 endpoint ,
231245 self .settings ,
246+ timeout = self .timeout ,
232247 data = data ,
233248 headers = headers ,
234249 log_error = False ,
@@ -251,6 +266,7 @@ async def check_connected(self):
251266 "get" ,
252267 self .api_url + "/sync/maindata" ,
253268 self .settings ,
269+ timeout = self .timeout ,
254270 cookies = self .cookie ,
255271 )
256272 ).json ()
@@ -353,6 +369,7 @@ async def set_tag(self, tags, hashes):
353369 "post" ,
354370 self .api_url + "/torrents/addTags" ,
355371 self .settings ,
372+ timeout = self .timeout ,
356373 data = data ,
357374 cookies = self .cookie ,
358375 )
@@ -376,6 +393,7 @@ async def get_qbit_items(self, hashes: list[str] | str | None = None) -> list[di
376393 method = "get" ,
377394 endpoint = f"{ self .api_url } /torrents/info" ,
378395 settings = self .settings ,
396+ timeout = self .timeout ,
379397 params = None , # Retrieve all torrents
380398 cookies = self .cookie ,
381399 )
@@ -395,12 +413,13 @@ async def get_qbit_items(self, hashes: list[str] | str | None = None) -> list[di
395413 async def get_torrent_properties (self , qbit_hash ):
396414 params = {"hash" : qbit_hash .lower ()}
397415 response = await make_request (
398- "get" ,
399- self .api_url + "/torrents/properties" ,
400- self .settings ,
401- params = params ,
402- cookies = self .cookie ,
403- )
416+ "get" ,
417+ self .api_url + "/torrents/properties" ,
418+ self .settings ,
419+ timeout = self .timeout ,
420+ params = params ,
421+ cookies = self .cookie ,
422+ )
404423 return response .json ()
405424
406425
@@ -411,6 +430,7 @@ async def get_torrent_files(self, download_id):
411430 method = "get" ,
412431 endpoint = self .api_url + "/torrents/files" ,
413432 settings = self .settings ,
433+ timeout = self .timeout ,
414434 params = {"hash" : download_id .lower ()},
415435 cookies = self .cookie ,
416436 )
@@ -429,6 +449,7 @@ async def set_torrent_file_priority(self, download_id, file_id, priority=0):
429449 "post" ,
430450 self .api_url + "/torrents/filePrio" ,
431451 self .settings ,
452+ timeout = self .timeout ,
432453 data = data ,
433454 cookies = self .cookie ,
434455 )
@@ -440,6 +461,7 @@ async def set_bandwidth_usage(self):
440461 method = "get" ,
441462 endpoint = self .api_url + "/transfer/info" ,
442463 settings = self .settings ,
464+ timeout = self .timeout ,
443465 cookies = self .cookie ,
444466 )
445467 records = extract_json_from_response (response )
@@ -476,6 +498,7 @@ async def remove_download(self, download_hash: str, delete_files: bool = True):
476498 "post" ,
477499 f"{ self .api_url } /torrents/delete" ,
478500 self .settings ,
501+ timeout = self .timeout ,
479502 data = data ,
480503 cookies = self .cookie ,
481504 )
0 commit comments