o
    i                    @   s  d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZ dZdZdZdZ d	Z!	
d4de"ej# de$de	eB eB de%de&e f
ddZ'G dd dej#Z(G dd dej#Z)G dd dej#Z*G dd dej#Z+G dd dej#Z,G dd dej#Z-G dd dej#Z.G d d! d!ej#Z/G d"d# d#ej#Z0d$e%de&fd%d&Z1G d'd( d(ej#Z2G d)d* d*ej#Z3G d+d, d,ej#Z4G d-d. d.ej#Z5G d/d0 d0eZ6de6fd1d2Z7d3S )5    )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              	      s   t | t|ddt|dI d H }|jdkrtd|j t| tt|j dt	dd d	d d
d |dI d H }|j
sFtd|j d|j |j
S )NPOST)pathmethod)endpointresponse_modeldatafailedzVidu request failed. Code: )r"   c                 S      | j S N)stater r-   8/mnt/c/Users/fbmor/ComfyUI/comfy_api_nodes/nodes_vidu.py<lambda>7       zexecute_task.<locals>.<lambda>c                 S   r(   r)   )progressr+   r-   r-   r.   r/   8   r0   c                 S   s   | j d ur
| j d S d S )Ng{Gzt?)creditsr+   r-   r-   r.   r/   9   s    )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responser-   r-   r.   execute_task%   s.   

	r>   c                   @   sH   e Zd Zedd Zededededededed	ed
ejfddZ	dS )ViduTextToVideoNodec                 C   s   t jddddt jjddgddt jjd	d
ddt jjdddddt jjdd
dt jjdddddt jjd
dd
d	t jjdg ddd
dt jjddgdd
d
dt jjdg d d!d
d
dgt j	 gt j
jt j
jt j
jgd
t jd"d#d$	S )%Nr?   zVidu Text To Video Generationapi node/video/Vidu!Generate video from a text promptmodelviduq1
Model nameoptionstooltippromptT*A textual description for video generation	multilinerG   duration      'Duration of the output video in secondsdefaultminmaxstepdisplay_moderG   optionalseedr   (Seed for video generation (0 for random)rQ   rR   rS   rT   rU   control_after_generaterG   rV   aspect_ratio16:99:161:1$The aspect ratio of the output videorF   rG   rV   
resolution1080p-Supported values may vary by model & durationrF   rG   rV   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   r-   r-   r.   define_schemaE   s   
2z!ViduTextToVideoNode.define_schemarB   rH   rL   rW   r\   rc   rh   r    c           
   	      sP   |st dt|||||||d}t| t|I d H }	tt|	d jI d H S )N1The prompt field is required and cannot be empty.rB   rH   rL   rW   r\   rc   rh   r   )
ValueErrorr   r>   VIDU_TEXT_TO_VIDEOr   
NodeOutputr   url)
r   rB   rH   rL   rW   r\   rc   rh   r   resultsr-   r-   r.   execute   s   	zViduTextToVideoNode.executeN)
__name__
__module____qualname__classmethodr   strintr   r   r   r-   r-   r-   r.   r?   C   s*    
E	r?   c                   @   J   e Zd Zedd Zededejdedededed	ed
e	j
fddZdS )ViduImageToVideoNodec                 C   s   t jddddt jjddgddt jjd	d
dt jjddddddt jjdddddt jjdddt jjdddddt jjdddd	t jjddgddddt jjdg d d!dddgt j	
 gt jjt jjt jjgdt jd"d#d$	S )%Nr   zVidu Image To Video Generationr@   z-Generate video from image and optional promptrB   rC   rD   rE   imagez=An image to be used as the start frame of the generated videorG   rH   T rI   )rK   rQ   rG   rV   rL   rM   rN   rO   rP   rW   r   rX   rY   rZ   rc   rd   re   rf   rh   ri   rn   ro   rp   rr   r   r|   r}   r   Imager~   r   r   r   r   r   r   r   r   r   r   r   r-   r-   r.   r      s   
2z"ViduImageToVideoNode.define_schemarB   r   rH   rL   rW   rc   rh   r    c           
         sz   t |dkrtdt|dd t||||||d}t| |dddI d H |_t| t|I d H }	t	t
