-
-
Notifications
You must be signed in to change notification settings - Fork 130
Prowlarr parallel requests and rank torrent name fix #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9dac1ca
7f2b65a
7fd7b8f
ac4c095
0018ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -77,16 +77,42 @@ async def process_torrent( | |||||||||||||||||||||||||||||||||||||||||||
| return torrents | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| async def fetch_prowlarr_results( | ||||||||||||||||||||||||||||||||||||||||||||
| session: aiohttp.ClientSession, indexer_id: int, query: str | ||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| Fetches results from a single Prowlarr indexer with a configured timeout. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| search_url = f"{settings.INDEXER_MANAGER_URL}/api/v1/search?query={query}&indexerIds={indexer_id}&type=search" | ||||||||||||||||||||||||||||||||||||||||||||
| response = await session.get( | ||||||||||||||||||||||||||||||||||||||||||||
| search_url, | ||||||||||||||||||||||||||||||||||||||||||||
| headers={"X-Api-Key": settings.INDEXER_MANAGER_API_KEY}, | ||||||||||||||||||||||||||||||||||||||||||||
| # This is the key change, mirroring the Jackett implementation | ||||||||||||||||||||||||||||||||||||||||||||
| timeout=aiohttp.ClientTimeout(total=settings.INDEXER_MANAGER_TIMEOUT), | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| response.raise_for_status() | ||||||||||||||||||||||||||||||||||||||||||||
| return await response.json() | ||||||||||||||||||||||||||||||||||||||||||||
| except asyncio.TimeoutError: | ||||||||||||||||||||||||||||||||||||||||||||
| logger.warning(f"Prowlarr search timed out for indexer ID {indexer_id}") | ||||||||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||||||||
| except aiohttp.ClientError as e: | ||||||||||||||||||||||||||||||||||||||||||||
| logger.warning(f"Prowlarr search failed for indexer ID {indexer_id}: {e}") | ||||||||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| async def get_prowlarr(manager, session: aiohttp.ClientSession, title: str, seen: set): | ||||||||||||||||||||||||||||||||||||||||||||
| torrents = [] | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| # Get all configured indexer IDs from Prowlarr | ||||||||||||||||||||||||||||||||||||||||||||
| indexers = [indexer.lower() for indexer in settings.INDEXER_MANAGER_INDEXERS] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| get_indexers = await session.get( | ||||||||||||||||||||||||||||||||||||||||||||
| get_indexers_response = await session.get( | ||||||||||||||||||||||||||||||||||||||||||||
| f"{settings.INDEXER_MANAGER_URL}/api/v1/indexer", | ||||||||||||||||||||||||||||||||||||||||||||
| headers={"X-Api-Key": settings.INDEXER_MANAGER_API_KEY}, | ||||||||||||||||||||||||||||||||||||||||||||
| timeout=aiohttp.ClientTimeout(total=settings.INDEXER_MANAGER_TIMEOUT), | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| get_indexers = await get_indexers.json() | ||||||||||||||||||||||||||||||||||||||||||||
| get_indexers = await get_indexers_response.json() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| indexers_id = [] | ||||||||||||||||||||||||||||||||||||||||||||
| for indexer in get_indexers: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,12 +122,17 @@ async def get_prowlarr(manager, session: aiohttp.ClientSession, title: str, seen | |||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||
| indexers_id.append(indexer["id"]) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| response = await session.get( | ||||||||||||||||||||||||||||||||||||||||||||
| f"{settings.INDEXER_MANAGER_URL}/api/v1/search?query={title}&indexerIds={'&indexerIds='.join(str(indexer_id) for indexer_id in indexers_id)}&type=search", | ||||||||||||||||||||||||||||||||||||||||||||
| headers={"X-Api-Key": settings.INDEXER_MANAGER_API_KEY}, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| response = await response.json() | ||||||||||||||||||||||||||||||||||||||||||||
| # Create a search task for each indexer ID | ||||||||||||||||||||||||||||||||||||||||||||
| tasks = [ | ||||||||||||||||||||||||||||||||||||||||||||
| fetch_prowlarr_results(session, indexer_id, title) | ||||||||||||||||||||||||||||||||||||||||||||
| for indexer_id in indexers_id | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| all_results_lists = await asyncio.gather(*tasks) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Flatten the list of lists into a single list of results | ||||||||||||||||||||||||||||||||||||||||||||
| response = [result for sublist in all_results_lists for result in sublist] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add Without Apply this diff: tasks = [
fetch_prowlarr_results(session, indexer_id, title)
for indexer_id in indexers_id
]
-all_results_lists = await asyncio.gather(*tasks)
+all_results_lists = await asyncio.gather(*tasks, return_exceptions=True)
# Flatten the list of lists into a single list of results
-response = [result for sublist in all_results_lists for result in sublist]
+response = [
+ result
+ for sublist in all_results_lists
+ if not isinstance(sublist, Exception)
+ for result in sublist
+]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| # Process the combined results | ||||||||||||||||||||||||||||||||||||||||||||
| torrent_tasks = [] | ||||||||||||||||||||||||||||||||||||||||||||
| for result in response: | ||||||||||||||||||||||||||||||||||||||||||||
| if result["infoUrl"] in seen: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add status check before parsing JSON response.
The code calls
json()without verifying the HTTP response status. If the indexer list fetch fails with a non-2xx status, this could raise an exception.Apply this diff to check the status:
get_indexers_response = await session.get( f"{settings.INDEXER_MANAGER_URL}/api/v1/indexer", headers={"X-Api-Key": settings.INDEXER_MANAGER_API_KEY}, timeout=aiohttp.ClientTimeout(total=settings.INDEXER_MANAGER_TIMEOUT), ) +get_indexers_response.raise_for_status() get_indexers = await get_indexers_response.json()📝 Committable suggestion
🤖 Prompt for AI Agents