
    +j                    D   S SK Jr  S SK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  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  SrSrSrSr S	r! S0S
\"\RF                     S\$S\	\-  \-  S\%S\&\   4
S jjr' " S S\RF                  5      r( " S S\RF                  5      r) " S S\RF                  5      r* " S S\RF                  5      r+ " S S\RF                  5      r, " S S\RF                  5      r- " S S\RF                  5      r. " S S\RF                  5      r/ " S  S!\RF                  5      r0S"\%S\&4S# jr1 " S$ S%\RF                  5      r2 " S& S'\RF                  5      r3 " S( S)\RF                  5      r4 " S* S+\RF                  5      r5 " S, S-\5      r6S\64S. jr7g/)1    )override)IOComfyExtensionInput)FrameSettingSubjectReferenceTaskCreationRequestTaskCreationResponseTaskExtendCreationRequestTaskMultiFrameCreationRequest
TaskResultTaskStatusResponse)ApiEndpointdownload_url_to_video_outputget_number_of_imagespoll_opsync_opupload_image_to_comfyapiupload_images_to_comfyapiupload_video_to_comfyapivalidate_image_aspect_ratiovalidate_image_dimensions&validate_images_aspect_ratio_closenessvalidate_stringvalidate_video_durationz/proxy/vidu/text2videoz/proxy/vidu/img2videoz/proxy/vidu/reference2videoz/proxy/vidu/start-end2videoz/proxy/vidu/tasks/%s/creationsclsvidu_endpointpayloadmax_poll_attemptsreturnc           
        #    [        U [        USS9[        US9I S h  vN nUR                  S:X  a  [	        SUR
                   35      e[        U [        [        UR                  -  S9[        S S S	 US
9I S h  vN nUR                  (       d%  [	        SUR                   SUR                   35      eUR                  $  N NH7f)NPOST)pathmethod)endpointresponse_modeldatafailedzVidu request failed. Code: )r#   c                     U R                   $ N)staters    :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_vidu.py<lambda>execute_task.<locals>.<lambda>7   s    177    c                     U R                   $ r*   )progressr,   s    r.   r/   r0   8   s    QZZr1   c                 >    U R                   b  U R                   S-  $ S $ )Ng{Gzt?)creditsr,   s    r.   r/   r0   9   s    qyy7L!))e"3"VRV"Vr1   )r&   status_extractorprogress_extractorprice_extractorr   z.Vidu request does not contain results. State: z, Error Code: )r   r   r
   r+   RuntimeErrorcoder   VIDU_GET_GENERATION_STATUStask_idr   	creationserr_code)r   r   r   r   task_creation_responseresponses         r.   execute_taskrA   %   s      $+-?+	$  ##x/89O9T9T8UVWW36L6T6TTU)*/V+ H <X^^<LN[c[l[lZmn
 	
 +s#   CCAC<C=ACCc                   l    \ rS rSr\S 5       r\S\S\S\S\S\S\S	\S
\R                  4S j5       r
Srg)ViduTextToVideoNodeC   c                 ^   [         R                  " SSSS[         R                  R                  SS/SS9[         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[         R                  R                  S
SS
S9	[         R                  R                  S/ SQSS
S9[         R                  R                  SS/SS
S
S9[         R                  R                  S/ S QS!S
S
S9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S
[         R                  " S"S#9S$9	$ )%NrC   zVidu Text To Video Generationpartner/video/Vidu!Generate video from a text promptmodelviduq1
Model nameoptionstooltippromptT*A textual description for video generation	multilinerM   duration      'Duration of the output video in secondsdefaultminmaxstepdisplay_moderM   optionalseedr   (Seed for video generation (0 for random)rW   rX   rY   rZ   r[   control_after_generaterM   r\   aspect_ratio16:99:161:1$The aspect ratio of the output videorL   rM   r\   
resolution1080p-Supported values may vary by model & durationrL   rM   r\   advancedmovement_amplitudeautosmallmediumlarge.The movement amplitude of objects in the frame{"type":"usd","usd":0.4}expr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaCombor   StringIntNumberDisplaynumberVideoOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadger   s    r.   define_schema!ViduTextToVideoNode.define_schemaE   s   yy)8);w
LQ		"H   
 !#!1!1!8!8E!  	 "!#!1!1!8!8+/F!  
 "3B!	    $IK!!   (@L!!  S0d ! 		..		++		##
 3B
 B	
r1   rH   rN   rR   r]   rb   ri   rn   r    c           
         #    U(       d  [        S5      e[        UUUUUUUS9n[        U [        U5      I S h  vN n	[        R
                  " [        U	S   R                  5      I S h  vN 5      $  N8 N
7f)N1The prompt field is required and cannot be empty.rH   rN   rR   r]   rb   ri   rn   r   )
ValueErrorr	   rA   VIDU_TEXT_TO_VIDEOr   
NodeOutputr   url)
r   rH   rN   rR   r]   rb   ri   rn   r   resultss
             r.   executeViduTextToVideoNode.execute   sr      PQQ%%!1
 %S*<gFF}}#?
#OOPP GOs!   6A5A1/A5(A3)	A53A5 N)__name__
__module____qualname____firstlineno__classmethodr   strintr   r   r   __static_attributes__r   r1   r.   rC   rC   C   s    C
 C
J QQ Q 	Q
 Q Q Q  Q 