|	d jI d H S )	NrN    Only one input image is allowed.rN      r   rN   rB   rH   rL   rW   rc   rh   	image/png
max_images	mime_typer   )r   r   r   r   r   imagesr>   VIDU_IMAGE_TO_VIDEOr   r   r   r   )
r   rB   r   rH   rL   rW   rc   rh   r   r   r-   r-   r.   r      s(   zViduImageToVideoNode.executeNr   r   r   r   r   r   r   r   r   r   r   r   r-   r-   r-   r.   r      s*    
E	r   c                   @   sN   e Zd Zedd Zededejdedededed	ed
ede	j
fddZdS )ViduReferenceVideoNodec                 C   s   t jddddt jjddgddt jjd	d
dt jjddddt jjdddddt jjdddt jjdddddt jjdddd	t jjdg ddddt jjddgd ddd!t jjd"g d#d$ddd!gt j	
 gt jjt jjt jjgdt jd%d&d'	S )(Nr   z"Vidu Reference To Video Generationr@   z0Generate video from multiple images and a promptrB   rC   rD   rE   r   zXImages to use as references to generate a video with consistent subjects (max 7 images).r   rH   TrI   rJ   rL   rM   rN   rO   rP   rW   r   rX   rY   rZ   r\   r]   ra   rb   rc   rd   re   rf   rh   ri   rn   ro   rp   rr   r   r   r-   r-   r.   r     s   
6z$ViduReferenceVideoNode.define_schemarB   r   rH   rL   rW   r\   rc   rh   r    c	              	      s   |st dt|}	|	dkrt d|D ]}
t|
dd t|
ddd qt|||||||d}t| |dd	d
I d H |_t| t|I d H }t	
t|d jI d H S )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   r>   VIDU_REFERENCE_VIDEOr   r   r   r   )r   rB   r   rH   rL   rW   r\   rc   rh   ar   r   r   r-   r-   r.   r   Y  s4   	zViduReferenceVideoNode.executeNr   r-   r-   r-   r.   r     s.    
I	
r   c                   @   P   e Zd Zedd Zededejdejdededed	ed
ede	j
fddZdS )ViduStartEndToVideoNodec                 C   s   t jddddt jjddgddt jjd	d
dt jjdddt jjdddddt jjdddddt jjdddt jjdddddt jjdddd	t jjddgddddt jjd g d!d"dddgt j	
 gt jjt jjt jjgdt jd#d$d%	S )&Nr   z"Vidu Start End To Video Generationr@   z7Generate a video from start and end frames and a promptrB   rC   rD   rE   first_framezStart framer   	end_framez	End framerH   TrI   )rK   rG   rV   rL   rM   rN   rO   rP   rW   r   rX   rY   rZ   rc   rd   re   rf   rh   ri   rn   ro   rp   rr   r   r   r-   r-   r.   r     s   
5z%ViduStartEndToVideoNode.define_schemarB   r   r   rH   rL   rW   rc   rh   r    c	                    sr   t ||dddd t||||||d}	 fdd||fD I d H |	_t t|	I d H }
tt|
d jI d H S )	N皙?      ?Fmin_relmax_relstrictr   c                    (   g | ]}t  |d ddI dH d qS rN   r   r   Nr   r   .0framer   r-   r.   
<listcomp>  
    z3ViduStartEndToVideoNode.execute.<locals>.<listcomp>r   )	r   r   r   r>   VIDU_START_END_VIDEOr   r   r   r   r   rB   r   r   rH   rL   rW   rc   rh   r   r   r-   r   r.   r     s   
