
    +j{                    r   S SK r S SKrS SKrS SKrS SKJr  S SKrS SKJr  S SK	J
r
  S SKJrJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  S SK/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrB  S SKCJDrD  S	rES
rFSrGSSSS.rH\\\S.rISrJSrKSrLSSS.rMSS1rN\R                  " \P5      rQS\R                  S\SS\SS\TSS4
S jrUS\R                  S\R                  4S jrWS S!S"S#S$S%S&.rXS'S(S)S*.rYS\SS+\SS\R                  S\[\T\T4   4S, jr\S\R                  S-\TS.\TS\R                  4S/ jr]S0\^\R                     S1\`\S   S\[\a\S\S4   \a\S\S4   \a\S\S4   4   4S2 jrb\R                  " S3\R                  5      reS4\a\S\S4   S5\a\S\S4   S6\a\S\S4   S7\a\S\S4   S8\TS9\TS:\TS\a\T\S4   4S; jrfS<\SS=\a\T\S4   S\S4S> jrgS0\^\R                     S\S4S? jrhS0\^\R                     S@\SS\S4SA jriS0\^\R                     S@\SSB\SSC\SSD\SS\S4SE jrjS0\^\R                     SF\SS@\SS\4SG jrkSHSI.S0\^\R                     S\R                  SJ\SS\S4SK jjrlSLSI.S0\^\R                     S\R                  SJ\SS\S4SM jjrmS\SSN\n4SO jroSP\S\S4SQ jrp " SR SS\R                  5      rq " ST SU\R                  5      rrSV\TSW\`4SX jrs " SY SZ\R                  5      rt " S[ S\\R                  5      ru " S] S^\R                  5      rv " S_ S`\R                  5      rw " Sa Sb\R                  5      rxS<\SSc\`\S   SS4Sd jry\R                  " \R                  " / SeQSf9SgSh9r|S}Si\`\S   Sj\S4Sk jjr} " Sl Sm\R                  5      r~ " Sn So\R                  5      rS}Si\`\S   Sj\S4Sp jjr " Sq Sr\R                  5      rS0\^\R                     Ss\.\-  St\TS-  S\GR                  4Su jr " Sv Sw\R                  5      r " Sx Sy\R                  5      r " Sz S{\5      rS\4S| jrg)~    N)BytesIO)override)common_upscale)IOComfyExtensionInputTypes)RECOMMENDED_PRESETSRECOMMENDED_PRESETS_SEEDREAM_4 RECOMMENDED_PRESETS_SEEDREAM_4_0 RECOMMENDED_PRESETS_SEEDREAM_4_5#RECOMMENDED_PRESETS_SEEDREAM_5_LITESEEDANCE2_PRICE_PER_1K_TOKENS SEEDANCE2_REF_VIDEO_PIXEL_LIMITSVIDEO_TASKS_EXECUTION_TIMEGetAssetResponseImage2VideoTaskCreationRequestImageTaskCreationResponseSeedance2TaskCreationRequestSeedanceCreateAssetRequestSeedanceCreateAssetResponse+SeedanceCreateVisualValidateSessionResponse(SeedanceGetVisualValidateSessionResponse(SeedanceVirtualLibraryCreateAssetRequestSeedream4OptionsSeedream4TaskCreationRequestTaskAudioContentTaskAudioContentUrlTaskCreationResponseTaskImageContentTaskImageContentUrlTaskStatusResponseTaskTextContentTaskVideoContentTaskVideoContentUrlText2ImageTaskCreationRequestText2VideoTaskCreationRequest)ApiEndpointdownload_url_to_image_tensordownload_url_to_video_output"downscale_image_tensor_by_max_sidedownscale_video_to_max_pixelsget_number_of_imagesimage_tensor_pair_to_batchpoll_opsync_opupload_audio_to_comfyapiupload_image_to_comfyapiupload_images_to_comfyapiupload_video_to_comfyapiupscale_video_to_min_pixelsvalidate_image_aspect_ratiovalidate_image_dimensionsvalidate_stringvalidate_video_dimensionsvalidate_video_duration)PromptServerz)/proxy/byteplus/api/v3/images/generationsx      seedream-5-0-260128seedream-4-5-251128seedream-4-0-250828)seedream 5.0 liter?   r@   )r>   r?   r@   z1/proxy/byteplus/api/v3/contents/generations/tasksz;/proxy/byteplus-seedance2/api/v3/contents/generations/taskszdreamina-seedance-2-0-260128z!dreamina-seedance-2-0-fast-260128)Seedance 2.0Seedance 2.0 Fastseedance-1-0-lite-t2v-250428seedance-1-0-lite-i2v-250428videomodel_id
resolutionindexreturnc                    [         R                  " U5      nU(       d  gUR                  U5      nU(       d  g U R                  5       u  pgXg-  nUR                  S5      n	UR                  S5      n
U	(       a"  X:  a  [	        SU SU SU SUS S	U	S S
35      eU
(       a#  X:  a  [	        SU SU SU SUS SU
S S35      egg! [         a     gf = f)zcValidate reference video pixel count against Seedance 2.0 model limits for the selected resolution.NminmaxReference video z is too small: xz = ,z) total pixels. Minimum for this model is z total pixels.z is too large: z) total pixels. Maximum for this model is z) total pixels. Try downscaling the video.)r   getget_dimensions	Exception
ValueError)rF   rG   rH   rI   model_limitslimitswhpixelsmin_pxmax_pxs              ?/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_bytedance.py_validate_ref_video_pixelsr]   d   s   377ALj)F##% UFZZFZZF&/ug_QCq3vaj I))/
.B
 	
 &/ug_QCq3vaj I))/
2[]
 	
 "v  s   C 
