Skip to content

Commit d3ed0f9

Browse files
committed
Fix of Request-URI Too Large
1 parent e8b566c commit d3ed0f9

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/settings/_download_clients_qbit.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,36 @@ async def fetch_download_progress(self, download_id):
342342
items = await self.get_qbit_items(download_id)
343343
return items[0]["completed"]
344344

345-
async def get_qbit_items(self, hashes=None):
346-
params = None
347-
if hashes:
348-
if isinstance(hashes, str):
349-
hashes = [hashes]
350-
params = {"hashes": "|".join(hashes).lower()} # Join and make lowercase
345+
async def get_qbit_items(self, hashes: list[str] | str | None = None) -> list[dict]:
346+
"""
347+
Fetch all torrents from qBittorrent and optionally filter by given hashes.
348+
Note: Filtration now on decluttarr side, as passing of hashes into qbit call may cause error (too long request URI)
349+
350+
Args:
351+
hashes: Optional single hash (str) or list of hashes to filter results.
351352
353+
Returns:
354+
List of torrent dicts, filtered if hashes provided.
355+
"""
352356
response = await make_request(
353357
method="get",
354-
endpoint=self.api_url + "/torrents/info",
358+
endpoint=f"{self.api_url}/torrents/info",
355359
settings=self.settings,
356-
params=params,
360+
params=None, # Retrieve all torrents
357361
cookies=self.cookie,
358362
)
359-
return response.json()
363+
364+
all_items = response.json()
365+
366+
if not hashes:
367+
return all_items
368+
369+
# Ensure hashes is a list and create a set for O(1) lookup
370+
if isinstance(hashes, str):
371+
hashes = [hashes]
372+
hashes_set = {h.lower() for h in hashes}
373+
374+
return [item for item in all_items if item["hash"].lower() in hashes_set]
360375

361376
async def get_torrent_properties(self, qbit_hash):
362377
params = {"hash": qbit_hash.lower()}

0 commit comments

Comments
 (0)