zViduStartEndToVideoNode.executeNr   r-   r-   r-   r.   r     s.    
H	
r   c                   @   sH   e Zd Zedd Zededededededed	ed
ej	fddZ
dS )Vidu2TextToVideoNodec                 C   s   t jddddt jjddgdt jjdd	d
dt jjdddddt jjdt jjdddddt jjd	dt jjdg ddt jjdddgd	dt j	jdddd	dgt j
 gt jjt jjt jjgd	t jt jddgdd d!d"	S )#Nr   zVidu2 Text-to-Video Generationr@   rA   rB   viduq2rF   rH   TUA textual description for video generation, with a maximum length of 2000 characters.rJ   rL   rM   rN   
   rQ   rR   rS   rT   rU   rW   r   rX   rQ   rR   rS   rT   rU   r[   r\   r^   r_   3:44:3r`   rc   720prd   rF   rg   background_musicFz7Whether to add background music to the generated video.rQ   rG   rg   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_onrq   rr   )r   r|   r}   r   r~   r   r   sliderr   Booleanr   r   r   r   r   r   r   PriceBadgeDependsr   r-   r-   r.   r     sb   	"z"Vidu2TextToVideoNode.define_schemarB   rH   rL   rW   r\   rc   r   r    c           	         sN   t |ddd t| tt|||||||dI d H }tt|d jI d H S )NrN     
min_length
max_length)rB   rH   rL   rW   r\   rc   bgmr   r   r>   r   r   r   r   r   r   )	r   rB   rH   rL   rW   r\   rc   r   r   r-   r-   r.   r   (  s    
zVidu2TextToVideoNode.executeN)r   r   r   r   r   r   r   boolr   r   r   r-   r-   r-   r.   r     s*    
=	r   c                   @   r   )Vidu2ImageToVideoNodec                 C   s   t jddddt jjdg ddt jjdd	d
t jjdddddt jjdddddt jjdt jjdddddt jj	ddt jjdddgddt jjdg dddd gt j
 gt jjt jjt jjgdt jt jg d!d"d#d$d%	S )&Nr   zVidu2 Image-to-Video Generationr@   6Generate a video from an image and an optional prompt.rB   zviduq2-pro-fast
viduq2-providuq2-turbor   r   >An image to be used as the start frame of the generated video.r   rH   Tr   CAn optional text prompt for video generation (max 2000 characters).rK   rQ   rG   rL   rM   rN   r   r   rW   r   rX   r   rc   r   rd   r   rh   ri   /The movement amplitude of objects in the frame.rF   rG   rg   rB   rL   rc   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   rr   r   r|   r}   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r-   r.   r   F  sr   	*z#Vidu2ImageToVideoNode.define_schemarB   r   rH   rL   rW   rc   rh   r    c           	         s~   t |dkrtdt|dd t|dd t| tt||||||t| |dddI d H d	I d H }t	t
|d
 jI d H S )NrN   r   r   r   r   r   r   r   rB   rH   rL   rW   rc   rh   r   r   )r   r   r   r   r>   r   r   r   r   r   r   r   )	r   rB   r   rH   rL   rW   rc   rh   r   r-   r-   r.   r     s0   

zVidu2ImageToVideoNode.executeNr   r-   r-   r-   r.   r   D  s*    
[	r   c                   @   sT   e Zd Zedd Zededejjdede	de
de
d	ed
ededejfddZdS )Vidu2ReferenceVideoNodec                 C   s  t jddddt jjddgdt jjdt jjt jd	g d
ddddt jjddddt jjdddddt j	jdddddt j
jdt j	jdddddt j
jddt jjdg d dt jjd!d"d#gdd$t jjd%g d&d'dd(g	t j gt jjt jjt jjgdt jt jg d)d*d+d,d-	S ).Nr   z#Vidu2 Reference-to-Video Generationr@   z=Generate a video from multiple reference images and a prompt.rB   r   r   subjectsreference_images)subject1subject2subject3subject4subject5subject6subject7rN   )namesrR   zFor each subject, provide up to 3 reference images (7 images total across all subjects). Reference them in prompts via @subject{subject_id}.)templaterG   rH   Tz_When enabled, the video will include generated speech and background music based on the prompt.rJ   audioFzZWhen enabled video will contain generated speech and background music based on the prompt.r   rL   rM   r   r   rW   r   rX   r   r\   )r^   r_   r   r   r`   rc   r   rd   r   rh   ri   r   r   )r   rL   rc   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   rr   )r   r|   r}   r   AutogrowTemplateNamesr   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r-   r.   r     s   

	3z%Vidu2ReferenceVideoNode.define_schemarB   r   rH   r   rL   rW   r\   rc   rh   r    c
                    s   t |ddd d}
