The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
[Partner Nodes] feat: improve video references uploading for SeeDance 2 (#14098)
Alexander Piskun0cce76d40213
diff --git a/comfy_api_nodes/apis/bytedance.py b/comfy_api_nodes/apis/bytedance.pyindex 03f4c445b..47f24586c 100644--- a/comfy_api_nodes/apis/bytedance.py+++ b/comfy_api_nodes/apis/bytedance.py@@ -158,8 +158,9 @@ class SeedanceCreateAssetResponse(BaseModel):class SeedanceVirtualLibraryCreateAssetRequest(BaseModel):- url: str = Field(..., description="Publicly accessible URL of the image asset to upload.")+ url: str = Field(..., description="Publicly accessible URL of the asset to upload.")hash: str = Field(..., description="Dedup key. Re-submitting the same hash returns the existing asset id.")+ asset_type: str | None = Field(None, description="BytePlus asset type. Defaults to Image server-side when omitted.")# Dollars per 1K tokens, keyed by (model_id, has_video_input).diff --git a/comfy_api_nodes/nodes_bytedance.py b/comfy_api_nodes/nodes_bytedance.pyindex e08fc0b01..1b4abafe6 100644--- a/comfy_api_nodes/nodes_bytedance.py+++ b/comfy_api_nodes/nodes_bytedance.py@@ -2,11 +2,12 @@ import hashlibimport loggingimport mathimport re+from io import BytesIOimport torchfrom typing_extensions import override-from comfy_api.latest import IO, ComfyExtension, Input+from comfy_api.latest import IO, ComfyExtension, Input, Typesfrom comfy_api_nodes.apis.bytedance import (RECOMMENDED_PRESETS,RECOMMENDED_PRESETS_SEEDREAM_4,@@ -308,6 +309,26 @@ async def _seedance_virtual_library_upload_image_asset(return f"asset://{create_resp.asset_id}"+async def _seedance_virtual_library_upload_video_asset(+ cls: type[IO.ComfyNode],+ video: Input.Video,+ *,+ wait_label: str = "Uploading video",+) -> str:+ buf = BytesIO()+ video.save_to(buf, format=Types.VideoContainer.MP4, codec=Types.VideoCodec.H264)+ video_hash = hashlib.sha256(buf.getbuffer()).hexdigest()+ public_url = await upload_video_to_comfyapi(cls, video, wait_label=wait_label)+ create_resp = await sync_op(+ cls,+ ApiEndpoint(path="/proxy/seedance/virtual-library/assets", method="POST"),+ response_model=SeedanceCreateAssetResponse,+ data=SeedanceVirtualLibraryCreateAssetRequest(url=public_url, hash=video_hash, asset_type="Video"),+ )+ await _wait_for_asset_active(cls, create_resp.asset_id, group_id="virtual-library")+ return f"asset://{create_resp.asset_id}"++def _seedance2_price_extractor(model_id: str, has_video_input: bool):"""Returns a price_extractor closure for Seedance 2.0 poll_op."""rate = SEEDANCE2_PRICE_PER_1K_TOKENS.get((model_id, has_video_input))@@ -2106,7 +2127,7 @@ class ByteDance2ReferenceNode(IO.ComfyNode):content.append(TaskVideoContent(video_url=TaskVideoContentUrl(- url=await upload_video_to_comfyapi(+ url=await _seedance_virtual_library_upload_video_asset(cls,reference_videos[key],wait_label=f"Uploading video {i}",