Q Qr1   rC   c                       \ rS rSr\S 5       r\S\S\R                  S\S\	S\	S\S	\S
\
R                  4S j5       rSrg)ViduImageToVideoNode   c                 Z   [         R                  " SSSS[         R                  R                  SS/SS9[         R                  R                  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 QS!SSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " S"S#9S$9	$ )%Nr   zVidu Image To Video GenerationrF   z-Generate video from image and optional promptrH   rI   rJ   rK   imagez=An image to be used as the start frame of the generated videorM   rN   T rO   )rQ   rW   rM   r\   rR   rS   rT   rU   rV   r]   r   r^   r_   r`   ri   rj   rk   rl   rn   ro   rt   ru   rv   rx   r   r   r   r   Imager   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   "ViduImageToVideoNode.define_schema   s   yy*9)Gw
LQ[   		"H!    !#!1!1!8!8E!  	 "!#!1!1!8!8+/F!  
  $IK!!   (@L!!  S0d ! 		..		++		##
 3B
 B	
r1   rH   r   rN   rR   r]   ri   rn   r    c           	      L  #    [        U5      S:  a  [        S5      e[        USS5        [        UUUUUUS9n[	        U USSS9I S h  vN Ul        [        U [        U5      I S h  vN n	[        R                  " [        U	S   R                  5      I S h  vN 5      $  NV N: N7f)	NrT    Only one input image is allowed.rT      r   rT   rH   rN   rR   r]   ri   rn   	image/png
max_images	mime_typer   )r   r   r   r	   r   imagesrA   VIDU_IMAGE_TO_VIDEOr   r   r   r   )
r   rH   r   rN   rR   r]   ri   rn   r   r   s
             r.   r   ViduImageToVideoNode.execute   s       &*?@@#E66:%!1
  9!	 
 
 %S*=wGG}}#?
#OOPP
 HOs6   AB$BB$%B &/B$B"	B$ B$"B$r   Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r1   r.   r   r      s    C
 C