|D ]&}t|| dkrtd|| D ]}|
d7 }
t|dd t|d	d	d
 qq|
dkr;tdg }|D ]}|t|t| || ddd| dI d H d q?t||||||||	|d	}t	| t
|I d H }tt|d jI d H S )NrN   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   )	rB   rH   r   rL   rW   r\   rc   rh   r   )r   r   r   r   r   appendr   r   r   r>   r   r   r   r   r   )r   rB   r   rH   r   rL   rW   r\   rc   rh   total_imagesiimsubjects_paramr   r   r-   r-   r.   r     sP   
zVidu2ReferenceVideoNode.executeN)r   r   r   r   r   r   r   r   Typer   r   r   r   r-   r-   r-   r.   r     s2    
O	
r   c                   @   r   )Vidu2StartEndToVideoNodec                 C   s   t jddddt jjdg ddt jdt jd	t jjd
dddt jjdddddt jjdt jjdddddt jj	ddt jjdddgddt jjdg ddddgt j
 gt jjt jjt jjgdt jt jg d d!d"d#d$	S )%Nr
  z)Vidu2 Start/End Frame-to-Video Generationr@   @Generate a video from a start frame, an end frame, and a prompt.rB   r   r   r   r   rH   T)Prompt description (max 2000 characters).rJ   rL   rM         rN   r   rW   r   rX   r   rc   r   rd   r   rh   ri   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   rr   r   r   r-   r-   r.   r   O  sd   

	#z&Vidu2StartEndToVideoNode.define_schemarB   r   r   rH   rL   rW   rc   rh   r    c	              
      s   t |dd t|dkrtdt|dkrtdt||dddd	 t|||||| fd
d||fD I d H d}	t t|	I d H }
tt	|
d j
I d H S )Nr   r   rN   z2Only one input image is allowed for `first_frame`.z0Only one input image is allowed for `end_frame`.r   r   Fr   c                    r   r   r   r   r   r-   r.   r     r   z4Vidu2StartEndToVideoNode.execute.<locals>.<listcomp>r   r   )r   r   r   r   r   r>   r   r   r   r   r   r   r-   r   r.   r     s(   

z Vidu2StartEndToVideoNode.executeNr   r-   r-   r-   r.   r
  M  s.    
S	
r
  c                   @   sL   e Zd Zedd Ze	ddedejdede	dej
dB d	ejfd
dZdS )ViduExtendVideoNodec                 C   s  t jddddt jjdt jdt jjddd	d
d	t jjddt jjdddgddgt jdt jjddd	d
d	t jjddt jjdddgddggddt j	jdddt j
jdddddt jjdd	ddd	t jjddt jjd dd!gt j	 gt jjt jjt jjgdt jt jg d"d#d$d%d&	S )'Nr  zVidu Video Extensionr@   z9Extend an existing video by generating additional frames.rB   r   rL   r   rN   r   z*Duration of the extended video in seconds.rQ   rR   rS   rT   rU   rG   rc   r   rd   Resolution of the output video.rE   r   z!Model to use for video extension.videozThe source video to extend.r   rH   Tr   zEAn optional text prompt for the extended video (max 2000 characters).r   rW   r   rX   r   r   )rV   rB   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   rr   )r   r|   DynamicCombor   Optionr   r   r   r}   r   r~   r   r   r   r   r   r   r   r   r   r   r-   r-   r.   r     s   		(,	Cz!ViduExtendVideoNode.define_schemaNrB   r  rH   rW   r   r    c                    s   t |dd t|ddd d }|d ur+t|dd t|ddd	 t| |d
dI d H }t| dt|d ||d ||d t| |ddI d H |rH|gnd dddI d H }t	t
|d jI d H S )Nr   r   r   7   )min_durationmax_durationr   r   r   r   zUploading end frame)r  z/proxy/vidu/extendrB   rL   rc   zUploading video)rB   rH   rL   rW   rc   	video_urlr     r   r   )r   r   r   r   r   r>   r
   r   r   r   r   r   )r   rB   r  rH   rW   r   	image_urlr   r-   r-   r.   r   0  s.   		zViduExtendVideoNode.executer)   )r   r   r   r   r   dictr   r   r   r   r   r   r   r   r-   r-   r-   r.   r    s$    
