Add Cloud audio result download helper

Amp-Thread-ID: https://ampcode.com/threads/T-019fd01c-5e2c-77a8-b7c0-dd523218716f
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Hunter Senft-Grupp
2026-08-05 04:14:10 +00:00
parent afb8cbbe3e
commit 93b47ed9fb
3 changed files with 84 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ from .conversions import (
)
from .download_helpers import (
download_url_as_bytesio,
download_url_to_audio_input,
download_url_to_bytesio,
download_url_to_file_3d,
download_url_to_image_tensor,
@@ -76,6 +77,7 @@ __all__ = [
"upload_video_to_comfyapi",
# Download helpers
"download_url_as_bytesio",
"download_url_to_audio_input",
"download_url_to_bytesio",
"download_url_to_file_3d",
"download_url_to_image_tensor",

View File

@@ -11,7 +11,7 @@ import torch
from aiohttp.client_exceptions import ClientError, ContentTypeError
from comfy_api.latest import IO as COMFY_IO
from comfy_api.latest import InputImpl, Types
from comfy_api.latest import Input, InputImpl, Types
from folder_paths import get_output_directory
from . import request_logger
@@ -24,7 +24,7 @@ from ._helpers import (
)
from .client import _diagnose_connectivity
from .common_exceptions import ApiServerError, LocalNetworkError, ProcessingInterrupted
from .conversions import bytesio_to_image_tensor
from .conversions import audio_bytes_to_audio_input, bytesio_to_image_tensor
_RETRY_STATUS = {408, 429, 500, 502, 503, 504}
@@ -241,6 +241,19 @@ async def download_url_to_video_output(
return InputImpl.VideoFromFile(result)
async def download_url_to_audio_input(
audio_url: str,
*,
timeout: float = None,
max_retries: int = 5,
cls: type[COMFY_IO.ComfyNode] = None,
) -> Input.Audio:
"""Downloads audio from a URL and decodes it into a Comfy AUDIO input."""
result = BytesIO()
await download_url_to_bytesio(audio_url, result, timeout=timeout, max_retries=max_retries, cls=cls)
return audio_bytes_to_audio_input(result.getvalue())
async def download_url_as_bytesio(
url: str,
*,