CCimagec                 L    [        U SSSS9  [        U SS9n [        U SSSSS9  U $ )	zOAuto-downscale a Seedance image input to the per-side limits, then validate it.      rb   ra   Fstrictp  )max_side,  	min_width
min_height	max_width
max_height)r6   r+   r7   )r^   s    r\   _prepare_seedance_imagern      s2    vveD.utDEessd_cdL    )   	   )   r=   )   rs   )r=   rr   )rq   rp   )   rq   16:94:31:13:49:1621:9i  i  i8  480p720p1080pratioc                   ^ [         U    nU[        ;  a1  UR                  S   UR                  S   -  m[        [        U4S jS9n[        U   u  pEXE:  a  [	        X4-  U-  5      UpvOU[	        X5-  U-  5      pvXfS-  -
  XwS-  -
  4$ )aE  Exact supported output (width, height) for (resolution, ratio).

The shorter side equals the resolution number (e.g. 1080p 16:9 -> 1920x1080). For ratio
"adaptive" (or any unexpected value) the ratio is derived from the image's own aspect, snapped
to the nearest supported ratio, so the output keeps the frame's orientation.
c                 N   > [        [        U    S   [        U    S   -  T-
  5      $ )Nr   rs   )absSEEDANCE2_RATIO_WH)kaspects    r\   <lambda>(_seedance2_target_dims.<locals>.<lambda>   s.    c:LQ:OPQ:RUghiUjklUm:mpv:v6wro   )keyra   )SEEDANCE2_RES_SHORT_SIDEr   shaperL   round)	rH   r   r^   shortrwrhout_wout_hr   s	           @r\   _seedance2_target_dimsr      s     %Z0E&&R5;;r?2&,wx&FB	xUZ"_-uueEJO4u19eai///ro   widthheightc                 f    U R                  SS5      n[        X1USS5      nUR                  SS5      $ )zPCenter-crop to the target aspect and resize to exactly width x height (lanczos).rs   lanczoscenter)movedimr   )r^   r   r   samplesresizeds        r\   _resize_to_exactr      s3    mmB"GWVYIG??1b!!ro   cls	asset_idsc                 N  #    0 n0 n0 n[        US5       GH  u  pVU=(       d    SR                  5       nU(       d  M(  [        U [        SU 3S9[        S9I Sh  vN nUR
                  S:w  ad  UR                  (       a0  SUR                  R                   S	UR                  R                   3OSn	[        S
U SU SUR
                   SU	 35      eSU 3n
UR                  S:X  a  XU'   M  UR                  S:X  a  XU'   M  UR                  S:X  d  GM  XU'   GM     X#U4$  N7f)zLook up each asset, validate Active status, group by asset_type.

Returns (image_assets, video_assets, audio_assets), each mapping asset_id -> "asset://<asset_id>".
rs    /proxy/seedance/assets/pathresponse_modelNActive z: zReference asset z (Id=z) is not Active (Status=).asset://ImageVideoAudio)	enumeratestripr0   r(   r   statuserrorcodemessagerT   
asset_type)r   r   image_assetsvideo_assetsaudio_assetsiraw_idasset_idresultextra	asset_uris              r\   _resolve_reference_assetsr      s6     $&L#%L#%Ly!,	Lb'')6xjAB+
 

 ==H$GM||a))*"V\\-A-A,BCY[E/s%zAYZ`ZgZgYhhjkpjqrssxj)	'%."')%."')%."% -& |33
s   AD%D#B7D%D%z\basset ?(\d{1,2})\breference_assetsimage_asset_urisvideo_asset_urisaudio_asset_urisn_reference_imagesn_reference_videosn_reference_audiosc                 ^   UnUnUn	0 n
U R                  5        H  u  pU=(       d    SR                  5       nU(       d  M'   [        UR                  SS5      S   5      nX;   a  US-  nSU 3X'   MY  X;   a  US-  nSU 3X'   Ml  X;   d  Ms  U	S-  n	SU	 3X'   M     U
$ ! [         a     M  f = f)a5  Map asset slot number (from 'asset_N' keys) to its positional label.

Asset entries are appended to `content` after the reference_images/videos/audios,
so their 1-indexed labels continue from the count of existing same-type refs:
one reference_images entry + one Image-type asset -> asset labelled "Image 2".
r   _rs   r   zImage zVideo zAudio )itemsr   intrsplitrT   )r   r   r   r   r   r   r   image_nvideo_naudio_nlabelsslot_keyr   r   slot_nums                  r\   _build_asset_labelsr      s     !G G GF,224Lb'')	8??32267H 'qLG!'y1F)qLG!'y1F)qLG!'y1F! 5" M  		s   B
B,+B,promptr   c                 `   ^ T(       d  U $ SSS[         4U4S jjn[        R                  X 5      $ )zJCase-insensitively replace 'assetNN' (1-2 digit) tokens with their labels.mzre.Match[str]rJ   c                 v   > TR                  [        U R                  S5      5      U R                  S5      5      $ )Nrs   r   )rQ   r   group)r   r   s    r\   _sub!_rewrite_asset_refs.<locals>._sub   s(    zz#aggaj/1771:66ro   )str_ASSET_REF_REsub)r   r   r   s    ` r\   _rewrite_asset_refsr      s1    7 7C 7 T**ro   c                 z  #    [        U [        SSS9[        S9I S h  vN n[        R	                  SUR
                  5        SUR
                   3n[        U [        SUR                   3S9[        S	 S
/S/[        [        [        -  S-
  [        S-
  US9
I S h  vN nUR                  (       d  [        SUR                   S35      e[        R	                  SUR                  5        [        R                  R                  SUR                   3U R                   R"                  5        UR                  $  GN N7f)Nz(/proxy/seedance/visual-validate/sessionsPOSTr   methodr   z/Seedance authentication required. Open link: %sz@Open this link in your browser and complete face verification:

z)/proxy/seedance/visual-validate/sessions/r   c                     U R                   $ Nr   rs    r\   r   ._obtain_group_id_via_h5_auth.<locals>.<lambda>      188ro   	completedfailedrs   )r   status_extractorcompleted_statusesfailed_statusespoll_intervalmax_poll_attemptsestimated_duration
extra_textzSeedance session z completed without a group_idz1Seedance authentication complete. New GroupId: %sz&Authentication complete. New GroupId: )r0   r(   r   loggerwarningh5_linkr/   
session_idr   _VERIFICATION_POLL_INTERVAL_SEC_VERIFICATION_POLL_TIMEOUT_SECgroup_idRuntimeErrorr;   instancesend_progress_texthidden	unique_id)r   sessionh5_textr   s       r\   _obtain_group_id_via_h5_authr     s"    CFSB G
 NNDgooVRSZSbSbRcdGDWEWEWDXYZ?+'=!
59=\\`aa9A= F ??.w/A/A.BB_`aa
NNFX,,
00ABCJJDXDX ??;s#   D;D6A<D;D9BD;9D;r   c                    #    U(       a%  UR                  5       (       a  UR                  5       $ [        U 5      I S h  vN $  N7fr   )r   r   )r   r   s     r\   _resolve_group_idr  $  s2     HNN$$~~-c2222s   ;AAAurlnamer   c                   #    [        UUUU=(       d    S S9n[        U [        SSS9[        US9I S h  vN nUR                  $  N7f)N)r   r  r   r  z/proxy/seedance/assetsr   r   r   data)r   r0   r(   r   r   )r   r   r  r  r   reqr   s          r\   _create_seedance_assetr	  *  sW      %\T	C 1&A2	 F ??s   1AAAr   c                 n   #    [        U [        SU 3S9[        S S/S/SSSU S	U 3S
9	I Sh  vN $  N7f)z=Poll the newly created asset until its status becomes Active.r   r   c                     U R                   $ r   r   r   s    r\   r   (_wait_for_asset_active.<locals>.<lambda>G  r   ro   r   Failedrb   i  z/Waiting for asset pre-processing...

asset_id: 

group_id: )r   r   r   r   r   r   r   N)r/   r(   r   )r   r   r   s      r\   _wait_for_asset_activer  A  sX     28*=>'+$:!
FxjP^_g^hi
 
 
 
s   ,535zUploading image
wait_labelr  c          
        #    [        XUS9I Sh  vN nUR                  5       R                  5       R                  5       R	                  [
        R                  5      n[        R                  " 5       nUR                  [        [        UR                  5      5      R                  S5      5        UR                  S5        UR                  UR                  5       R                  5       5        UR!                  5       n[#        U [%        SSS9[&        [)        X6S9S	9I Sh  vN n[+        XR,                  S
S9I Sh  vN   SUR,                   3$  GN? N2 N7f)zHUpload an image into the caller's per-customer Seedance virtual library.r  Nzutf-8    &/proxy/seedance/virtual-library/assetsr   r   )r  hashr  virtual-libraryr   r   )r2   detachcpu
contiguoustotorchfloat32hashlibsha256updater   tupler   encodenumpytobytes	hexdigestr0   r(   r   r   r  r   )r   r^   r  
public_url
normalizeddigest
image_hashcreate_resps           r\   ,_seedance_virtual_library_upload_image_assetr+  P  s     0zRRJ##%00255emmDJ^^F
MM#eJ,,-.55g>?
MM%
MM*""$,,./!!#JA&Q25*V	 K !&:&:EV
WWWk**+,, S Xs4   EEDEE E;E<EEEzUploading videoc                  #    [        5       nUR                  U[        R                  R                  [        R
                  R                  S9  [        R                  " UR                  5       5      R                  5       n[        XUS9I S h  vN n[        U [        SSS9[        [        XTSS9S9I S h  vN n[!        XR"                  S	S
9I S h  vN   SUR"                   3$  NW N1 N7f)N)formatcodecr  r  r   r   r   )r  r  r   r  r  r  r   )r   save_tor	   VideoContainerMP4
VideoCodecH264r  r  	getbufferr%  r4   r0   r(   r   r   r  r   )r   rF   r  buf
video_hashr&  r*  s          r\   ,_seedance_virtual_library_upload_video_assetr7  h  s      )C	MM#e2266e>N>N>S>SMT0::<J/zRRJA&Q25*bij	 K !&:&:EV
WWWk**+,, S Xs6   BC+C%'C+5C'6C+C)C+'C+)C+has_video_inputc                 l   ^ [         R                  " X45      mTc  gS[        S[        S-  4U4S jjnU$ )z;Returns a price_extractor closure for Seedance 2.0 poll_op.NresponserJ   c                 ^   > U R                   c  g U R                   R                  S-  T-  S-  $ )NgzG?g     @@)usagetotal_tokens)r:  rates    r\   	extractor-_seedance2_price_extractor.<locals>.extractor  s/    >>!~~**T1D87BBro   )r   rQ   r"   float)rG   r8  r?  r>  s      @r\   _seedance2_price_extractorrB  |  sA    (,,h-HID|C. C54< C
 ro   r:  c                    U R                   (       aC  SU R                   S    SU R                   S    3n[        R                  " U5        [        U5      e[        R                  " SU R                  S   S   5        U R                  S   S   $ )Nz ByteDance request failed. Code: r   z, message: r   z'ByteDance task succeeded, image URL: %sr   r  )r   logginginfor   r  )r:  	error_msgs     r\   get_image_url_from_responserG    s{    ~~6x~~f7M6NkZbZhZhirZsYtu	Y9%%LL:HMM!<LU<ST==E""ro   c                   p    \ rS rSr\S 5       r\S\S\S\S\S\S\S	\S
\	S\
R                  4S j5       rSrg)ByteDanceImageNodei  c                    [         R                  " SSSS[         R                  R                  SS/S9[         R                  R                  SS	S
S9[         R                  R                  S[
         VVs/ s H  u  n  o!PM
     snnSS9[         R                  R                  SSSSSSS9[         R                  R                  SSSSSSS9[         R                  R                  SSSSS[         R                  R                  S	SS	S9	[         R                  R                  SSS S!S"[         R                  R                  S#S	S$9[         R                  R                  S%S&S'S	S	S(9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S	[         R"                  " S)S*9S	S+9
$ s  snnf ),NrI  zByteDance Imagepartner/image/ByteDancez>Generate images using ByteDance models via api based on promptmodelzseedream-3-0-t2i-250415optionsr   Tz*The text prompt used to generate the image	multilinetooltipsize_presetzHPick a recommended size. Select Custom to use the width and height belowrN  rQ  r            @   QCustom width for image. Value is working only if `size_preset` is set to `Custom`defaultrL   rM   steprQ  r   RCustom height for image. Value is working only if `size_preset` is set to `Custom`seedr   rs   zSeed to use for generationrZ  rL   rM   r[  display_modecontrol_after_generaterQ  optionalguidance_scale      @g      ?      $@g{Gz?z;Higher value makes the image follow the prompt more closelyrZ  rL   rM   r[  r`  rQ  rb  	watermarkFz7Whether to add an "AI generated" watermark to the imagerZ  rQ  rb  advancedz{"type":"usd","usd":0.03})expr
node_iddisplay_namecategorydescriptioninputsoutputsr   is_api_nodeprice_badgeis_deprecated)r   SchemaCombor   Stringr
   IntNumberDisplaynumberFloatBooleanr   OutputHiddenauth_token_comfy_orgapi_key_comfy_orgr   
PriceBadger   labelr   s      r\   define_schema ByteDanceImageNode.define_schema  s   yy(*.Xw1J0KL		"H   
 !6IJ6I{uaU6IJf  
  o    p   "!#!1!1!8!8+/8!  
 $!#!1!1!8!8Y!  	 

  !U!! ! c8t ! 		..		++		##
 4 UK
 K	
 Ks   4G%rL  r   rR  r   r   r]  rc  rg  rJ   c	           	        #    [        USSS9  S =p[         H  u  pnX:X  d  M  Xp  O   U	b  U
c3  XEpSU	s=::  a  S::  a  O  OSU
s=::  a  S::  d  O  [        SU	 SU
 S35      e[        UUU	 SU
 3UUUS	9n[	        U [        [        S
S9U[        S9I S h  vN n[        R                  " [        [        U5      5      I S h  vN 5      $  N4 N
7f)NTrs   strip_whitespace
min_lengthrU  rV  zCustom size out of range: rO   z<. Both width and height must be between 512 and 2048 pixels.)rL  r   sizer]  rc  rg  r   r   r  r   )r8   r
   rT   r&   r0   r(   BYTEPLUS_IMAGE_ENDPOINTr   r   
NodeOutputr)   rG  )r   rL  r   rR  r   r   r]  rc  rg  rW   rX   r  twthpayloadr:  s                   r\   executeByteDanceImageNode.execute  s      	!D0MEr#1 1
 9	q1$$cQ.>$.> 01QC7ww  03as)
 !4VD4	
 
 }}#?@[\d@e#ffgg
 gs)   CA1CC
+CC	CC N)__name__
__module____qualname____firstlineno__classmethodr  r   r   rA  boolr   r  r  __static_attributes__r  ro   r\   rI  rI    s    L
 L
\ 'h'h 'h 	'h
 'h 'h 'h 'h 'h 
'h 'hro   rI  c                       \ rS rSr\S 5       r\S\S   S   SSSSSSS	4	S
\S\S\R                  S-  S\S\
S\
S\S\
S\
S\S\S\R                  4S jj5       rSrg)ByteDanceSeedreamNodei  c                    [         R                  " SSSS[         R                  R                  S[	        [
        R                  5       5      S9[         R                  R                  SSS	S
S9[         R                  R                  SSSS9[         R                  R                  S[         VVs/ s H  u  n  o!PM
     snnSS9[         R                  R                  SSSSSSSS9[         R                  R                  SSSSSSSS9[         R                  R                  SSS/SSS 9[         R                  R                  S!S"S"S#S"[         R                  R                  S$SS%9[         R                  R                  S&S'S'S(S"[         R                  R                  SS)SS*9	[         R                  R                  S+S,S-SSS.9[         R                  R                  S/SS0SSS.9/[         R                  R                  5       /[         R                  R                   [         R                  R"                  [         R                  R$                  /S[         R&                  " [         R(                  " S/S19S2S39SS49
$ s  snnf )5Nr  ByteDance Seedream 4.5 & 5.0rK  \Unified text-to-image generation and precise single-sentence editing at up to 4K resolution.rL  rM  r   Tr   -Text prompt for creating or editing an image.rP  rZ  rQ  r^   zjInput image(s) for image-to-image generation. Reference image(s) for single or multi-reference generation.rQ  rb  rR  IPick a recommended size. Select Custom to use the width and height below.rS  r   rV  rT  `  ra   rX  )rZ  rL   rM   r[  rQ  rb  r     r\  sequential_image_generationdisabledautozGroup image generation mode. 'disabled' generates a single image. 'auto' lets the model decide whether to generate multiple related images (e.g., story scenes, character variations).)rN  rQ  rb  
max_imagesrs      zMaximum number of images to generate when sequential_image_generation='auto'. Total images (input + generated) cannot exceed 15.rf  r]  r   r^  Seed to use for generation.r_  rg  F8Whether to add an "AI generated" watermark to the image.rh  fail_on_partialSIf enabled, abort execution if any requested images are missing or return an error.widgets  
                (
                  $price := $contains(widgets.model, "5.0 lite") ? 0.035 :
                            $contains(widgets.model, "4-5") ? 0.04 : 0.03;
                  {
                    "type":"usd",
                    "usd": $price,
                    "format": { "suffix":" x images/Run", "approximate": true }
                  }
                )
                
depends_onrj  rk  )r   ru  rv  r   listSEEDREAM_MODELSkeysrw  r   r   rx  ry  rz  r|  r}  r~  r  r  r   r  PriceBadgeDependsr  s      r\   r  #ByteDanceSeedreamNode.define_schema  s   yy+7.v !5!5!78   		"K	    S!	   !6TU6T{uaU6TUg  
  o!    p!   1'0B "    !#!1!1!8!8I!  
 "!#!1!1!8!8+/9!  
 

  !V!! !  

  % q!! ! ]Un ! 		..		++		##
 //	B
 es
 s	
0 Vs   -I5Nr   rV  r  rs   FTrL  r   r^   rR  r   r   r  r  r]  rg  r  rJ   c                 r  #    [         U   n[        USSS9  S =p[         H  u  pnX:X  d  M  UUp  O   Ub  Uc  XVpX-  nUS-  nSU;   d  SU;   a  US:  a  [        SUS	 S
35      eSU;   a  US:  a  [        SUS	 S
35      eSU;   a  SOSnUU:  a  [        SUS-  S	 SUS	 S
35      eUb  [	        U5      OSnUS:X  a  SOSnUU:  a  [        SU SU S35      eUS:X  a  UU-   S:  a  [        S5      e/ nU(       a*  U H  n[        USS5        M     [        U UUSS 9I S h  vN n[        U [        [        S!S"9[        [        UUUU S#U 3U	U[        US$9U
US:X  a  S%OS S&9	S'9I S h  vN n[        UR                  5      S:X  a0  [        R                   " [#        [%        U5      5      I S h  vN 5      $ UR                   Vs/ s H0  n['        U[(        5      (       d  M  S(U;   d  M"  [+        US(   5      PM2     nnU(       aP  [        U5      [        UR                  5      :  a.  [-        S)[        U5       S*[        UR                  5       S+35      e[        R                   " [.        R0                  " U Vs/ s H  n[#        U5      I S h  vN PM     sn5      5      $  GN GN; Ns  snf  N s  snf 7f),NTrs   r      .Aseedream-4-5seedream-5-0 @8 ?Minimum image resolution for the selected model is 3.68MP, but .2fMP provided.seedream-4-0  MMinimum image resolution that the selected model can generate is 0.92MP, but i    z3Maximum image resolution for the selected model is i@B zMP, but r   r>      
   Maximum of % reference images are supported, but 
 received.r  r  \The maximum number of generated images plus the number of reference images cannot exceed 15.rs   r=   r=   rs   	image/pngr  	mime_typer   r   rO   r  png)	rL  r   r^   r  r]  r  #sequential_image_generation_optionsrg  output_formatr  r  Only  of $ images were generated before error.)r  r8   r   rT   r-   r6   r3   r0   r(   r  r   r   r   lenr  r   r  r)   rG  
isinstancedictr   r   r  cat)r   rL  r   r^   rR  r   r   r  r  r]  rg  r  rW   rX   r  r  r  out_num_pixelsmp_provided
max_pixelsn_input_imagesmax_num_of_imagesreference_images_urlsr   r:  durlss                              r\   r  ByteDanceSeedreamNode.execute  s&      &!D;MEr#21 <
 9	q${2e#~'>NU\D\UVabeUffrs  U"~'>"3'|5  $2U#:Z

J&EjS\F\]`Ea b"3'|5  9>8I-e4q"'+@"@Bb--/00UVdUeeop  '&0^j5PSU5Un  !#+Avv> *C)%	+ %! !4VD4-+s!A3Z,G4DPZ4[#',0E'Ee4
	
 
  x}}"=='CD_`hDi'j!jkk'/}}[}!
1d8KPUYZPZAeH}[s4y3x}}+==s4ykc(--6H5IImnoo}}UYYW['\W[RS.J1.M(M(MW['\]^^7%
" "k[ )N'\s   'J7C7J7$J#%AJ7+J&,AJ70J)1J7J+$J+,J+>A=J7;J2J0J2J7&J7)J7+J70J22J7r  )r  r  r  r  r  r  r   r   r   r   r   r  r   r  r  r  r  ro   r\   r  r    s    t
 t
l 
 %)9!<Q?+5 $S_S_ S_ {{T!	S_
 S_ S_ S_ &)S_ S_ S_ S_ S_ 
S_ S_ro   r  max_ref_imagespresetsc                    [         R                  R                  SU VVs/ s H  u  n  o2PM
     snnSS9[         R                  R                  SSSSSS	S
9[         R                  R                  SSSSSSS
9[         R                  R                  SSSU S[         R                  R
                  SS9[         R                  R                  S[         R                  R                  [         R                  R                  S5      [        SU S-   5       Vs/ s H  nSU 3PM
     snSS9SU  S3S9[         R                  R                  SSSSS9/$ s  snnf s  snf )NrR  r  rS  r   rV  rT  r  ra   rX  rY  r   r  r\  r  rs   zMaximum number of images to generate. With 1, exactly one image is produced. With >1, the model generates between 1 and max_images related images (e.g., story scenes, character variations). Total images (input + generated) cannot exceed 15.)rZ  rL   rM   r[  r`  rQ  imagesr^   image_r   namesrL   zTOptional reference image(s) for image-to-image or multi-reference generation. Up to z images.)templaterQ  r  Fr  TrZ  rQ  ri  )r   rv  r   rx  ry  rz  AutogrowTemplateNamesr   ranger|  )r  r  r  r   r   s        r\   _seedream_model_inputsr    s|   
.56g{uaUg6_ 	 	

 	g 	 	
 	h 	 	
 	))00A 	 	
 	[[..w'-21nq6H-IJ-Is|-IJ / 
#$H. 	 		
 	

i	 	 	
Y2 2 7F Ks   EEc                   h    \ rS rSr\S 5       r\  SS\S\S\S\	S\
R                  4
S jj5       rS	rg
)ByteDanceSeedreamNodeV2i  c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
[         R                  R                  S[        S[        S95      [         R                  R                  S[        S[        S95      [         R                  R                  S[        S[        S95      /S9[         R                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  SSSSS9/[         R                  R                  5       /[         R                   R"                  [         R                   R$                  [         R                   R&                  /S[         R(                  " [         R*                  " S
/S9SS9S9	$ ) Nr  r  rK  r  r   Tr   r  r  rL  rA   r  )r  r  r?   r  r@   rM  r]  r   r^  rs   r  rZ  rL   rM   r[  r`  ra  rQ  rg  Fr  r  r  r  r  	rl  rm  rn  ro  rp  rq  r   rr  rs  )r   ru  rw  r   DynamicComboOptionr  r   r   r   rx  ry  rz  r|  r   r}  r~  r  r  r   r  r  r   s    r\   r  %ByteDanceSeedreamNodeV2.define_schema  s   yy-7.v		"K	    %%../2"Nqr ..12"Nno ..12"Nno & " "!#!1!1!8!8+/9  	 

  !V!	 ! E(T ! 		..		++		##
 //	B
oE
 E	
ro   r   rL  r]  rg  rJ   c                   #    [        USSS9  [        US      n[        U   nUR                  SUS   S   5      nUR                  SS5      nUR                  S	S5      n	UR                  S
S5      n
U
S:X  a  SOSnUR                  S5      =(       d    0 nUR                  SS5      nS =pU H  u  nnnUU:X  d  M  UUp  O   Ub  Uc  XpX-  nUS-  nSU;   d  SU;   a  US:  a  [	        SUS S35      eSU;   a  US:  a  [	        SUS S35      eUS:  a  [	        SUS S35      eUR                  5        Vs/ s H
  nUc  M  UPM     nn[        S U 5       5      nUS:X  a  SOSnUU:  a  [	        S U S!U S"35      eUS:X  a  UU
-   S#:  a  [	        S$5      e/ nU(       a+  U H  n[        US%S&5        M     [        U UUS'S(S)9I S h  vN n[        U [        [        S*S+9[        [        UUUU S,U 3UU[        U
S-9US.9S/9I S h  vN n[        UR                   5      S:X  a0  ["        R$                  " ['        [)        U5      5      I S h  vN 5      $ UR                    Vs/ s H0  n[+        U[,        5      (       d  M  S0U;   d  M"  [/        US0   5      PM2     nnU(       aP  [        U5      [        UR                   5      :  a.  [1        S1[        U5       S2[        UR                   5       S335      e["        R$                  " [2        R4                  " U Vs/ s H  n['        U5      I S h  vN PM     sn5      5      $ s  snf  GN{ GN@ Ns  snf  N%s  snf 7f)4NTrs   r  rL  rR  r   r   rV  r   r  r  r  r  r  Fr  r  r  r  r  r  r  r  r  r  r  z@Maximum image resolution for the selected model is 16.78MP, but c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r-   ).0ts     r\   	<genexpr>2ByteDanceSeedreamNodeV2.execute.<locals>.<genexpr>  s     Lm1!44ms   r>   r  r  r  r  r  r  r  r  r  r  zUploading reference images)r  r  r  r   r   rO   r  )rL  r   r^   r  r]  r  r  rg  r  r  r  r  r  )r8   r  SEEDREAM_PRESETSrQ   rT   valuessumr6   r3   r0   r(   r  r   r   r   r  r  r   r  r)   rG  r  r  r   r   r  r  )r   r   rL  r]  rg  rG   r  rR  r   r   r  r  images_dictr  rW   rX   r  r  r  r  r  r  image_tensorsr  r  r  tensorr:  r  r  r   s                                  r\   r  ByteDanceSeedreamNodeV2.execute`  s     	!D"5>2"8,iiwqz!}=		'4(8T*YY|Q/
4>!Oj#ii)/R))$5u=$ME2r#21 % 9	q${2h&.H*D.[bJbQR]^aQbbno  X%.6*A"3'|5  J&RS^_bRccop  8C7I7I7K+]7K!qA7K+]LmLL"*.C"CB--/00UVdUeeop  '&0^j5PSU5Un  ,.'+FFFC (*C)%7+ %! !4VD4-+s!A3Z,G4DPZ4[#		
 
 x}}"=='CD_`hDi'j!jkk'/}}[}!
1d8KPUYZPZAeH}[s4y3x}}+==s4ykc(--6H5IImnoo}}UYYW['\W[RS.J1.M(M(MW['\]^^Y ,^ %
  "k[ )N'\s   B5M;A>M9L?L?
A?M	M
=MMAMM
M#M MMA=MM+M,M4MM
MMMMr  N)r   F)r  r  r  r  r  r  r   r  r   r  r   r  r  r  r  ro   r\   r  r    su    F
 F
P 
 W_W_ W_ 	W_
 W_ 
W_ W_ro   r  c                   z    \ rS rSr\S 5       r\ SS\S\S\S\S\S\S	\S
\S\S\	R                  4S jj5       rSrg)ByteDanceTextToVideoNodei  c                    [         R                  " SSSS[         R                  R                  S/ SQSS9[         R                  R                  S	S
SS9[         R                  R                  S/ SQSS9[         R                  R                  S/ SQSS9[         R
                  R                  SSSSSS[         R                  R                  S9[         R
                  R                  SSSSS[         R                  R                  S
SS
S9	[         R                  R                  S S!S"S
S
S#9[         R                  R                  S$S!S%S
S
S#9[         R                  R                  S&S!S'S
S
S#9/	[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S
[         S(9	$ ))Nr  zByteDance Text to Videopartner/video/ByteDancez=Generate video using ByteDance models via api based on promptrL  )seedance-1-5-pro-251215seedance-1-0-pro-250528rD   seedance-1-0-pro-fast-251015r  rN  rZ  r   T+The text prompt used to generate the video.rO  rH   r|   #The resolution of the output video.rS  aspect_ratioru   %The aspect ratio of the output video.durationrb   r=      rs   ,The duration of the output video in seconds.rZ  rL   rM   r[  rQ  r`  r]  r   r^  r  r_  camera_fixedFSpecifies whether to fix the camera. The platform appends an instruction to fix the camera to your prompt, but does not guarantee the actual effect.rh  rg  8Whether to add an "AI generated" watermark to the video.generate_audio@This parameter is ignored for any model except seedance-1-5-pro.r  )r   ru  rv  r   rw  rx  ry  sliderrz  r|  r   r}  r~  r  r  r   PRICE_BADGE_VIDEOr  s    r\   r  &ByteDanceTextToVideoNode.define_schema  s   yy.2.W ;  	 		"I   
  5A  
 "IC  
 J!#!1!1!8!8   "!#!1!1!8!8+/9!  
 

  "!b!! !  

  !V!! !  

  $!^!! ! {DL ! 		..		++		##
 )gT
 T	
ro   rL  r   rH   r  r  r]  r  rg  r  rJ   c
                   #    US:X  a  US:  a  [        S5      e[        USSS9  [        U/ SQ5        U SU S	U S
U SU S[        U5      R	                  5        S[        U5      R	                  5        3n[        U [        U[        US9/US:X  a  U	OS S9[        S[        R                  " [        U   U   US-  -  5      5      S9I S h  vN $  N7f)Nr  rr   =Minimum supported duration for Seedance 1.5 Pro is 4 seconds.Trs   r  rH   r   r  r]  camerafixedrg   --resolution 	 --ratio  --duration  --seed  --camerafixed  --watermark textrL  contentr  re  r  r   )rT   r8   raise_if_text_paramsr   lowerprocess_video_taskr'   r#   rM   mathceilr   )
r   rL  r   rH   r  r  r]  r  rg  r  s
             r\   r   ByteDanceTextToVideoNode.execute  s     --(Q,\]]!DV%lm h &< (#n %" $V  .4467 8y>//124 	 (1(f5616:S1S~Y]
  #1dii0J50QR\0]ailpap0q&rs
 
 	
 
s   C
CCCr  NF)r  r  r  r  r  r  r   r   r  r   r  r  r  r  ro   r\   r  r    s    U
 U
n   %"
"
 "
 	"

 "
 "
 "
 "
 "
 "
 
"
 "
ro   r  c                       \ rS rSr\S 5       r\ SS\S\S\R                  S\S\S\	S	\	S
\
S\
S\
S\R                  4S jj5       rSrg)ByteDanceImageToVideoNodei;  c                    [         R                  " SSSS[         R                  R                  S/ SQSS9[         R                  R                  S	S
SS9[         R
                  R                  SSS9[         R                  R                  S/ SQSS9[         R                  R                  S/ SQSS9[         R                  R                  SSSSSS[         R                  R                  S9[         R                  R                  SSSS S[         R                  R                  S
S!S
S"9	[         R                  R                  S#S$S%S
S
S&9[         R                  R                  S'S$S(S
S
S&9[         R                  R                  S)S$S*S
S
S&9/
[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S
["        S+9	$ ),Nr6  zByteDance Image to Videor
  zGGenerate video using ByteDance models via api based on image and promptrL  )r  r  rE   r  r  r  r   Tr  rO  r^   %First frame to be used for the video.rQ  rH   r|   r  rS  r  adaptiverv   rw   rx   ry   rz   r{   r  r  rb   r=   r  rs   r  r  r]  r   r^  r  r_  r  Fr  rh  rg  r  r  r  r  r   ru  rv  r   rw  r   rx  ry  r  rz  r|  r   r}  r~  r  r  r   r  r  s    r\   r  'ByteDanceImageToVideoNode.define_schema=  s   yy/3.a ;  	 		"I   
 C    5A  
 "UC  
 J!#!1!1!8!8   "!#!1!1!8!8+/9!  
 

  "!b!! !  

  !V!! !  

  $!^!! ! CHT ! 		..		++		##
 )oX
 X	
ro   rL  r   r^   rH   r  r  r]  r  rg  r  rJ   c                 (  #    US:X  a  US:  a  [        S5      e[        USSS9  [        U/ SQ5        [        USSS	S	S
9  [	        USSSS9  [        XSS9I S h  vN S   nU SU SU SU SU S[        U5      R                  5        S[        U	5      R                  5        3n[        U [        U[        US9[        [        US9S9/US:X  a  U
OS S9[        S[        R                  " [         U   U   US-  -  5      5      S9I S h  vN $  N N7f)Nr  rr   r   Trs   r  r!  rh   rf   ri   r`   rc   Frd   r  r   r#  r$  r%  r&  r'  r(  r)  r  )	image_urlr+  re  r-  )rT   r8   r.  r7   r6   r3   r   r/  r0  r   r#   r    r!   rM   r1  r2  r   )r   rL  r   r^   rH   r  r  r]  r  rg  r  r@  s               r\   r  !ByteDanceImageToVideoNode.execute  sX     --(Q,\]]!DV%lm!%33RVcgh#E66%H4SANNPQR	h &< (#n %" $V  .4467 8y>//124 	 (2(f57GRejsRt7uv16:S1S~Y]
  #1dii0J50QR\0]ailpap0q&rs
 
 	
 O
s%   ADDB/D	D
DDr  Nr4  r  r  r  r  r  r  r   r   r   r   r  r   r  r  r  r  ro   r\   r6  r6  ;  s    Y
 Y
v   %'
'
 '
 {{	'

 '
 '
 '
 '
 '
 '
 '
 
'
 '
ro   r6  c                       \ rS rSr\S 5       r\ SS\S\S\R                  S\R                  S\S\S	\	S
\	S\
S\
S\
S\R                  4S jj5       rSrg)ByteDanceFirstLastFrameNodei  c                 .   [         R                  " SSSS[         R                  R                  S/ SQSS9[         R                  R                  S	S
SS9[         R
                  R                  SSS9[         R
                  R                  SSS9[         R                  R                  S/ SQSS9[         R                  R                  S/ SQSS9[         R                  R                  SSSSSS[         R                  R                  S9[         R                  R                  S S!S!S"S[         R                  R                  S
S#S
S$9	[         R                  R                  S%S&S'S
S
S(9[         R                  R                  S)S&S*S
S
S(9[         R                  R                  S+S&S,S
S
S(9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S
["        S-9	$ ).NrD  z#ByteDance First-Last-Frame to Videor
  z6Generate video using prompt and first and last frames.rL  )r  r  rE   rE   r  r   Tr  rO  first_framer8  r9  
last_framez$Last frame to be used for the video.rH   r|   r  rS  r  r:  r  r  rb   r=   r  rs   r  r  r]  r   r^  r  r_  r  Fr  rh  rg  r  r  r  r  r<  r  s    r\   r  )ByteDanceFirstLastFrameNode.define_schema  s   yy1>.Pr:  
 		"I   
 !C    B    5A  
 "UC  
 J!#!1!1!8!8   "!#!1!1!8!8+/9!  
 

  "!b!! !  

  !V!! !  

  $!^!! ! AGR ! 		..		++		##
 )mW
 W	
ro   rL  r   rF  rG  rH   r  r  r]  r  rg  r  rJ   c                   #    US:X  a  US:  a  [        S5      e[        USSS9  [        U/ SQ5        X44 H  n[        USSS	S	S
9  [	        USSSS9  M     [        U [        X45      SSS9I S h  vN nU SU SU SU SU S[        U	5      R                  5        S[        U
5      R                  5        3n[        U [        U[        US9[        [        [        US   5      S9SS9[        [        [        US   5      S9SS9/US:X  a  UOS S9[        S[        R                   " ["        U   U   US-  -  5      5      S 9I S h  vN $  N N7f)!Nr  rr   r   Trs   r  r!  rh   rf   ri   r`   rc   Frd   ra   r  r  r#  r$  r%  r&  r'  r(  r)  r   r?  rF  r@  rolerG  r+  re  r-  )rT   r8   r.  r7   r6   r3   r.   r   r/  r0  r   r#   r    r!   rM   r1  r2  r   )r   rL  r   rF  rG  rH   r  r  r]  r  rg  r  r   download_urlss                 r\   r  #ByteDanceFirstLastFrameNode.execute!  s     --(Q,\]]!DV%lm*A%a33RVcgh'66%H + 8&{?!	
 
 h &< (#n %" $V  .4467 8y>//124 	 (2#0$/Bs=YZK[G\/]dqr$/Bs=YZK[G\/]dpq
 27:S1S~Y]  #1dii0J50QR\0]ailpap0q&rs
 
 	
#
"
s%   A,E.E	/CEEEEr  Nr4  rB  r  ro   r\   rD  rD    s    X
 X
t   %3
3
 3
 [[	3

 KK3
 3
 3
 3
 3
 3
 3
 3
 
3
 3
ro   rD  c                       \ rS rSr\S 5       r\S\S\S\R                  S\S\S\	S	\	S
\
S\R                  4S j5       rSrg)ByteDanceImageReferenceNodeiX  c                    [         R                  " SSSS[         R                  R                  SSS/SS9[         R                  R                  S	S
SS9[         R
                  R                  SSS9[         R                  R                  SSS/SS9[         R                  R                  S/ SQSS9[         R                  R                  SSSSSS[         R                  R                  S9[         R                  R                  SS S S!S[         R                  R                  S
S"S
S#9	[         R                  R                  S$S%S&S
S
S'9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S
[         R"                  " [         R$                  " / S(QS)9S*S+9S,9	$ )-NrO  z#ByteDance Reference Images to Videor
  z1Generate video using prompt and reference images.rL  r  rE   r  r   Tr  rO  r  zOne to four images.r9  rH   r}   r~   r  rS  r  r:  r  r  rb   r=   r  rs   r  r  r]  r   r^  r  r_  rg  Fr  rh  )rL  r  rH   r  a(  
                (
                  $priceByModel := {
                    "seedance-1-0-pro": {
                      "480p":[0.23,0.24],
                      "720p":[0.51,0.56]
                    },
                    "seedance-1-0-lite": {
                      "480p":[0.17,0.18],
                      "720p":[0.37,0.41]
                    }
                  };
                  $model := widgets.model;
                  $modelKey :=
                    $contains($model, "seedance-1-0-pro")  ? "seedance-1-0-pro" :
                    "seedance-1-0-lite";
                  $resolution := widgets.resolution;
                  $resKey :=
                    $contains($resolution, "720") ? "720p" :
                    "480p";
                  $modelPrices := $lookup($priceByModel, $modelKey);
                  $baseRange := $lookup($modelPrices, $resKey);
                  $min10s := $baseRange[0];
                  $max10s := $baseRange[1];
                  $scale := widgets.duration / 10;
                  $minCost := $min10s * $scale;
                  $maxCost := $max10s * $scale;
                  ($minCost = $maxCost)
                    ? {"type":"usd","usd": $minCost}
                    : {"type":"range_usd","min_usd": $minCost, "max_usd": $maxCost}
                )
                r  r  )r   ru  rv  r   rw  r   rx  ry  r  rz  r|  r   r}  r~  r  r  r   r  r  r  s    r\   r  )ByteDanceImageReferenceNode.define_schemaZ  s   yy1>.K68VW:  
 		"I   
 1    #V,A  
 "UC  
 J!#!1!1!8!8   "!#!1!1!8!8+/9!  
 

  !V!! ! [4l ! 		..		++		##
 //8[\"Gf
 f	
ro   rL  r   r  rH   r  r  r]  rg  rJ   c	                   #    [        USSS9  [        U/ SQ5        U H  n	[        U	SSSSS9  [        U	SS	S
S9  M     [	        XSSS9I S h  vN n
U SU SU SU SU S[        U5      R                  5        3n[        US9/U
 Vs/ s H  n[        [        [        U5      S9SS9PM     snQn[        U [        XS S9[        S[        R                  " [        U   U   US-  -  5      5      S9I S h  vN $  Ns  snf  N7f)NTrs   r  )rH   r   r  r]  rg  rh   rf   ri   r`   rc   Frd   rr   r  r  r#  r$  r%  r&  r(  r)  r?  reference_imagerJ  r+  re  r-  )r8   r.  r7   r6   r3   r   r/  r#   r    r!   r0  r   rM   r1  r2  r   )r   rL  r   r  rH   r  r  r]  rg  r^   
image_urlsr   rO   s                r\   r  #ByteDanceImageReferenceNode.execute  sG     	!DV%]^E%essVZgkl'vveL  5SQZeff
h &< (#n %" $V y>//124 	 (
kuvkufg)<Q)HO`akuv
 (2Z^_"1dii0J50QR\0]ailpap0q&rs
 
 	
 g w
s1   A
DC9;D$C;,AD4D 5D;Dr  NrB  r  ro   r\   rO  rO  X  s    g
 g
R "
"
 "
 	"

 "
 "
 "
 "
 "
 
"
 "
ro   rO  text_paramsc                 H    U H  nSU S3U ;   d  M  [        SU S35      e   g )Nz--r   zV is not allowed in the prompt, use the appropriated widget input to change this value.)rT   )r   rV  r   s      r\   r.  r.    s6    s!9QCmn  ro   )rL  r  rH   r  r  a  
    (
      $priceByModel := {
        "seedance-1-5-pro": {
          "480p":[0.12,0.12],
          "720p":[0.26,0.26],
          "1080p":[0.58,0.59]
        },
        "seedance-1-0-pro": {
          "480p":[0.23,0.24],
          "720p":[0.51,0.56],
          "1080p":[1.18,1.22]
        },
        "seedance-1-0-pro-fast": {
          "480p":[0.09,0.1],
          "720p":[0.21,0.23],
          "1080p":[0.47,0.49]
        },
        "seedance-1-0-lite": {
          "480p":[0.17,0.18],
          "720p":[0.37,0.41],
          "1080p":[0.85,0.88]
        }
      };
      $model := widgets.model;
      $modelKey :=
        $contains($model, "seedance-1-5-pro")      ? "seedance-1-5-pro" :
        $contains($model, "seedance-1-0-pro-fast") ? "seedance-1-0-pro-fast" :
        $contains($model, "seedance-1-0-pro")      ? "seedance-1-0-pro" :
        "seedance-1-0-lite";
      $resolution := widgets.resolution;
      $resKey :=
        $contains($resolution, "1080") ? "1080p" :
        $contains($resolution, "720")  ? "720p" :
        "480p";
      $modelPrices := $lookup($priceByModel, $modelKey);
      $baseRange := $lookup($modelPrices, $resKey);
      $min10s := $baseRange[0];
      $max10s := $baseRange[1];
      $scale := widgets.duration / 10;
      $audioMultiplier := ($modelKey = "seedance-1-5-pro" and widgets.generate_audio) ? 2 : 1;
      $minCost := $min10s * $scale * $audioMultiplier;
      $maxCost := $max10s * $scale * $audioMultiplier;
      ($minCost = $maxCost)
        ? {"type":"usd","usd": $minCost, "format": { "approximate": true }}
        : {"type":"range_usd","min_usd": $minCost, "max_usd": $maxCost, "format": { "approximate": true }}
    )
    r  resolutionsdefault_ratioc                 r   [         R                  R                  SSSSS9[         R                  R                  SU SS9[         R                  R                  S	/ S
QUSS9[         R                  R                  SSSSSS[         R
                  R                  S9[         R                  R                  SSSS9/$ )Nr   Tr   z!Text prompt for video generation.r  rH   zResolution of the output video.rS  r   )rv   rw   rx   ry   rz   r{   r;  z!Aspect ratio of the output video.)rN  rZ  rQ  r     rr   r  rs   z/Duration of the output video in seconds (4-15).r  r  z-Enable audio generation for the output video.rZ  rQ  )r   rw  r   rv  rx  ry  r  r|  rX  rY  s     r\   _seedance2_text_inputsr^  '  s    
		7	 	 	
 	5 	 	

 	M!7	 	 	
 	E))00 	 	
 	

C 	 	
7   ro   c            	       \    \ rS rSr\S 5       r\S\S\S\S\	R                  4S j5       rSrg	)
ByteDance2TextToVideoNodeiK  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[        / SQ5      5      [         R                  R	                  S[        S	S
/5      5      /SS9[         R                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  SSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " / SQS9SS9S9	$ )Nr`  z$ByteDance Seedance 2.0 Text to Videor
  z@Generate video using Seedance 2.0 models based on a text prompt.rL  rB   r|   rC   r}   r~   KSeedance 2.0 for maximum quality; Seedance 2.0 Fast for speed optimization.rS  r]  r   r^  rs   T_Seed controls whether the node should re-run; results are non-deterministic regardless of seed.r  rg  F(Whether to add a watermark to the video.r  rL  zmodel.resolutionzmodel.durationr    
                (
                  $rate480 := 10044;
                  $rate720 := 21600;
                  $rate1080 := 48800;
                  $m := widgets.model;
                  $pricePer1K := $contains($m, "fast") ? 0.008008 : 0.01001;
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $rate := $res = "1080p" ? $rate1080 :
                           $res = "720p"  ? $rate720 :
                                            $rate480;
                  $cost := $dur * $rate * $pricePer1K / 1000;
                  {"type": "usd", "usd": $cost, "format": {"approximate": true}}
                )
                r  r  )r   ru  r  r   r  r^  rx  ry  rz  r|  r   r}  r~  r  r  r   r  r  r  s    r\   r  'ByteDance2TextToVideoNode.define_schemaM  sR   yy/?.Z%%..~?UVo?pq../BDZ\bdj[kDlm j &  "!#!1!1!8!8+/H  
 

  !F!	 ! )8 ! 		..		++		##
 //8ghS<
 <	
ro   rL  r]  rg  rJ   c                   #    [        US   SSS9  [        US      n[        U [        [        SS9[        U[        US   S9/US	   US
   US   US   UUS9[        S9I S h  vN n[        U [        [         SUR                   3S9[        S [        USS9SS9I S h  vN n[        R                  " [        UR                   R"                  5      I S h  vN 5      $  N| NA N7f)Nr   Trs   r  rL  r   r   r)  r  rH   r   r  rL  r,  r  rH   r   r  r]  rg  r  /r   c                     U R                   $ r   r   r   s    r\   r   3ByteDance2TextToVideoNode.execute.<locals>.<lambda>      qxxro   Fr8  rq   r   r   price_extractorr   )r8   SEEDANCE_MODELSr0   r(   BYTEPLUS_TASK_ENDPOINTr   r#   r   r/   'BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINTidr"   rB  r   r  r*   r,  	video_url)r   rL  r]  rg  rG   initial_responser:  s          r\   r  !ByteDance2TextToVideoNode.execute  s     	h$1M"5>2!(3FC-(eHo>?$%56 .Gnz*#	 0"
 
 ! GHJZJ]J]I^_`-/6xQVW
 
 }}#?@P@P@Z@Z#[[\\/

 \s6   AC$!C"<C$C 6C$C"	C$ C$"C$r  Nr  r  r  r  r  r  r  r   r  r   r  r  r  r  ro   r\   r`  r`  K  sY    =
 =
~ ]] ] 	]
 
] ]ro   r`  c                       \ rS rSr\S 5       r\    SS\S\S\S\	R                  S-  S\	R                  S-  S	\S
\S\R                  4S jj5       rSrg)ByteDance2FirstLastFrameNodei  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[        / SQSS	95      [         R                  R	                  S
[        SS/SS	95      /SS9[         R                  R                  SSSS9[         R                  R                  SSSS9[         R                  R                  SSSSS9[         R                  R                  SSSSS9[         R                  R                  SSSSS[         R                  R                  SSS 9[         R                  R                  S!S"S#SS$9/[         R                  R                  5       /[         R                  R                  [         R                  R                   [         R                  R"                  /S[         R$                  " [         R&                  " / S%QS&9S'S(9S)9	$ )*Nrz  z0ByteDance Seedance 2.0 First-Last-Frame to Videor
  zYGenerate video using Seedance 2.0 from a first frame image and optional last frame image.rL  rB   r|   r;  rY  rC   r}   r~   rb  rS  rF  z First frame image for the video.Tr  rG  zLast frame image for the video.first_frame_asset_idr   zaSeedance asset_id to use as the first frame. Mutually exclusive with the first_frame image input.)rZ  rQ  rb  last_frame_asset_idz_Seedance asset_id to use as the last frame. Mutually exclusive with the last_frame image input.r]  r   r^  rs   rc  r  rg  Frd  r  re  r  rf  r  r  )r   ru  r  r   r  r^  r   rw  rx  ry  rz  r|  r   r}  r~  r  r  r   r  r  r  s    r\   r  *ByteDance2FirstLastFrameNode.define_schema  s   yy2K.s%%..*23L\fg ../2FF3CS]^	 j &  !>!  
  =!  
 		*K!    		)J!    "!#!1!1!8!8+/H  
 

  !F!	 ! e8t ! 		..		++		##
 //8ghOZ
 Z	
ro   NrL  r]  rg  rF  rG  r}  r~  rJ   c                   #    [        US   SSS9  [        US      nUR                  5       nUR                  5       nUb  U(       a  [        S5      eUc  U(       d  [        S5      eUb  U(       a  [        S5      eUS	   n	U(       d  U(       a  Ub  [	        U5      nUb  [	        U5      nOyS
n	S n
Ub6  [        USSSS9  [        USSS9  [        US   US	   U5      n
[        U/U
Q76 nUb9  [        USSSS9  [        USSS9  U
c  [        US   US	   U5      n
[        U/U
Q76 nXg4 Vs/ s H  o(       d  M  UPM     nn0 nU(       a4  [        X5      I S h  vN u  n  nU H  nX;  d  M
  [        SU S35      e   U(       a  X   nO[        XSS9I S h  vN n[        US   S9[        [        US9SS9/nU(       a#  UR                  [        [        X   S9SS95        O3Ub0  UR                  [        [        [        XSS9I S h  vN S9SS95        [        U [!        ["        SS9[%        UUUS   US   U	US   UUS 9[&        S!9I S h  vN n[)        U [!        [*         S"UR,                   3S#9[.        S$ [1        USS%9S&S'9I S h  vN n[2        R4                  " [7        UR8                  R:                  5      I S h  vN 5      $ s  snf  GNv GN: N N NN N7f)(Nr   Trs   r  rL  zBProvide only one of first_frame or first_frame_asset_id, not both.z7Either first_frame or first_frame_asset_id is required.z@Provide only one of last_frame or last_frame_asset_id, not both.r   r;  r`   rc   Frd   rh   )rj   rk   rH   zAsset z is not an Image asset.zUploading first frame.r  r)  r?  rF  rJ  rG  zUploading last frame.r   r   r  r  ri  r  rj  r   c                     U R                   $ r   r   r   s    r\   r   6ByteDance2FirstLastFrameNode.execute.<locals>.<lambda>{  rm  ro   rn  rq   ro  )r8   rq  r   rT   rn   r6   r7   r   r   r   r+  r#   r    r!   appendr0   r(   rr  r   r   r/   rs  rt  r"   rB  r   r  r*   r,  ru  )r   rL  r]  rg  rF  rG  r}  r~  rG   request_ratiotarget_dimsaasset_ids_to_resolver   r   aidfirst_frame_urlr,  rv  r:  s                       r\   r  $ByteDance2FirstLastFrameNode.execute  sI     	h$1M"5>2399;1779"';abb';VWW!&9_``g#6&5kB%4Z@
 'M26K&+KPUV)+QTU4U<5H%PW.Zef.{I[I%+JuU)*PST&"8|9LeT[n^h"iK-jG;G
,@+V\+VaZ[+V\')'@'[![L!Q+*$vcU2I%JKK ,  *@O$P-E% O
 x1-/B"=
 NN 1l6WX% #NN 1"N8O# 
 &	 ")3FC-$%56 .#z*#	 0"
 
 ! GHJZJ]J]I^_`-/6xQVW
 
 }}#?@P@P@Z@Z#[[\\A  ] "\,

 \s   D(K*
K8K>KKK,*KKA0KKAKK<KK	6K?K KKKKKKr  )NNr   r   )r  r  r  r  r  r  r  r   r  r   r   r   r   r  r  r  r  ro   r\   rz  rz    s    [
 [
z  +/)-$&#%n]n] n] 	n]
 [[4'n] KK$&n] "n] !n] 
n] n]ro   rz  c           
      j   / [        XS9Q[        R                  R                  S[        R                  R	                  [        R
                  R                  S5      / SQSS9S9P[        R                  R                  S[        R                  R	                  [        R                  R                  S	5      / S
QSS9S9P[        R                  R                  S[        R                  R	                  [        R                  R                  S5      / SQSS9S9P[        R                  R                  SSSSS9P[        R                  R                  SSSSSS9P[        R                  R                  S[        R                  R	                  [        R                  R                  S5      / SQSS9S9P$ )Nr|  reference_imagesrS  )	image_1image_2image_3image_4image_5image_6image_7image_8image_9r   r  )r  reference_videosreference_video)video_1video_2video_3reference_audiosreference_audio)audio_1audio_2audio_3auto_downscaleTzAutomatically downscale reference videos that exceed the model's pixel budget for the selected resolution. Aspect ratio is preserved; videos already within limits are untouched.)rZ  rb  rQ  auto_upscaleFa+  Automatically upscale reference videos that are below the model's minimum pixel count for the selected resolution. Aspect ratio is preserved; videos already meeting the minimum are untouched. Note: upscaling a low-resolution source does not add real detail and may produce lower-quality generations.)rZ  ri  rb  rQ  r   reference_asset)	asset_1asset_2asset_3asset_4asset_5asset_6asset_7asset_8asset_9)
r^  r   r  r   r  r   r   r   r|  rw  r]  s     r\   _seedance2_reference_inputsr    s   G		IG
[[..01
  /  	 	
G( 	[[..017 /  	 	
)G8 	[[..017 /  	 	
9GH 	

r	 	 	
IGV 	

) 	 		
WGj 	[[..		 12
  /  	 	
kG Gro   c            	       \    \ rS rSr\S 5       r\S\S\S\S\	R                  4S j5       rSrg	)
ByteDance2ReferenceNodei  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[        / SQSS	95      [         R                  R	                  S
[        SS/SS	95      /SS9[         R                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  SSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " / SQS/S9SS9S9	$ ) Nr  z)ByteDance Seedance 2.0 Reference to Videor
  zGenerate, edit, or extend video using Seedance 2.0 with reference images, videos, and audio. Supports multimodal reference, video editing, and video extension.rL  rB   r|   r;  r|  rC   r}   r~   rb  rS  r]  r   r^  rs   Trc  r  rg  Frd  r  re  zmodel.reference_videos)r  input_groupsa  
                (
                  $rate480 := 10044;
                  $rate720 := 21600;
                  $rate1080 := 48800;
                  $m := widgets.model;
                  $hasVideo := $lookup(inputGroups, "model.reference_videos") > 0;
                  $noVideoPricePer1K := $contains($m, "fast") ? 0.008008 : 0.01001;
                  $videoPricePer1K := $contains($m, "fast") ? 0.004719 : 0.006149;
                  $res := $lookup(widgets, "model.resolution");
                  $dur := $lookup(widgets, "model.duration");
                  $rate := $res = "1080p" ? $rate1080 :
                           $res = "720p"  ? $rate720 :
                                            $rate480;
                  $noVideoCost := $dur * $rate * $noVideoPricePer1K / 1000;
                  $minVideoFactor := $ceil($dur * 5 / 3);
                  $minVideoCost := $minVideoFactor * $rate * $videoPricePer1K / 1000;
                  $maxVideoCost := (15 + $dur) * $rate * $videoPricePer1K / 1000;
                  $hasVideo
                    ? {
                        "type": "range_usd",
                        "min_usd": $minVideoCost,
                        "max_usd": $maxVideoCost,
                        "format": {"approximate": true}
                      }
                    : {
                        "type": "usd",
                        "usd": $noVideoCost,
                        "format": {"approximate": true}
                      }
                )
                r  r  )r   ru  r  r   r  r  rx  ry  rz  r|  r   r}  r~  r  r  r   r  r  r  s    r\   r  %ByteDance2ReferenceNode.define_schema  sm   yy-D.d %%..*78Qakl ../78HXbc	 j &  "!#!1!1!8!8+/H  
 

  !F!	 ! 5 D ! 		..		++		##
 //K":!;%aV
 V	
ro   rL  r]  rg  rJ   c                 8  #    [        US   SSS9  UR                  S0 5      nUR                  S0 5      nUR                  S0 5      nUR                  S0 5      n[        U [        UR	                  5       5      5      I S h  vN u  pn
U(       d   U(       d  U(       d  U	(       d  [        S	5      e[        U5      [        U5      -   nUS
:  a'  [        SU S[        U5       S[        U5       S35      e[        U5      [        U	5      -   nUS:  a'  [        SU S[        U5       S[        U	5       S35      e[        U5      [        U
5      -   nUS:  a'  [        SU S[        U5       S[        U
5       S35      eU H  n[        XN   5      XN'   M     [        US      nUS:  nUR                  S5      (       a`  U(       aY  [        R                  " U0 5      R                  US   0 5      R                  S5      nU(       a  U H  n[        X^   U5      X^'   M     UR                  S5      (       a`  U(       aY  [        R                  " U0 5      R                  US   0 5      R                  S5      nU(       a  U H  n[        X^   U5      X^'   M     Sn[        US5       HI  u  nnX^   n[        UXS   U5         UR                  5       nUS:  a  [        S U S!US" S#35      eUU-  nMK     US$:  a  [        S%US" S&35      eSn[        US5       HR  u  nnXn   n[!        US'   R"                  S(   5      [!        US)   5      -  nUS:  a  [        S*U S!US" S#35      eUU-  nMT     US$:  a  [        S+US" S&35      e[%        UUU	U
[        U5      [        U5      [        U5      5      n['        US   U5      n[)        US,9/n[        US5       H<  u  nnUR+                  [-        [/        [1        U XN   S-U 3S.9I S h  vN S/9S0S195        M>     [        US5       H;  u  nnUR+                  [3        [5        [7        U X^   S2U 3S.9I S h  vN S/9S395        M=     U H7  nUR+                  [9        [;        [=        U Xn   S4S5S6S79I S h  vN S/9S895        M9     UR	                  5        H#  nUR+                  [-        [/        US/9S0S195        M%     U	R	                  5        H"  nUR+                  [3        [5        US/9S395        M$     U
R	                  5        H"  nUR+                  [9        [;        US/9S895        M$     [?        U [A        [B        S9S:9[E        UUUS;   US   US<   US=   UUS>9[F        S?9I S h  vN n[I        U [A        [J         S@URL                   3SA9[N        SB [Q        UUSC9S
SD9I S h  vN n[R        RT                  " [W        URX                  RZ                  5      I S h  vN 5      $  GNm! [
         a    e [         a     GMj  f = f GN GN GN N Ni N47f)ENr   Trs   r  r  r  r  r   z;At least one reference image or video or asset is required.rq   zToo many reference images: z	 (images=z, image assets=z). Maximum is 9.r=   zToo many reference videos: z	 (videos=z, video assets=z). Maximum is 3.zToo many reference audios: z	 (audios=z, audio assets=rL  r   r  rH   rM   r  rL   g        g?rN   z is too short: z.1fz#s. Minimum duration is 1.8 seconds.g333333.@z"Total reference video duration is zs. Maximum is 15.1 seconds.waveformr   sample_ratezReference audio z"Total reference audio duration is r)  zUploading image r  r?  rS  rJ  zUploading video )ru  mp3
libmp3lamez
audio/mpeg)container_format
codec_namer  )	audio_urlr   r   r  r   r  ri  r  rj  r   c                     U R                   $ r   r   r   s    r\   r   1ByteDance2ReferenceNode.execute.<locals>.<lambda>  rm  ro   rn  ro  ).r8   rQ   r   r  r  rT   r  rn   rq  r   r,   r5   r   r]   get_durationrS   r   r   r   r   r#   r  r    r!   r+  r$   r%   r7  r   r   r1   r0   r(   rr  r   r   r/   rs  rt  r"   rB  r   r  r*   r,  ru  )r   rL  r]  rg  r  r  r  r   reference_image_assetsreference_video_assetsreference_audio_assetstotal_imagestotal_videostotal_audiosr   rG   r8  r[   rZ   total_video_durationr   rF   durtotal_audio_durationaudioasset_labelsprompt_textr,  r  rv  r:  s                                  r\   r  ByteDance2ReferenceNode.execute)  s     	h$1M 99%7< 99%7< 99%7< 99%7<Wp&--/0X
 R
N8N  (8AW`vZ[[+,s3I/JJ!-l^ </01E[A\@]]mo  +,s3I/JJ!-l^ </01E[A\@]]mo  +,s3I/JJ!-l^ </01E[A\@]]mo 
 $C$;<L<Q$R! $ #5>2&*99%&&+;599(BGKKER^L_acdhhinoF+C,IJZJ_ag,h$) , 99^$$)9599(BGKKER^L_acdhhinoF+C,GHXH]_e,f$) ,  # 0!4FAs$)E&uhl8KQO((*9$'7s/#cRu%vww$+$ 5  $&ABVWZA[[vwxx" 0!4FAs$)EeJ'--b12S}9M5NNCSy #3A3oc#YNq!rss C'  5  $&ABVWZA[[vwxx*""" ! ! !
 *%/<H -c
   0!4FAsNN 1"N,1)9!'=#  +	 5   0!4FAsNN 1"N,1)9!'=# 
 5 $CNN 1":,1-2'3&2# 
 $ *002CNN 1c:* 3 *002CNN +>3+GH 3 *002CNN +>3+GH 3 ")3FC-$%56 .Gnz*#	 0"
 
 ! GHJZJ]J]I^_`-/6xQ`a
 
 }}#?@P@P@Z@Z#[[\\CR
j   B2

 \s   A=X?W, H7X8.W/&DX9X:AXX<XXC,X/X0<X,X-6X#X$	X/XXXXXXXXXr  Nrx  r  ro   r\   r  r    sa    W
 W
r n]n] n] 	n]
 
n] n]ro   r  r  r   c                   #    UR                   [        ;   a   [        R                  SUR                   5        [	        U [        [        SS9U[        S9I S h  vN n[        U [        [         SUR                   3S9S U[        S9I S h  vN n[        R                  " [        UR                  R                   5      I S h  vN 5      $  Ns NA N7f)	NzModel '%s' is deprecated and will be deactivated on May 13, 2026. Please switch to a newer model. Recommended: seedance-1-0-pro-fast-251015.r   r   r  rj  r   c                     U R                   $ r   r   r   s    r\   r   $process_video_task.<locals>.<lambda>  r   ro   )r   r   r   )rL  DEPRECATED_MODELSr   r   r0   r(   rr  r   r/   BYTEPLUS_TASK_STATUS_ENDPOINTrt  r"   r   r  r*   r,  ru  )r   r  r   rv  r:  s        r\   r0  r0    s     
 }}))YMM	

 %/?+	  9:!<L<O<O;PQR+-) H ==;H<L<L<V<VWWXX Xs6   ACC
3C
C6CC	CCCc                       \ rS rSr\S\R                  4S j5       r\ S	S\R                  S\
S\R                  4S jj5       rSrg)
ByteDanceCreateImageAsseti  rJ   c                    [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S
S9/[         R                  R                  SS9[         R                  R                  SS9/[         R                  R                  [         R                  R                  [         R                  R                  /S9$ )Nr  zByteDance Create Image AssetrK  zCreate a Seedance 2.0 personal image asset. Uploads the input image and registers it in the given asset group. If group_id is empty, runs a real-person H5 authentication flow to create a new group before adding the asset.r^   z&Image to register as a personal asset.r9  r   r   Reuse an existing Seedance asset group ID to skip repeated human verification for the same person. Leave empty to run real-person authentication in the browser and create a new group.r\  r   rm  rl  rm  rn  ro  rp  rq  r   )
r   ru  r   r   rw  r}  r~  r  r  r   r  s    r\   r  'ByteDanceCreateImageAsset.define_schema      yy/7.X
 w0XY		x    		  j 9		  j 9
 		..		++		##7!
 !	
ro   r^   r   c                   #    [        USSSSS9  [        USSS9  [        X5      I S h  vN n[        U U[	        X5      I S h  vN SSS	9I S h  vN n[        XU5      I S h  vN   [        R                  R                  S
U SU 3U R                  R                  5        [        R                  " XC5      $  N Nv Nl NZ7f)Nrh   rf   rj   rl   rk   rm   )皙?rs   )rd  rs   )	min_ratio	max_ratior   r   r   r  r  r   <Please save the asset_id and group_id for reuse.

asset_id: r  )r7   r6   r  r	  r2   r  r;   r   r   r   r   r   r  )r   r^   r   resolved_groupr   s        r\   r  !ByteDanceCreateImageAsset.execute	  s      	"%3$SVcgh#EXR0??/#.s::
 
 %SNCCC00LXJ W'(*JJ  	

 }}X66 @ ;
 	DsF   'C B8C B:C B<C #B>$AC :C <C >C r  Nr   )r  r  r  r  r  r   ru  r  r   r   r   r  r  r  r  ro   r\   r  r    s]    "
bii "
 "
H  7{{7 7
 
7 7ro   r  c                       \ rS rSr\S\R                  4S j5       r\ S	S\R                  S\
S\R                  4S jj5       rSrg)
ByteDanceCreateVideoAsseti9	  rJ   c                    [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S
S9/[         R                  R                  SS9[         R                  R                  SS9/[         R                  R                  [         R                  R                  [         R                  R                  /S9$ )Nr  zByteDance Create Video Assetr
  zCreate a Seedance 2.0 personal video asset. Uploads the input video and registers it in the given asset group. If group_id is empty, runs a real-person H5 authentication flow to create a new group before adding the asset.rF   z&Video to register as a personal asset.r9  r   r   r  r\  r   r  r  )
r   ru  r   r   rw  r}  r~  r  r  r   r  s    r\   r  'ByteDanceCreateVideoAsset.define_schema;	  r  ro   rF   r   c           	        #    [        USSS9  [        USSSSS9  UR                  5       u  p4US:  a)  X4-  nSUs=::  a  S	::  d  O  [        S
US SU SU S35      eX4-  nSUs=::  a  S::  d  O  [        SUS SU SU S35      e[	        UR                  5       5      nSUs=::  a  S::  d  O  [        SUS S35      e[        X5      I S h  vN n[        U U[        X5      I S h  vN SSS9I S h  vN n	[        X	U5      I S h  vN   [        R                  R                  SU	 SU 3U R                  R                  5        [        R                   " X5      $  N Nv Nl NZ7f)Nra   r  )min_durationmax_durationrh   rf   r  r   r  rd  z:Asset video aspect ratio (W/H) must be in [0.4, 2.5], got z.3fz (rO   r   i @ i& uA   Asset video total pixels (W×H) must be in [409600, 927408], got rP      <   z)Asset video FPS must be in [24, 60], got r  .r   r   r  r  r  )r:   r9   rR   rT   rA  get_frame_rater  r	  r4   r  r;   r   r   r   r   r   r  )
r   rF   r   rW   rX   r   rY   fpsr  r   s
             r\   r  !ByteDanceCreateVideoAsset.execute`	  s     	 ABG!%3$SVcgh##%q5EE5'C' #]^cdg]hhjkljmmnopnqqs!tuu6,W,WX^_`Waacdecffghigjjlm  E((*+cRHS	QRSTT0??/#.s::
 
 %SNCCC00LXJ W'(*JJ  	

 }}X66 @ ;
 	DsI   C	E"EE"%E&E"1E2E"E AE"E"E" E"r  Nr  )r  r  r  r  r  r   ru  r  r   r   r   r  r  r  r  ro   r\   r  r  9	  s]    "
bii "
 "
H  (7{{(7 (7
 
(7 (7ro   r  c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)ByteDanceExtensioni	  rJ   c                    #    [         [        [        [        [        [
        [        [        [        [        [        [        /$ 7fr   )rI  r  r  r  r6  rD  rO  r`  rz  r  r  r  )selfs    r\   get_node_list ByteDanceExtension.get_node_list	  s5      !#$%''%(#%%
 	
s   ?Ar  N)r  r  r  r  r   r  typer   	ComfyNoder  r  r  ro   r\   r  r  	  s)    
T$r||*<%= 
 
ro   r  c                     #    [        5       $ 7fr   )r  r  ro   r\   comfy_entrypointr  	  s     s   )rv   )r  rD  r1  reior   r  typing_extensionsr   comfy.utilsr   comfy_api.latestr   r   r   r	   comfy_api_nodes.apis.bytedancer
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   comfy_api_nodes.utilr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   serverr;   r  r   r   r  r   rr  r  rs  rq  r  	getLoggerr  r   r   r   r   r]   r   rn   r   r   Tensorr!  r   r   r  r  r  r  r   compile
IGNORECASEr   r   r   r   r  r	  r  r+  r7  r  rB  rG  rI  r  r  r  r  r6  rD  rO  r.  r  r  r  r^  r`  rz  r  r  r  r0  r  r  r  r  r  ro   r\   <module>r     s      	   & & = =       @     *  E !$ "#  /00 ?;;  M  S *g ' 3<
 45ST  
		8	$
ekk 
S 
c 
Z] 
bf 
65;; 5;;    %(tD 0s 03 0u|| 0PUVY[^V^P_ 0&"ELL " "c "ell "4	bll	4Cy4 4S>4S>4S>9:4B 

2BMMB$38n$38n$ 38n$ 38n	$
 $ $ $ 
#s(^$N+ +T#s(^ + +D,> 3 B3bll!3 3s 3s 3	bll	  
	
   	.d2<<&8 C SV [k & (	-	bll	-<<- 	-
 	-8 (	-	bll	-;;- 	-
 	-( t #*C # #yh yhxM_BLL M_`3c 3D 3lc_bll c_L}
r|| }
@F
 F
RQ
",, Q
hO
",, O
d 49   MM##,ab/
2 j!S	 !# !Hb] b]JO]2<< O]dHT#Y Hs HVK]bll K]\Y	bll	Y*-KKY d
Y ]]	Y6@7 @7FP7 P7f
 
&  2  ro   