hr  countc                 C   s   g }t d| d D ]:}|tjjd| ddd| ddtjjd| d	| d
dtjjd| ddddtjjd| ddg q	|S )z4Generate input widgets for a given number of frames.rN   rH   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   rL   r   r  r   zDuration for segment z in seconds.r  )	rangeextendr   r~   r   r   r   r   r   )r  rw   r  r-   r-   r.   _generate_frame_inputsQ  s2   


r"  c                   @   sB   e Zd Zedd Zededejdedede	de
jfd	d
ZdS )ViduMultiFrameVideoNodec                 C   s*  t jddddt jjdddgdt jjd	d
dt jjdddddt jjddt jjdddgdt jjdt j	dt
dt j	dt
dt j	dt
dt j	dt
dt j	dt
dt j	d t
d!t j	d"t
d#t j	d$t
d%gd&d'gt j gt jjt jjt jjgdt jt jg d(d)d*d+d,	S )-Nr#  z!Vidu Multi-Frame Video Generationr@   z4Generate a video with multiple keyframe transitions.rB   r   r   r   start_imagezCThe starting frame image. Aspect ratio must be between 1:4 and 4:1.r   rW   rN   r   rX   Tr   rc   r   rd   frames2r  3r  4r   5rM   6   7r   8r  9	   z%Number of keyframe transitions (2-9).rE   )rB   rc   r%  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   rr   )r   r|   r}   r   r   r   r   r   r  r  r"  r   r   r   r   r   r   r   r   r   r-   r-   r.   r   q  s`   	
 z%ViduMultiFrameVideoNode.define_schemarB   r$  rW   rc   r%  r    c                    s  t |dd t|d }g }td|d D ]}t |d|  dd t|d|  dd qt| |d	d
dI d H }	td|d D ](}|t|d|  t| |d|  d	d| ddI d H |d|  d qAt| dt||||	|dd| dI d H }
t	
t|
d jI d H S )Nr   r   r%  rN   r  rH   r   r   r   zUploading start image)r   r  zUploading end image()rL   )rH   	key_imagerL   z/proxy/vidu/multiframe)rB   rW   rc   r$  image_settingsr  r  r   )r   r   r   r   r   r  r   r>   r   r   r   r   r   )r   rB   r$  rW   rc   r%  frame_countr2  r  start_image_urlr   r-   r-   r.   r     sN   	

