
    +j>                        S SK Jr  S SKrS SKJr  S SKJrJr  S SK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  SrSrSSSS	.S
\\R2                     S\S\S\S\\R8                     S\\R8                     S\\   S\R:                  4S jjr " S S\R2                  5      r " S S\R2                  5      r  " S S\R2                  5      r! " S S\R2                  5      r" " S S\5      r#S\#4S jr$g)    )OptionalN)override)IOComfyExtension)MinimaxFileRetrieveResponseMiniMaxModelMinimaxTaskResultResponseMinimaxVideoGenerationRequestMinimaxVideoGenerationResponseSubjectReferenceItem)ApiEndpointdownload_url_to_video_outputpoll_opsync_opupload_images_to_comfyapivalidate_stringr      )imagesubjectaverage_durationclsprompt_textseedmodelr   r   r   returnc                &  #    Uc
  [        USS9  S nUb  [        XSS9I S h  vN S   nS nUb  [        XSS9I S h  vN S   n	[        U	S9/n[        U [	        SSS	9[
        [        [        U5      US UUS S
9S9I S h  vN n
U
R                  nU(       d  [        SU
R                   35      e[        U [	        SSU0S9[        S US9I S h  vN nUR                  nUc  [        S5      e[        U [	        SS[        U5      0S9[        S9I S h  vN nUR                   R"                  nUc  [        SUR%                  5        35      eUR                   R&                  (       a(   [(        R*                  " [-        USSS9I S h  vN 5      $ [(        R*                  " [-        U5      I S h  vN 5      $  GN GN| GN= N N N<! [         a>    [(        R*                  " [-        UR                   R&                  SS9I S h  vN  5      s $ f = f Nb7f)Nr   
field_name   
max_imagesr   )r   /proxy/minimax/video_generationPOSTpathmethod)r   promptcallback_urlfirst_frame_imagesubject_referenceprompt_optimizerresponse_modeldataMiniMax generation failed: %/proxy/minimax/query/video_generationtask_idr&   query_paramsc                 .    U R                   R                  $ Nstatusvaluexs    =/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_minimax.py<lambda>$_generate_mm_video.<locals>.<lambda>H   s    188>>    r.   status_extractorestimated_duration,Request was not successful. Missing file ID./proxy/minimax/files/retrievefile_idr.   3No video was found in the response. Full response: 
      timeoutmax_retries   rL   )r   r   r   r   r   r   r
   r   r2   	Exception	base_respr   r	   rE   intr   filedownload_url
model_dumpbackup_download_urlr   
NodeOutputr   )r   r   r   r   r   r   r   	image_urlr+   subject_urlresponser2   task_resultrE   file_resultfile_urls                   r<   _generate_mm_videor]      s/     }>I4SANNPQR	 6sPQRRTUV1DE:6J5*u%'/!
	 H G5h6H6H5IJKK@PY[bOcd01+ K !!GFGG8	SVW^S_G`a2 K ,,HMkNdNdNfMghii++	=='CHVXfg'h!hii
 ==;HEEFFk O
 S$ "i 	==2;3C3C3W3Wefggg 	 Fs    HF5HF8AH>F;?AHF>AHG AH'G GG H,H-	H8H;H>H HG ;H?H
 	H	HHHc            
           \ rS rSr\S\R                  4S j5       r\  S
S\S\S\	S\R                  4S jj5       rSrg	)MinimaxTextToVideoNodeb   r   c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
SS/SSS9[         R
                  R                  SSSSSSSSS9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                  " SS9S9	$ )Nr_   zMiniMax Text to Videopartner/video/MiniMaxzJGenerates videos synchronously based on a prompt, and optional parameters.r   T )Text prompt to guide the video generation	multilinedefaulttooltipr   T2V-01zT2V-01-Director!Model to use for video generationoptionsrg   rh   r   r       r    ,The random seed used for creating the noise.rg   minmaxstepcontrol_after_generaterh   optional{"type":"usd","usd":0.43}expr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badge)r   SchemaStringInputComboIntVideoOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadger   s    r<   define_schema$MinimaxTextToVideoNode.define_schemac   s    yy,0,d		!"G	    %'89$?	   *+/J!  	0 XX__&'		..		++		##
 4I'
 '	
r?   r   r   r   c           
      D   #    [        U UUUS S [        S9I S h  vN $  N7fN)r   r   r   r   r   r   r]   T2V_AVERAGE_DURATION)r   r   r   r   s       r<   executeMinimaxTextToVideoNode.execute   s3      (#1
 
 	
 
      N)ri   r   )__name__
__module____qualname____firstlineno__classmethodr   r   r   strrQ   rV   r   __static_attributes__r   r?   r<   r_   r_   b   sf    (
bii (
 (
T  	

 
 	

 

 
r?   r_   c                       \ rS rSr\S\R                  4S j5       r\  SS\R                  S\
S\
S\S\R                  4
S jj5       rS	rg
)MinimaxImageToVideoNode   r   c                 .   [         R                  " SSSS[         R                  R                  SSS9[         R                  R                  SS	S
SS9[         R
                  R                  S/ SQSSS9[         R                  R                  SSSSSS	SS	S9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S	[         R                  " SS9S9	$ )Nr   zMiniMax Image to Videorb   UGenerates videos synchronously based on an image and prompt, and optional parameters.r   z/Image to use as first frame of video generationrh   r   Trc   rd   re   r   )zI2V-01-DirectorI2V-01zI2V-01-liver   rj   rk   r   r   rm   r    rn   ro   ru   rv   rx   )r   r   Imager   r   r   r   r   r   r   r   r   r   r   r   s    r<   r   %MinimaxImageToVideoNode.define_schema   s   yy-1,oM   		!"G	    H$?	   *+/J!  	#8 XX__&'		..		++		##
 4Q+
 +	
r?   r   r   r   r   c           
      D   #    [        U UUUUS [        S9I S h  vN $  N7fr   )r]   I2V_AVERAGE_DURATION)r   r   r   r   r   s        r<   r   MinimaxImageToVideoNode.execute   s3      (#1
 
 	
 
r   r   N)r   r   r   r   r   r   r   r   r   r   torchTensorr   rQ   rV   r   r   r   r?   r<   r   r      st    ,
bii ,
 ,
\ 
 
||
 
 	

 
 

 
r?   r   c                       \ rS rSr\S\R                  4S j5       r\  SS\R                  S\
S\
S\S\R                  4
S jj5       rS	rg
)MinimaxSubjectToVideoNode   r   c                    [         R                  " SSSS[         R                  R                  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S	SS	S9/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S	S9$ )Nr   zMiniMax Subject to Videorb   r   r   z2Image of subject to reference for video generationr   r   Trc   rd   re   r   S2V-01rj   rk   r   r   rm   r    rn   ro   )ry   rz   r{   r|   r}   r~   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r<   r   'MinimaxSubjectToVideoNode.define_schema   s    yy/3,oP   		!"G	    %J$?	   *+/J!  	#8 XX__&'		..		++		##
 O(
 (	
r?   r   r   r   r   c           
      D   #    [        U UUUS U[        S9I S h  vN $  N7fr   r   )r   r   r   r   r   s        r<   r   !MinimaxSubjectToVideoNode.execute  s3      (#1
 
 	
 
r   r   N)r   r   r   r   r?   r<   r   r      st    )
bii )
 )
V 
 

 
 	

 
 

 
r?   r   c                       \ rS rSr\S\R                  4S j5       r\      SS\S\	S\
\R                     S\S	\	S
\S\S\R                  4S jj5       rSrg)MinimaxHailuoVideoNodei#  r   c                    [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
SSSS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SS9[         R                  R                  SS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MiniMax Hailuo Videorb   z^Generates videos from prompt, with optional start frame using the new MiniMax Hailuo-02 model.r   Trc   z*Text prompt to guide the video generation.re   r   r   rm   r    rn   ro   r*   z=Optional image to use as the first frame to generate a video.)rh   rt   r,   z:Optimize prompt to improve generation quality when needed.)rg   rh   rt   duration   rH   z*The length of the output video in seconds.)rl   rg   rh   rt   
resolution768P1080PzJThe dimensions of the video display. 1080p is 1920x1080, 768p is 1366x768.)widgetsa  
                (
                  $prices := {
                    "768p": {"6": 0.28, "10": 0.56},
                    "1080p": {"6": 0.49}
                  };
                  $resPrices := $lookup($prices, $lowercase(widgets.resolution));
                  $price := $lookup($resPrices, $string(widgets.duration));
                  {"type":"usd","usd": $price ? $price : 0.43}
                )
                )
depends_onrw   rx   )r   r   r   r   r   r   Booleanr   r   r   r   r   r   r   r   PriceBadgeDependsr   s    r<   r   $MinimaxHailuoVideoNode.define_schema$  s{   yy,/,x		!"H	    *+/J!  	 '[!  
 

  & X!	 !  GH!    #W-"h!  G*V XX__&'		..		++		##
 //z8RS
oE
 E	
r?   Nr   r   r*   r,   r   r   r   c                 D  #    Uc
  [        USS9  US:X  a%  UR                  5       S:X  a  US:w  a  [        S5      eS nUb  [        XSS9I S h  vN S	   n[	        U [        S
SS9[        [        [        U5      US UUUUS9S9I S h  vN n	U	R                  n
U
(       d  [        SU	R                   35      eUS:X  a  SOSn[        U [        SSU
0S9[        S US9I S h  vN nUR                  nUc  [        S5      e[	        U [        SS[        U5      0S9[        S9I S h  vN nUR                   R"                  nUc  [        SUR%                  5        35      eUR                   R&                  (       a(   [(        R*                  " [-        USSS9I S h  vN 5      $ [(        R*                  " [-        U5      I S h  vN 5      $  GNz GND N N N9! [         a>    [(        R*                  " [-        UR                   R&                  S S!9I S h  vN  5      s $ f = f N_7f)"Nr   r   MiniMax-Hailuo-02r   r   zZWhen model is MiniMax-Hailuo-02 and resolution is 1080P, duration is limited to 6 seconds.r    r!   r   r#   r$   r%   )r   r(   r)   r*   r,   r   r   r-   r0   r   x      r1   r2   r3   c                 .    U R                   R                  $ r6   r7   r:   s    r<   r=   0MinimaxHailuoVideoNode.execute.<locals>.<lambda>  s    qxx~~r?   r@   rC   rD   rE   rF   rG   rH   rI   rJ   rM   rN   )r   upperrO   r   r   r   r   r
   r   r2   rP   r   r	   rE   rQ   r   rR   rS   rT   rU   r   rV   r   )r   r   r   r*   r,   r   r   r   rW   rY   r2   r   rZ   rE   r[   r\   s                   r<   r   MinimaxHailuoVideoNode.executem  s>     $KMB''J,<,<,>',IhZ[ml 
 	(8\]^^`abI >vN9."5)"!"+!1!%	
 
 ""9(:L:L9MNOO","63C#DT]_fSgh45/
 
 %%?JKK#<IWZ[bWcKde6
 
 ##00QR]RhRhRjQklmm//}}+GZ\jk+l%lmm
 }}#?#IIJJe _
(

 &m }}6{7G7G7[7[ijkkk  Js   AH G8H G
AH G AH #G$AH 9G GG H >H?	H 
H H H G ;HH
	HH HH r   )r   NTr   r   r   )r   r   r   r   r   r   r   r   r   rQ   r   r   r   boolrV   r   r   r   r?   r<   r   r   #  s    F
bii F
 F
P  48!% (GKGK GK $ELL1	GK
 GK GK GK GK 
GK GKr?   r   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)MinimaxExtensioni  r   c                 ,   #    [         [        [        /$ 7fr6   )r_   r   r   )selfs    r<   get_node_listMinimaxExtension.get_node_list  s      ##"	
 	
s   r   N)r   r   r   r   r   listtyper   	ComfyNoder   r   r   r?   r<   r   r     s)    
T$r||*<%= 
 
r?   r   c                     #    [        5       $ 7fr6   )r   r   r?   r<   comfy_entrypointr     s     s   )%typingr   r   typing_extensionsr   comfy_api.latestr   r   comfy_api_nodes.apis.minimaxr   r   r	   r
   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   rQ   r   rV   r]   r_   r   r   r   r   r   r   r?   r<   <module>r      s*     & /      %)&*&*CG	bll	CG CG 	CG
 CG ELL!CG ell#CG smCG ]]CGL;
R\\ ;
|@
bll @
F=
 =
@RKR\\ RKj
~ 
 0 r?   