J QQ {{Q 	Q
 Q Q Q  Q 
Q Qr1   r   c                       \ rS rSr\S 5       r\S\S\R                  S\S\	S\	S\S	\S
\S\
R                  4S j5       rSrg)ViduReferenceVideoNodei  c                    [         R                  " SSSS[         R                  R                  SS/SS9[         R                  R                  S	S
S9[         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[         R                  R                  SSSS9	[         R                  R                  S/ SQSSS9[         R                  R                  SS/S SSS!9[         R                  R                  S"/ S#QS$SSS!9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " S%S&9S'9	$ )(Nr   z"Vidu Reference To Video GenerationrF   z0Generate video from multiple images and a promptrH   rI   rJ   rK   r   zXImages to use as references to generate a video with consistent subjects (max 7 images).r   rN   TrO   rP   rR   rS   rT   rU   rV   r]   r   r^   r_   r`   rb   rc   rg   rh   ri   rj   rk   rl   rn   ro   rt   ru   rv   rx   r   r   s    r.   r   $ViduReferenceVideoNode.define_schema  s   yy,=)Jw
LQv   		"H   
 !#!1!1!8!8E!  	 "!#!1!1!8!8+/F!  
 "3B!	    $IK!!   (@L!!  [4l ! 		..		++		##
 3GF
 F	
r1   rH   r   rN   rR   r]   rb   ri   rn   r    c	           
        #    U(       d  [        S5      e[        U5      n	U	S:  a  [        S5      eU H  n
[        U
SS5        [        U
SSS9  M     [	        UUUUUUUS9n[        U USS	S
9I S h  vN Ul        [        U [        U5      I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  NV N: N7f)Nr      z&Too many images, maximum allowed is 7.r   r      	min_width
min_heightr   r   r   r   )r   r   r   r   r	   r   r   rA   VIDU_REFERENCE_VIDEOr   r   r   r   )r   rH   r   rN   rR   r]   rb   ri   rn   ar   r   r   s                r.   r   ViduReferenceVideoNode.executeY  s      PQQ (q5EFFE'vv>%essK  &%!1
  9!	 
 
 %S*>HH}}#?
#OOPP
 IOs6   A.C0C1CC	/C>C?	C	CCr   Nr   r   r1   r.   r   r     s    G
 G
R #Q#Q #Q 	#Q
 #Q #Q #Q #Q  #Q 
#Q #Qr1   r   c                       \ rS rSr\S 5       r\S\S\R                  S\R                  S\S\	S\	S	\S
\S\
R                  4S j5       rSrg)ViduStartEndToVideoNodei  c                    [         R                  " SSSS[         R                  R                  SS/SS9[         R                  R                  S	S
S9[         R                  R                  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[         R                  R                  SSSS9	[         R                  R                  SS/SSSS9[         R                  R                  S / S!QS"SSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " S#S$9S%9	$ )&Nr   z"Vidu Start End To Video GenerationrF   z7Generate a video from start and end frames and a promptrH   rI   rJ   rK   first_framezStart framer   	end_framez	End framerN   TrO   )rQ   rM   r\   rR   rS   rT   rU   rV   r]   r   r^   r_   r`   ri   rj   rk   rl   rn   ro   rt   ru   rv   rx   r   r   s    r.   r   %ViduStartEndToVideoNode.define_schema  s   yy-=)Qw
LQ!)   '   		"H!	    !#!1!1!8!8E!  	 "!#!1!1!8!8+/F!  
  $IK!!   (@L!!  Y3j ! 		..		++		##
 3EE
 E	
r1   rH   r   r   rN   rR   r]   ri   rn   r    c	           
      H  #    [        X#SSSS9  [        UUUUUUS9n	X#4 V
s/ s H  n
[        X
SSS9I S h  vN S	   PM     sn
U	l        [	        U [
        U	5      I S h  vN n[        R                  " [        US	   R                  5      I S h  vN 5      $  N`s  sn
f  N? N7f)
N皙?      ?Fmin_relmax_relstrictr   rT   r   r   r   )
r   r	   r   r   rA   VIDU_START_END_VIDEOr   r   r   r   )r   rH   r   r   rN   rR   r]   ri   rn   r   framer   s               r.   r   ViduStartEndToVideoNode.execute  s      	/{s\`ino%!1
 &1
1 -SAQ\]]_`a1
 %S*>HH}}#?
#OOPP	 ^
 IOsD    B"BB
BB"B/B"B B"BB" B"r   Nr   r   r1   r.   r   r     s    F
 F
P QQ [[Q ;;	Q
 Q Q Q Q  Q 
Q Qr1   r   c                   l    \ rS rSr\S 5       r\S\S\S\S\S\S\S	\S
\	R                  4S j5       rSrg)Vidu2TextToVideoNodei  c                 r   [         R                  " SSSS[         R                  R                  SS/S9[         R                  R                  SS	S
S9[         R
                  R                  SSSSS[         R                  R                  S9[         R
                  R                  SSSSS[         R                  R                  S	S9[         R                  R                  S/ SQS9[         R                  R                  SS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/S9S S!9S"9	$ )#Nr   zVidu2 Text-to-Video GenerationrF   rG   rH   viduq2rL   rN   TUA textual description for video generation, with a maximum length of 2000 characters.rP   rR   rS   rT   
   rW   rX   rY   rZ   r[   r]   r   r^   rW   rX   rY   rZ   r[   ra   rb   rd   re   3:44:3rf   ri   720prj   rL   rm   background_musicFz7Whether to add background music to the generated video.rW   rM   rm   widgetsa(  
                (
                  $is1080 := widgets.resolution = "1080p";
                  $base := $is1080 ? 0.1 : 0.075;
                  $perSec := $is1080 ? 0.05 : 0.025;
                  {"type":"usd","usd": $base + $perSec * (widgets.duration - 1)}
                )
                
depends_onrw   rx   )r   r   r   r   r   r   r   sliderr   Booleanr   r   r   r   r   r   r   PriceBadgeDependsr   s    r.   r   "Vidu2TextToVideoNode.define_schema  s   yy*9);w
;		"s   
 !#!1!1!8!8   "!#!1!1!8!8+/   ~7\]|fg5FQUV

  &!U!	 ! 5 D ! 		..		++		##
 //\8RS
_:
 :	
r1   rH   rN   rR   r]   rb   ri   r   r    c                    #    [        USSS9  [        U [        [        UUUUUUUS95      I S h  vN n[        R
                  " [        US   R                  5      I S h  vN 5      $  N8 N
7f)NrT     
min_length
max_length)rH   rN   rR   r]   rb   ri   bgmr   r   rA   r   r	   r   r   r   r   )	r   rH   rN   rR   r]   rb   ri   r   r   s	            r.   r   Vidu2TextToVideoNode.execute(  sr      	1>$!)%$
 
 }}#?
#OOPP
 Ps!   -A,A(/A,A* 	A,*A,r   N)r   r   r   r   r   r   r   r   boolr   r   r   r   r   r1   r.   r   r     s    ;
 ;
z QQ Q 	Q
 Q Q Q Q 
Q Qr1   r   c                       \ rS rSr\S 5       r\S\S\R                  S\S\	S\	S\S	\S
\
R                  4S j5       rSrg)Vidu2ImageToVideoNodeiD  c                 v   [         R                  " SSSS[         R                  R                  S/ SQS9[         R                  R                  SS	S
9[         R
                  R                  SSSSS9[         R                  R                  SSSSS[         R                  R                  S9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSS/SS9[         R                  R                  S/ SQ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Vidu2 Image-to-Video GenerationrF   6Generate a video from an image and an optional prompt.rH   zviduq2-pro-fast
viduq2-providuq2-turbor   r   >An image to be used as the start frame of the generated video.r   rN   Tr   CAn optional text prompt for video generation (max 2000 characters).rQ   rW   rM   rR   rS   rT   r   r   r]   r   r^   r   ri   r   rj   r   rn   ro   /The movement amplitude of objects in the frame.rL   rM   rm   rH   rR   ri   r   a.  
                (
                  $m := widgets.model;
                  $d := widgets.duration;
                  $is1080 := widgets.resolution = "1080p";
                  $contains($m, "pro-fast")
                    ? (
                        $base := $is1080 ? 0.08 : 0.04;
                        $perSec := $is1080 ? 0.02 : 0.01;
                        {"type":"usd","usd": $base + $perSec * ($d - 1)}
                      )
                    : $contains($m, "pro")
                      ? (
                          $base := $is1080 ? 0.275 : 0.075;
                          $perSec := $is1080 ? 0.075 : 0.05;
                          {"type":"usd","usd": $base + $perSec * ($d - 1)}
                        )
                      : $contains($m, "turbo")
                        ? (
                            $is1080
                              ? {"type":"usd","usd": 0.175 + 0.05 * ($d - 1)}
                              : (
                                  $d <= 1 ? {"type":"usd","usd": 0.04}
                                  : $d <= 2 ? {"type":"usd","usd": 0.05}
                                  : {"type":"usd","usd": 0.05 + 0.05 * ($d - 2)}
                                )
                          )
                        : {"type":"usd","usd": 0.04}
                )
                r   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   #Vidu2ImageToVideoNode.define_schemaF  s   yy+:)Pw0ab\   		"a	    !#!1!1!8!8   "!#!1!1!8!8+/    #W-!  
 (@M!	  E(T ! 		..		++		##
 //8[\ oX
 X	
r1   rH   r   rN   rR   r]   ri   rn   r    c                 P  #    [        U5      S:  a  [        S5      e[        USS5        [        USS9  [	        U [
        [        UUUUUU[        U USSS9I S h  vN S	95      I S h  vN n[        R                  " [        US
   R                  5      I S h  vN 5      $  NF N: N7f)NrT   r   r   r   r   r   r   r   rH   rN   rR   r]   ri   rn   r   r   )r   r   r   r   rA   r   r	   r   r   r   r   r   )	r   rH   r   rN   rR   r]   ri   rn   r   s	            r.   r   Vidu2ImageToVideoNode.execute  s       &*?@@#E66:40$!%#56 )	 
 
$ }}#?
#OOPP
$ Ps6   AB&B B&'B"(/B&B$	B&"B&$B&r   Nr   r   r1   r.   r   r   D  s    Y
 Y
v  Q Q {{ Q 	 Q
  Q  Q  Q   Q 
 Q  Qr1   r   c                       \ rS rSr\S 5       r\S\S\R                  R                  S\S\
S\S\S	\S
\S\S\R                  4S j5       rSrg)Vidu2ReferenceVideoNodei  c                 h   [         R                  " SSSS[         R                  R                  SS/S9[         R                  R                  S[         R                  R                  [         R                  R                  S	5      / S
QSS9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[         R                  R                  S9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  S/ S QS9[         R                  R                  S!S"S#/SS$9[         R                  R                  S%/ S&Q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#Vidu2 Reference-to-Video GenerationrF   z=Generate a video from multiple reference images and a prompt.rH   r   r   subjectsreference_images)subject1subject2subject3subject4subject5subject6subject7rT   )namesrX   zFor each subject, provide up to 3 reference images (7 images total across all subjects). Reference them in prompts via @subject{subject_id}.)templaterM   rN   Tz_When enabled, the video will include generated speech and background music based on the prompt.rP   audioFzZWhen enabled video will contain generated speech and background music based on the prompt.r   rR   rS   r   r   r]   r   r^   r   rb   )rd   re   r   r   rf   ri   r   rj   r   rn   ro   r  r  )r  rR   ri   r   ay  
                (
                  $is1080 := widgets.resolution = "1080p";
                  $base := $is1080 ? 0.375 : 0.125;
                  $perSec := $is1080 ? 0.05 : 0.025;
                  $audioCost := widgets.audio = true ? 0.075 : 0;
                  {"type":"usd","usd": $base + $perSec * (widgets.duration - 1) + $audioCost}
                )
                r   rx   )r   r   r   r   AutogrowTemplateNamesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   %Vidu2ReferenceVideoNode.define_schema  s   yy->)Ww
;!![[66'9:r 7 
J " 	 		"+    

  !x!	 !  !#!1!1!8!8   "!#!1!1!8!8+/   ~7\]|fg5FQUV(@M!	  W1f ! 		..		++		##
 //8[\AL
 L	
r1   rH   r  rN   r  rR   r]   rb   ri   rn   r    c
                    #    [        USSS9  Sn
U HG  n[        X+   5      S:  a  [        S5      eX+    H   nU
S-  n
[        USS5        [	        US	S	S
9  M"     MI     U
S:  a  [        S5      e/ nU H4  nUR                  [        U[        U X+   SSSU 3S9I S h  vN S95        M6     [        UUUUUUUU	US9	n[        U [        U5      I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  Nl N: N7f)NrT   r   r   r      z*Maximum number of images per subject is 3.r   r   r   r   r   z4Too many reference images; the maximum allowed is 7.r   zUploading reference images for )r   r   
wait_label)idr   )	rH   rN   r  rR   r]   rb   ri   rn   r  )r   r   r   r   r   appendr   r   r	   rA   r   r   r   r   r   )r   rH   r  rN   r  rR   r]   rb   ri   rn   total_imagesiimsubjects_paramr   r   s                   r.   r   Vidu2ReferenceVideoNode.execute  s7     	1>A#HK014 !MNNk!+B?)"L "  !STT13A!! !: #$"-%DQC#H" 	  &%!1#

 %S*>HH}}#?
#OOPP+( IOs6   BDD3DD
/D?D 	D
DDr   N)r   r   r   r   r   r   r   r   r  Typer   r   r   r   r   r   r1   r.   r  r    s    M
 M
^ 1Q1Q ++""1Q 	1Q
 1Q 1Q 1Q 1Q 1Q  1Q 
1Q 1Qr1   r  c                       \ rS rSr\S 5       r\S\S\R                  S\R                  S\S\	S\	S	\S
\S\
R                  4S j5       rSrg)Vidu2StartEndToVideoNodeiM  c                    [         R                  " SSSS[         R                  R                  S/ SQS9[         R                  R                  S5      [         R                  R                  S	5      [         R
                  R                  S
SSS9[         R                  R                  SSSSS[         R                  R                  S9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSS/SS9[         R                  R                  S/ SQ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)Vidu2 Start/End Frame-to-Video GenerationrF   @Generate a video from a start frame, an end frame, and a prompt.rH   r   r   r   r   rN   T)Prompt description (max 2000 characters).rP   rR   rS         rT   r   r]   r   r^   r   ri   r   rj   r   rn   ro   r  r  r  r   a  
                (
                  $m := widgets.model;
                  $d := widgets.duration;
                  $is1080 := widgets.resolution = "1080p";
                  $contains($m, "pro-fast")
                    ? (
                        $base := $is1080 ? 0.08 : 0.04;
                        $perSec := $is1080 ? 0.02 : 0.01;
                        {"type":"usd","usd": $base + $perSec * ($d - 1)}
                      )
                    : $contains($m, "pro")
                      ? (
                          $base := $is1080 ? 0.275 : 0.075;
                          $perSec := $is1080 ? 0.075 : 0.05;
                          {"type":"usd","usd": $base + $perSec * ($d - 1)}
                        )
                      : $contains($m, "turbo")
                        ? (
                            $is1080
                              ? {"type":"usd","usd": 0.175 + 0.05 * ($d - 1)}
                              : (
                                  $d <= 2 ? {"type":"usd","usd": 0.05}
                                  : {"type":"usd","usd": 0.05 + 0.05 * ($d - 2)}
                                )
                          )
                        : {"type":"usd","usd": 0.04}
                )
                r   rx   r  r   s    r.   r   &Vidu2StartEndToVideoNode.define_schemaO  s   yy.D)Zw0ab}-{+		"G   
 !#!1!1!8!8   "!#!1!1!8!8+/   |fg5FQUV(@M!	  7!F ! 		..		++		##
 //8[\aP
 P	
r1   rH   r   r   rN   rR   r]   ri   rn   r    c	                   #    [        USS9  [        U5      S:  a  [        S5      e[        U5      S:  a  [        S5      e[        X#SSSS	9  [	        UUUUUUX#4 V	s/ s H  n	[        X	SS
S9I S h  vN S   PM     sn	S9n
[        U [        U
5      I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  N]s  sn	f  N? N7f)Nr   r  rT   z2Only one input image is allowed for `first_frame`.z0Only one input image is allowed for `end_frame`.r   r   Fr   r   r   r   r  )r   r   r   r   r	   r   rA   r   r   r   r   r   )r   rH   r   r   rN   rR   r]   ri   rn   r   r   r   s               r.   r    Vidu2StartEndToVideoNode.execute  s      	40,q0QRR	*Q.OPP.{s\`ino%!1 *55E 1U`aacde5
 %S*>HH}}#?
#OOPP b
 IOsH   ACC1C2C=CC/CCCCCCr   Nr   r   r1   r.   r,  r,  M  s    Q
 Q
f QQ [[Q ;;	Q
 Q Q Q Q  Q 
Q Qr1   r,  c                       \ rS rSr\S 5       r\ SS\S\R                  S\	S\
S\R                  S-  S	\R                  4S
 jj5       rSrg)ViduExtendVideoNodei  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[         R
                  R                  SSS	S
S	[         R                  R                  SS9[         R                  R                  SSS/SS9/5      [         R                  R	                  S[         R
                  R                  SSS	S
S	[         R                  R                  SS9[         R                  R                  SSS/SS9/5      /SS9[         R                  R                  SSS9[         R                  R                  SSSSS9[         R
                  R                  SS	SSS	[         R                  R                  SS9[         R                  R                  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	$ )'Nr6  zVidu Video ExtensionrF   z9Extend an existing video by generating additional frames.rH   r   rR   r   rT   r   z*Duration of the extended video in seconds.rW   rX   rY   rZ   r[   rM   ri   r   rj   Resolution of the output video.rK   r  z!Model to use for video extension.videozThe source video to extend.r   rN   Tr   zEAn optional text prompt for the extended video (max 2000 characters).r  r]   r   r^   r   r   )r\   rH   zmodel.durationzmodel.resolutionr   a2  
                (
                  $m := widgets.model;
                  $d := $lookup(widgets, "model.duration");
                  $res := $lookup(widgets, "model.resolution");
                  $contains($m, "pro")
                    ? (
                        $base := $lookup({"720p": 0.15, "1080p": 0.3}, $res);
                        $perSec := $lookup({"720p": 0.05, "1080p": 0.075}, $res);
                        {"type":"usd","usd": $base + $perSec * ($d - 1)}
                      )
                    : (
                        $base := $lookup({"720p": 0.075, "1080p": 0.2}, $res);
                        $perSec := $lookup({"720p": 0.025, "1080p": 0.05}, $res);
                        {"type":"usd","usd": $base + $perSec * ($d - 1)}
                      )
                )
                r   rx   )r   r   DynamicCombor   Optionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   !ViduExtendVideoNode.define_schema  s4   yy)/)S%%..( "$.,-()())*131A1A1H1H,X !- !" !#$0-3W,=,M !/ !"& ..* "$.,-()())*131A1A1H1H,X !- !" !#$0-3W,=,M !/ !")'P @U & +X 9   		"c	    "!#!1!1!8!8+/   {T:AAF ! 		..		++		##
 //8ghae
 e	
r1   NrH   r:  rN   r]   r   r    c                   #    [        USS9  [        USSS9  S nUb*  [        USS5        [        USSS	9  [	        XS
S9I S h  vN n[        U S[        US   UUS   UUS   [        XSS9I S h  vN U(       a  U/OS S95      I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  N} NS N< N7f)Nr   r  r   7   )min_durationmax_durationr   r   r   r   zUploading end frame)r"  z/proxy/vidu/extendrH   rR   ri   zUploading video)rH   rN   rR   r]   ri   	video_urlr   r   )r   r   r   r   r   rA   r   r   r   r   r   r   )r   rH   r:  rN   r]   r   	image_urlr   s           r.   r   ViduExtendVideoNode.execute0  s      	40ABG	 '	66B%i33O6sRghhI$ %Gnz* . 8Pa bb&/	{T
 
 }}#?
#OOPP i c
 PsH   A CC +C.C/CC/C7C8	CCCCr   r*   )r   r   r   r   r   r   dictr   r   r   r   r   r   r   r   r   r   r1   r.   r6  r6    s    f
 f
P  )-QQ {{Q 	Q
 Q ;;%Q 
Q Qr1   r6  countc                 n   / n[        SU S-   5       H  nUR                  [        R                  R	                  SU 3SSSU S3S9[        R
                  R	                  SU 3S	U S
3S9[        R                  R	                  SU 3SSSS[        R                  R                  SU S3S9/5        M     U$ )z4Generate input widgets for a given number of frames.rT   rN   Tr   zText prompt for frame z transition.r  	end_imagezEnd frame image for segment z+. Aspect ratio must be between 1:4 and 4:1.r   rR   r   r0  r   zDuration for segment z in seconds.r8  )	rangeextendr   r   r   r   r   r   r   )rG  r}   r&  s      r.   _generate_frame_inputsrL  P  s    F1eai 		QCL"4QC|D	    sO:1#=hi   qcN!#!1!1!8!83A3lC  	
 !0 Mr1   c                   x    \ rS rSr\S 5       r\S\S\R                  S\	S\S\
S\R                  4S	 j5       rS
rg)ViduMultiFrameVideoNodein  c                 >   [         R                  " SSSS[         R                  R                  SSS/S9[         R                  R                  S	S
S9[         R
                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSS/S9[         R                  R                  S[         R                  R                  S[        S5      5      [         R                  R                  S[        S5      5      [         R                  R                  S[        S5      5      [         R                  R                  S[        S5      5      [         R                  R                  S[        S5      5      [         R                  R                  S [        S!5      5      [         R                  R                  S"[        S#5      5      [         R                  R                  S$[        S%5      5      /S&S'9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S[         R"                  " [         R$                  " / S(QS)9S*S+9S,9	$ )-NrN  z!Vidu Multi-Frame Video GenerationrF   z4Generate a video with multiple keyframe transitions.rH   r   r  r   start_imagezCThe starting frame image. Aspect ratio must be between 1:4 and 4:1.r   r]   rT   r   r^   Tr   ri   r   rj   frames2r0  3r!  4r   5rS   6   7r   8r1  9	   z%Number of keyframe transitions (2-9).rK   )rH   ri   rQ  zframes.duration1zframes.duration2zframes.duration3zframes.duration4zframes.duration5zframes.duration6zframes.duration7zframes.duration8zframes.duration9r   a  
                (
                  $m := widgets.model;
                  $n := $number(widgets.frames);
                  $is1080 := widgets.resolution = "1080p";
                  $d1 := $lookup(widgets, "frames.duration1");
                  $d2 := $lookup(widgets, "frames.duration2");
                  $d3 := $n >= 3 ? $lookup(widgets, "frames.duration3") : 0;
                  $d4 := $n >= 4 ? $lookup(widgets, "frames.duration4") : 0;
                  $d5 := $n >= 5 ? $lookup(widgets, "frames.duration5") : 0;
                  $d6 := $n >= 6 ? $lookup(widgets, "frames.duration6") : 0;
                  $d7 := $n >= 7 ? $lookup(widgets, "frames.duration7") : 0;
                  $d8 := $n >= 8 ? $lookup(widgets, "frames.duration8") : 0;
                  $d9 := $n >= 9 ? $lookup(widgets, "frames.duration9") : 0;
                  $totalDuration := $d1 + $d2 + $d3 + $d4 + $d5 + $d6 + $d7 + $d8 + $d9;
                  $contains($m, "pro")
                    ? (
                        $base := $is1080 ? 0.3 : 0.15;
                        $perSec := $is1080 ? 0.075 : 0.05;
                        {"type":"usd","usd": $n * $base + $perSec * $totalDuration}
                      )
                    : (
                        $base := $is1080 ? 0.2 : 0.075;
                        $perSec := $is1080 ? 0.05 : 0.025;
                        {"type":"usd","usd": $n * $base + $perSec * $totalDuration}
                      )
                )
                r   rx   )r   r   r   r   r   r   r   r   r<  r=  rL  r   r   r   r   r   r   r   r   r   s    r.   r   %ViduMultiFrameVideoNode.define_schemap  s   yy-<)Nw~0NO!a   "!#!1!1!8!8+/   |fg5FG%%..s4J14MN..s4J14MN..s4J14MN..s4J14MN..s4J14MN..s4J14MN..s4J14MN..s4J14MN	 D & !@ ! 		..		++		##
 // #-[[
 [	
r1   rH   rP  r]   ri   rQ  r    c                 J  #    [        USS5        [        US   5      n/ n[        SUS-   5       H&  n[        USU 3   SS5        [        USU 3   SS9  M(     [	        U US	S
S9I S h  vN n	[        SUS-   5       HE  nUR                  [        USU 3   [	        U USU 3   S	SU S3S9I S h  vN USU 3   S95        MG     [        U S[        UUUU	US9SU-  S9I S h  vN n
[        R                  " [        U
S   R                  5      I S h  vN 5      $  N Nm N< N7f)Nr   r   rQ  rT   rI  rN   r   r  r   zUploading start image)r   r"  zUploading end image()rR   )rN   	key_imagerR   z/proxy/vidu/multiframe)rH   r]   ri   rP  image_settings  r   r   )r   r   rJ  r   r   r$  r   rA   r   r   r   r   r   )r   rH   rP  r]   ri   rQ  frame_countr`  r&  start_image_urlr   s              r.   r   ViduMultiFrameVideoNode.execute  sl     	$K@&*+-/q+/*A'1#(?PFVA3<0TB + !9!.	!
 
 q+/*A!!!F1#,/$<1#/"-%9!A#>	%  $hqcN3	 + %$)%+- "K/
 
 }}#?
#OOPP?

 PsI   A&D#(D)AD#/D02D#"D#/D#D!	D#D#D#!D#r   N)r   r   r   r   r   r   r   r   r   r   rF  r   r   r   r   r   r1   r.   rN  rN  n  su    \
 \
| -Q-Q [[-Q 	-Q
 -Q -Q 
-Q -Qr1   rN  c            	       \    \ rS rSr\S 5       r\S\S\S\S\	R                  4S j5       rSrg	)
Vidu3TextToVideoNodei   c                     [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[         R
                  R                  S/ SQS	S
9[         R
                  R                  SSS/SS
9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      [         R                  R	                  S[         R
                  R                  S/ SQS	S
9[         R
                  R                  SSS/SS
9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      /SS
9[         R                  R                  SSSS9[         R                  R                  SSS S!S[         R                  R                  SS"9/[         R                  R                  5       /[         R                  R                  [         R                  R                   [         R                  R"                  /S[         R$                  " [         R&                  " / S#QS$9S%S&9S'9	$ )(Nrg  z Vidu Q3 Text-to-Video GenerationrF   z"Generate video from a text prompt.rH   
viduq3-prorb   r   z%The aspect ratio of the output video.rK   ri   r   rj   r9  rR   rS   rT      (Duration of the output video in seconds.r8  r  FNWhen enabled, outputs video with sound (including dialogue and sound effects).rW   rM   viduq3-turbo"Model to use for video generation.rN   Tr   rP   r]   r   r^   r   r;  r   U  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $d := $lookup(widgets, "model.duration");
                  $contains(widgets.model, "turbo")
                    ? (
                        $rate := $lookup({"720p": 0.06, "1080p": 0.08}, $res);
                        {"type":"usd","usd": $rate * $d}
                      )
                    : (
                        $rate := $lookup({"720p": 0.15, "1080p": 0.16}, $res);
                        {"type":"usd","usd": $rate * $d}
                      )
                )
                r   rx   )r   r   r<  r   r=  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   "Vidu3TextToVideoNode.define_schema  s   yy*;)<%%..( "$2,Q,S !/ !"
 !#$0-3W,=,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !")< ..* "$2,Q,S !/ !"
 !#$0-3W,=,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !")?=| AA & AD 		"s   
 "!#!1!1!8!8+/  QQf ! 		..		++		##
 //8ghAr
 r	
r1   rH   rN   r]   r    c                    #    [        USSS9  [        U [        [        US   UUS   UUS   US   US   S	9S
S9I S h  vN n[        R
                  " [        US   R                  5      I S h  vN 5      $  N8 N
7f)NrT   r   r   rH   rR   rb   ri   r  )rH   rN   rR   r]   rb   ri   r  i  rb  r   r   )r   rH   rN   r]   r   s        r.   r   Vidu3TextToVideoNode.executex  s      	1>$Gnz*">2 .Gn "
 
 }}#?
#OOPP
 Ps!   ;A:A6/A:-A8.	A:8A:r   N)r   r   r   r   r   r   rF  r   r   r   r   r   r   r   r1   r.   rg  rg     s[    s
 s
j QQ Q 	Q
 
Q Qr1   rg  c                   t    \ rS rSr\S 5       r\S\S\R                  S\	S\
S\R                  4
S j5       rS	rg
)Vidu3ImageToVideoNodei  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[         R
                  R                  S/ SQS	S
9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      [         R                  R	                  S[         R
                  R                  SSS/S	S
9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      /SS
9[         R                  R                  SSS9[         R                  R                  SSSSS 9[         R                  R                  S!SS"S#S[         R                  R                  SS$9/[         R                  R                  5       /[         R                  R                   [         R                  R"                  [         R                  R$                  /S[         R&                  " [         R(                  " / S%QS&9S'S(9S)9	$ )*Nru  z!Vidu Q3 Image-to-Video GenerationrF   r   rH   ri  ri   )r   rj   2Kr9  rK   rR   rS   rT   rj  rk  r8  r  Frl  rm  rn  r   rj   ro  r   r  r   rN   Tr   r  r  r]   r   r^   r   r;  r   a`  
                (
                  $res := $lookup(widgets, "model.resolution");
                  $d := $lookup(widgets, "model.duration");
                  $contains(widgets.model, "turbo")
                    ? (
                        $rate := $lookup({"720p": 0.06, "1080p": 0.08}, $res);
                        {"type":"usd","usd": $rate * $d}
                      )
                    : (
                        $rate := $lookup({"720p": 0.15, "1080p": 0.16, "2k": 0.2}, $res);
                        {"type":"usd","usd": $rate * $d}
                      )
                )
                r   rx   r   r   r<  r   r=  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r.   r   #Vidu3ImageToVideoNode.define_schema  sc   yy+<)P%%..( "$0,C,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !"2 ..* "$0-3W,=,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !"53h Am & 7p \   		"a	    "!#!1!1!8!8+/  GL\ ! 		..		++		##
 //8ghwm
 m	
r1   rH   r   rN   r]   r    c                 2  #    [        USS5        [        USS9  [        U [        [	        US   UUS   UUS   US   [        X5      I S h  vN /S	9S
S9I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  NF N: N7f)Nr   r   r   r  rH   rR   ri   r  rH   rN   rR   r]   ri   r  r   i  rb  r   )
r   r   rA   r   r	   r   r   r   r   r   )r   rH   r   rN   r]   r   s         r.   r   Vidu3ImageToVideoNode.execute  s      	$E66:40$Gnz* .Gn6sBBC "
 
 }}#?
#OOPP	 C
 Ps6   AB
BBB/BB		BBBr   Nr   r   r   r   r   r   rF  r   r   r   r   r   r   r   r   r   r1   r.   ru  ru    sj    n
 n
` QQ {{Q 	Q
 Q 
Q Qr1   ru  c                       \ rS rSr\S 5       r\S\S\R                  S\R                  S\	S\
S\R                  4S	 j5       rS
rg)Vidu3StartEndToVideoNodei  c                    [         R                  " SSSS[         R                  R                  S[         R                  R	                  S[         R
                  R                  SSS	/S
S9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      [         R                  R	                  S[         R
                  R                  SSS	/S
S9[         R                  R                  SSSSS[         R                  R                  SS9[         R                  R                  SSSS9/5      /SS9[         R                  R                  S5      [         R                  R                  S5      [         R                  R                  SSSS9[         R                  R                  SSSS S[         R                  R                  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+Vidu Q3 Start/End Frame-to-Video GenerationrF   r.  rH   ri  ri   r   rj   r9  rK   rR   rS   rT   rj  rk  r8  r  Frl  rm  rn  ro  r   r   rN   Tr/  rP   r]   r   r^   r   r;  r   rp  r   rx   rx  r   s    r.   r   &Vidu3StartEndToVideoNode.define_schema!  sh   yy.F)Z%%..( "$0-3W,=,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !"2 ..* "$0-3W,=,M !/ !"
 !#$.,-()(*)*131A1A1H1H,V !- !" !#

 0 0$+,1-N !1 !"53h Am & 7p }-{+		"G   
 "!#!1!1!8!8+/  AIV ! 		..		++		##
 //8ghqj
 j	
r1   rH   r   r   rN   r]   r    c                 h  #    [        USS9  [        X#SSSS9  [        US   UUS   UUS	   US
   X#4 Vs/ s H  n[        XSSS9I S h  vN S   PM     snS9n[	        U [
        U5      I S h  vN n[        R                  " [        US   R                  5      I S h  vN 5      $  N]s  snf  N? N7f)Nr   r  r   r   Fr   rH   rR   ri   r  rT   r   r   r   r{  )
r   r   r	   r   rA   r   r   r   r   r   )	r   rH   r   r   rN   r]   r   r   r   s	            r.   r    Vidu3StartEndToVideoNode.execute  s      	40.{s\`ino%.:&\*. *55E 1U`aacde5
 %S*>HH}}#?
#OOPP b
 IOsF   3B2B)	B'
B)B2.B.//B2B0B2'B))B20B2r   Nr}  r   r1   r.   r  r    sy    k
 k
Z QQ [[Q ;;	Q
 Q Q 
Q Qr1   r  c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)ViduExtensioni  r    c                    #    [         [        [        [        [        [
        [        [        [        [        [        [        [        /$ 7fr*   )rC   r   r   r   r   r   r  r,  r6  rN  rg  ru  r  )selfs    r.   get_node_listViduExtension.get_node_list  s8        "# !#$# !$
 	
s   AAr   N)r   r   r   r   r   listtyper   	ComfyNoder  r   r   r1   r.   r  r    s)    
T$r||*<%= 
 
r1   r  c                     #    [        5       $ 7fr*   )r  r   r1   r.   comfy_entrypointr    s     ?s   N)ra  )8typing_extensionsr   comfy_api.latestr   r   r   comfy_api_nodes.apis.vidur   r   r	   r
   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r  r  r   r   r  rA   rC   r   r   r   r   r   r  r,  r6  rL  rN  rg  ru  r  r  r  r   r1   r.   <module>r     s   & 6 6	 	 	     . - 4 4 =  !		bll	 !#<<?\\ 	
 
*<_Q",, _QDeQ2<< eQPpQR\\ pQfeQbll eQPYQ2<< YQxQBLL QDDQbll DQNuQr|| uQpHQ",, HQV# $ <OQbll OQdNQ2<< NQbKQBLL KQ\HQr|| HQV
N 
( r1   