zViduMultiFrameVideoNode.executeN)r   r   r   r   r   r   r   r   r   r  r   r   r   r-   r-   r-   r.   r#  o  s"    
^r#  c                	   @   s8   e Zd Zedd Zededededej	fddZ
d	S )
Vidu3TextToVideoNodec                 C   sH  t jddddt jjdt jdt jjdg dd	d
t jjdddgdd
t jjdddddt jjddt j	jddddgt jdt jjdg dd	d
t jjdddgdd
t jjdddddt jjddt j	jddddggdd
t j
jddddt jjddd d!dt jjdd"gt j gt jjt jjt jjgdt jt jg d#d$d%d&d'	S )(Nr5  z Vidu Q3 Text-to-Video Generationr@   z"Generate video from a text prompt.rB   
viduq3-pror\   r   z%The aspect ratio of the output video.rE   rc   r   rd   r  rL   rM   rN      (Duration of the output video in seconds.r  r   FNWhen enabled, outputs video with sound (including dialogue and sound effects).rQ   rG   viduq3-turbo"Model to use for video generation.rH   Tr   rJ   rW   r   rX   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   rr   )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     s   		>BSz"Vidu3TextToVideoNode.define_schemarB   rH   rW   r    c                    sf   t |ddd t| tt|d ||d ||d |d |d d	d
dI d H }tt|d jI d H S )NrN   r   r   rB   rL   r\   rc   r   )rB   rH   rL   rW   r\   rc   r   i  r  r   r   )r   rB   rH   rW   r   r-   r-   r.   r   y  s"   	zVidu3TextToVideoNode.executeN)r   r   r   r   r   r  r   r   r   r   r   r-   r-   r-   r.   r5    s    
ur5  c                   @   s>   e Zd Zedd Zededejdede	de
jf
dd	Zd
S )Vidu3ImageToVideoNodec                 C   s0  t jddddt jjdt jdt jjdg dd	d
t jjdddddt jjddt j	jddddgt jdt jjdddgd	d
t jjdddddt jjddt j	jddddggdd
t j
jdddt jjddddd t jjd!dd"d#dt jjdd$gt j gt jjt jjt jjgdt jt jg d%d&d'd(d)	S )*Nr>  z!Vidu Q3 Image-to-Video Generationr@   r   rB   r6  rc   )r   rd   2Kr  rE   rL   rM   rN   r7  r8  r  r   Fr9  r:  r;  r   rd   r<  r   r   r   rH   Tr   r   r   rW   r   rX   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   rr   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     s   		48Nz#Vidu3ImageToVideoNode.define_schemarB   r   rH   rW   r    c                    sz   t |dd t|dd t| tt|d ||d ||d |d t| |I d H gd	d
dI d H }tt|d j	I d H S )Nr   r   r   r   rB   rL   rc   r   rB   rH   rL   rW   rc   r   r   i  r  r   )
r   r   r>   r   r   r   r   r   r   r   )r   rB   r   rH   rW   r   r-   r-   r.   r     s$   	zVidu3ImageToVideoNode.executeNr   r   r   r   r   r  r   r   r   r   r   r   r   r-   r-   r-   r.   r>    s    
pr>  c                   @   sD   e Zd Zedd Zededejdejdede	de
jfd	d
ZdS )Vidu3StartEndToVideoNodec                 C   s4  t jddddt jjdt jdt jjddd	gd
dt jjdddddt jjddt j	jddddgt jdt jjddd	gd
dt jjdddddt jjddt j	jddddggddt j
dt j
dt jjddddt jjdddd dt jjdd!gt j gt jjt jjt jjgdt jt jg d"d#d$d%d&	S )'NrC  z+Vidu Q3 Start/End Frame-to-Video Generationr@   r  rB   r6  rc   r   rd   r  rE   rL   rM   rN   r7  r8  r  r   Fr9  r:  r;  r<  r   r   rH   Tr  rJ   rW   r   rX   r   r  r   r=  r   rr   r@  r   r-   r-   r.   r   "  s   		4
8
Kz&Vidu3StartEndToVideoNode.define_schemarB   r   r   rH   rW   r    c              
      s   t |dd t||dddd t|d ||d ||d	 |d
  fdd||fD I d H d}t t|I d H }tt|d jI d H S )Nr   r   r   r   Fr   rB   rL   rc   r   c                    r   r   r   r   r   r-   r.   r     r   z4Vidu3StartEndToVideoNode.execute.<locals>.<listcomp>rA  r   )	r   r   r   r>   r   r   r   r   r   )r   rB   r   r   rH   rW   r   r   r-   r   r.   r     s    	

z Vidu3StartEndToVideoNode.executeNrB  r-   r-   r-   r.   rC     s"    
mrC  c                   @   s(   e Zd Zedeeej  fddZdS )ViduExtensionr    c                    s    t ttttttttt	t
ttgS r)   )r?   r   r   r   r   r   r   r
  r  r#  r5  r>  rC  )selfr-   r-   r.   get_node_list  s   zViduExtension.get_node_listN)	r   r   r   r   listtyper   	ComfyNoderF  r-   r-   r-   r.   rD    s    rD  c                      s   t  S r)   )rD  r-   r-   r-   r.   comfy_entrypoint  s   rJ  N)r   )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   r8   rH  rI  r   r   rG  r>   r?   r   r   r   r   r   r   r
  r  r"  r#  r5  r>  rC  rD  rJ  r-   r-   r-   r.   <module>   sX    (<


bhsh\  x     