Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions streamrip/client/qobuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,22 @@ async def _test_secret(self, secret: str) -> Optional[str]:
return None

async def _get_valid_secret(self, secrets: list[str]) -> str:
results = await asyncio.gather(
*[self._test_secret(secret) for secret in secrets],
)
working_secrets = [r for r in results if r is not None]
if len(working_secrets) == 0:
raise InvalidAppSecretError(secrets)

return working_secrets[0]
# ⚑ Bolt: Use asyncio.as_completed to return the first successful secret
# instead of waiting for all requests to finish. This short-circuits the
# process, reducing network I/O and tail latency.
pending = [asyncio.create_task(self._test_secret(secret)) for secret in secrets]

try:
for task in asyncio.as_completed(pending):
result = await task
if result is not None:
return result
finally:
for task in pending:
if not task.done():
task.cancel()

raise InvalidAppSecretError(secrets)

async def _request_file_url(
self,
Expand Down