
    +j_                     4   S SK r S SKJr  S SKJr  S SKJrJrJrJ	r	  S SK
JrJrJrJrJrJrJr  S SKJrJrJrJrJr  SrSS	S
SSSS.r " S S\R4                  5      r " S S\R4                  5      r " S S\R4                  5      r " S S\5      rS\4S jrg)    N)BytesIO)override)IOComfyExtensionInput	InputImpl)VeoGenVidPollRequestVeoGenVidPollResponseVeoGenVidRequestVeoGenVidResponseVeoRequestInstanceVeoRequestInstanceImageVeoRequestParameters)ApiEndpointdownload_url_to_video_outputpoll_opsync_optensor_to_base64_string    veo-2.0-generate-001zveo-3.1-generate-001zveo-3.1-fast-generate-001zveo-3.1-lite-generate-001veo-3.0-generate-001veo-3.0-fast-generate-001)r   veo-3.1-generateveo-3.1-fast-generateveo-3.1-liter   r   c                   N    \ rS rSrSr\S 5       r\         SS j5       rSrg)VeoVideoGenerationNode#   z
Generates videos from text prompts using Google's Veo API.

This node can create videos from text descriptions and optional image inputs,
with control over parameters like aspect ratio, duration, and more.
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9[         R
                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  SSSSSS9[         R                  R                  SSS/SSSSS9[         R
                  R                  S S!S!S"S[         R                  R                  SS#SS$9	[         R                  R                  S%S&SS'9[         R                  R                  S(S)/S)S*SS+9/	[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " S/S,9S-S.9S/9	$ )0Nr   zGoogle Veo 2 Video Generationpartner/video/Veoz;Generates videos from text prompts using Google's Veo 2 APIpromptT Text description of the video	multilinedefaulttooltipaspect_ratio16:99:16 Aspect ratio of the output videooptionsr&   r'   negative_prompt8Negative text prompt to guide what to avoid in the videor%   r&   r'   optionalduration_seconds         'Duration of the output video in secondsr&   minmaxstepdisplay_moder'   r1   enhance_promptz0Whether to enhance the prompt with AI assistancer&   r'   r1   advancedperson_generationALLOWBLOCK/Whether to allow generating people in the videor-   r&   r'   r1   r>   seedr       (Seed for video generation (0 for random)r&   r8   r9   r:   r;   control_after_generater'   r1   image2Optional reference image to guide video generationr'   r1   modelr   z'Veo 2 model to use for video generationr-   r&   r'   r1   widgetsz4{"type":"usd","usd": 0.5 * widgets.duration_seconds}
depends_onexpr	node_iddisplay_namecategorydescriptioninputsoutputshiddenis_api_nodeprice_badger   SchemaStringr   ComboIntNumberDisplaynumberBooleanImageVideoOutputHiddenauth_token_comfy_orgapi_key_comfy_org	unique_id
PriceBadgePriceBadgeDependsclss    :/home/wildlama/comfy/ComfyUI/comfy_api_nodes/nodes_veo2.pydefine_schema$VeoVideoGenerationNode.define_schema+   s   yy,8(U		";	    "#V,">	   		%"V!    &!#!1!1!8!8E!  	 

  $ N!! !  '$g.#M!!   "!#!1!1!8!8+/F!  
 P!  
 342E!  {DL ! 		..		++		##
 //9K8LMOgW
 W	
    Nc           
        #    [         U	   n	/ nSU0nUb  [        U5      nU(       a  USS.US'   UR                  U5        UUUUS.nU(       a  X>S'   US:  a  X~S'   U	R                  S	5      S
:X  a	  XS'   SUS'   [	        U [        SU	 S3SS9[        [        UUS9S9I S h  vN nS n[        U [        SU	 S3SS9[        U[        UR                  S9S[        S9I S h  vN nUR                  (       a:  [        SUR                  R                   SUR                  R                    S35      e[#        UR$                  S5      (       a  UR$                  R&                  S:  a  [#        UR$                  S5      (       aR  UR$                  R(                  (       a7  UR$                  R(                  S   nSU SUR$                  R&                   S 3nOS!UR$                  R&                   S 3n[        U5      eUR$                  (       GaE  [#        UR$                  S"5      (       Ga)  UR$                  R*                  (       Ga  [-        UR$                  R*                  5      S:  a  UR$                  R*                  S   n[#        US#5      (       ab  UR.                  (       aQ  [0        R2                  " [4        R6                  " [9        [:        R<                  " UR.                  5      5      5      5      $ [#        US$5      (       aB  UR>                  (       a1  [0        R2                  " [A        UR>                  5      I S h  vN 5      $ [        S%5      e[        S&5      e GN GN| N$7f)'Nr!   	image/pngbytesBase64EncodedmimeTyperI   )aspectRatiopersonGenerationdurationSecondsenhancePromptnegativePromptr   rD   zveo-2.0generateAudioTr|   /proxy/veo/	/generatePOSTpathmethod	instances
parametersresponse_modeldatac                 ,    U R                   (       a  S$ S$ N	completedpendingdone)responses    rp   status_extractor8VeoVideoGenerationNode.execute.<locals>.status_extractor   s     #+--;>Y>rs   /polloperationNameg      @r   r   r   poll_intervalestimated_durationVeo API error:  (code: )raiMediaFilteredCountraiMediaFilteredReasonsz7Content filtered by Google's Responsible AI practices:  (z videos filtered.)z7Content filtered by Google's Responsible AI practices (videosrw   gcsUri.Video returned but no data or URL was provided4Video generation completed but no video was returned)!
MODELS_MAPr   appendfindr   r   r   r   r   r
   r	   nameAVERAGE_DURATION_VIDEO_GENerror	Exceptionmessagecodehasattrr   r   r   r   lenrw   r   
NodeOutputr   VideoFromFiler   base64	b64decoder   r   )ro   r!   r(   r.   r2   r<   r?   rD   rI   rL   generate_audior   instanceimage_base64r   initial_responser   poll_responsereasonerror_messagevideos                        rp   executeVeoVideoGenerationNode.execute   sH     5!	f% 259L;GU`$a!" ( 1/+	

 +:'(!8!%v::i B&*8'*.J'!({5';FK,!#%	"
 
	?
 &{5'7G0-%.33 9

 

 om.A.A.I.I-J(S`SfSfSkSkRllmnoo M**,CDD&&<<q@
 ..0IJJ!**BB&//GGJ"YZ`Yaacdqdzdz  eQ  eQ  dR  Rd  !e"YZgZpZp  [G  [G  ZH  HZ  ![M** """..99&&---M**112Q6!**11!4E u2338P8P}}Y%<%<WVEUEUV[VnVnEo=p%qrruh''ELL}}+G+U%UVVLMMNOOG


b &Vs7   BM!!M">M! M!IM!:M;M!M!M! )	r)   r"   r3   Tr@   r   Nr   F	__name__
__module____qualname____firstlineno____doc__classmethodrq   r   __static_attributes__r   rs   rp   r   r   #   sS     X
 X
t  !$qP qPrs   r   c                   P    \ rS rSrSr\S 5       r\          SS j5       rSrg)Veo3VideoGenerationNode   z<Generates videos from text prompts using Google's Veo 3 API.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QSSSS9[         R                  R                  SSSSSS9[         R
                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  SSSSSS9[         R                  R                  S S!S"/S!S#SSS$9[         R
                  R                  S%S&S&S'S([         R                  R                  SS)SS*9	[         R                  R                  S+S,SS-9[         R                  R                  S./ S/QS0SS19[         R                  R                  S2S3S4SS59/[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                  /S[         R                   " [         R"                  " / S6QS79S8S99S:9	$ );Nr   zGoogle Veo 3 Video Generationr    z;Generates videos from text prompts using Google's Veo 3 APIr!   Tr"   r#   r$   r(   r)   r*   r+   r,   
resolution720p1080p4kr   zQOutput video resolution. 4K is not available for veo-3.1-lite and veo-3.0 models.rM   r.   r/   r0   r2   r4         r6   r7   r<   z)This parameter is deprecated and ignored.r=   r?   r@   rA   rB   rC   rD   r   rE   r5   rF   rG   rI   rJ   rK   rL   )r   r   r   r   r   z'Veo 3 model to use for video generation)r-   r'   r1   r   Fz<Generate audio for the video. Supported by all Veo 3 models.)r&   r'   r1   )rL   r   r   r2   rN   af  
                (
                  $m := widgets.model;
                  $r := widgets.resolution;
                  $a := widgets.generate_audio;
                  $seconds := widgets.duration_seconds;
                  $pps :=
                    $contains($m, "lite")
                      ? ($r = "1080p" ? ($a ? 0.08 : 0.05) : ($a ? 0.05 : 0.03))
                    : $contains($m, "3.1-fast")
                      ? ($r = "4k" ? ($a ? 0.30 : 0.25) : $r = "1080p" ? ($a ? 0.12 : 0.10) : ($a ? 0.10 : 0.08))
                    : $contains($m, "3.1-generate")
                      ? ($r = "4k" ? ($a ? 0.60 : 0.40) : ($a ? 0.40 : 0.20))
                    : $contains($m, "3.0-fast")
                      ? ($a ? 0.15 : 0.10)
                    : ($a ? 0.40 : 0.20);
                  {"type":"usd","usd": $pps * $seconds}
                )
                rP   rS   r]   rn   s    rp   rq   %Veo3VideoGenerationNode.define_schema   sc   yy-8(U		";	    "#V,">	    3"o!   		%"V!    &!#!1!1!8!8E!  	 

  $ G!! !  '$g.#M!!   "!#!1!1!8!8+/F!  
 P!  
  F!   

  $!Z!	 ! aVp ! 		..		++		##
 //8uvK{
 {	
rs   Nc           
        #    US:X  a  SU
;   d  SU
;   a  [        S5      e[        U
   n
SU0/nU	b  [        U	5      nU(       a  USS.US   S	'   UUUS
US.nU(       a  XNS'   US:  a  XS'   SU
;   a  X>S'   [        U [	        SU
 S3SS9[
        [        UUS9S9I S h  vN n[        U [	        SU
 S3SS9[        S [        UR                  S9S[        S9I S h  vN nUR                  (       a:  [        SUR                  R                   SUR                  R                   S35      eUR                  nUR                   nU(       aC  UR"                  =(       d    / nU(       a  SUS    3OSn[        S U S!U S"US#:w  a  S$OS S%35      eUR$                  (       a  UR$                  S   nUR&                  (       aQ  [(        R*                  " [,        R.                  " [1        [2        R4                  " UR&                  5      5      5      5      $ UR6                  (       a1  [(        R*                  " [9        UR6                  5      I S h  vN 5      $ [        S&5      e[        S'5      e GN GN N$7f)(Nr   litez3.0zE4K resolution is not supported by the veo-3.1-lite or veo-3.0 models.r!   ru   rv   r   rI   T)ry   rz   r{   r|   r   r}   rD   zveo-3.1r   r   r   r   r   r   r   r   c                 ,    U R                   (       a  S$ S$ r   r   rs    rp   <lambda>1Veo3VideoGenerationNode.execute.<locals>.<lambda>      aff{'K)'Krs   r         "@r   r   r   r   : r"   2Content blocked by Google's Responsible AI filtersr    videor5   s filtered).r   r   )r   r   r   r   r   r   r   r   r
   r	   r   r   r   r   r   r   r   r   r   rw   r   r   r   r   r   r   r   r   r   )ro   r!   r(   r   r.   r2   r<   r?   rD   rI   rL   r   r   r   r   r   r   r   filtered_countreasonsreason_partr   s                         rp   r   Veo3VideoGenerationNode.execute}  sv     6U?euncdd5!'(	259L?KYd(e	!W% ( 1/!+

 +:'(!8!%v'1|$!({5';FK,!#%	"
 
 &{5'7G0K%4D4I4IJ9
 
 om.A.A.I.I-J(S`SfSfSkSkRllmnoo ))!7766<"G/6Bwqzl+BKD[M R"#611D#")M[Z 
 ??OOA&E''}}Y%<%<WVEUEUV[VnVnEo=p%qrr||}}+G+U%UVVLMMNOOQ

8 &Vs7   BI-I%<I-I(E,I-I+I-(I-+I-r   )
r)   r   r"   r4   Tr@   r   Nr   Fr   r   rs   rp   r   r      sR    F|
 |
|  !$OP OPrs   r   c                       \ rS rSr\S 5       r\S\S\S\S\S\S\S	\R                  S
\R                  S\S\
4S j5       rSrg)Veo3FirstLastFrameNodei  c                 ,   [         R                  " SSSS[         R                  R                  SSSSS	9[         R                  R                  S
SSSS	9[         R                  R                  S/ SQS9[         R                  R                  SSS/SSS9[         R
                  R                  SSSSS[         R                  R                  SS9[         R
                  R                  SSSSS[         R                  R                  SSS9[         R                  R                  S S!S"9[         R                  R                  S#S$S"9[         R                  R                  S%/ S&QS9[         R                  R                  S'SS(S)9/
[         R                  R                  5       /[         R                  R                  [         R                  R                  [         R                  R                   /S[         R"                  " [         R$                  " / S*QS+9S,S-9S.9	$ )/Nr   z&Google Veo 3 First-Last-Frame to Videor    z6Generate video using prompt and first and last frames.r!   Tr"   r#   r$   r.   r/   r   r   )r-   r(   r)   r*   r+   r,   durationr4   r   r   r6   )r&   r8   r9   r:   r;   r'   rD   r   rE   r5   zSeed for video generation)r&   r8   r9   r:   r;   rH   r'   first_framezStart frame)r'   
last_framez	End framerL   )r   r   r   r   zGenerate audio for the video.)r&   r'   )rL   r   r   r   rN   a  
                (
                  $m := widgets.model;
                  $r := widgets.resolution;
                  $ga := widgets.generate_audio;
                  $seconds := widgets.duration;
                  $pps :=
                    $contains($m, "lite")
                      ? ($r = "1080p" ? ($ga ? 0.08 : 0.05) : ($ga ? 0.05 : 0.03))
                    : $contains($m, "fast")
                      ? ($r = "4k" ? ($ga ? 0.30 : 0.25) : $r = "1080p" ? ($ga ? 0.12 : 0.10) : ($ga ? 0.10 : 0.08))
                    : ($r = "4k" ? ($ga ? 0.60 : 0.40) : ($ga ? 0.40 : 0.20));
                  {"type":"usd","usd": $pps * $seconds}
                )
                rP   rS   )r   r^   r_   r   r`   ra   rb   sliderrc   re   rd   rf   rg   rh   ri   rj   rk   rl   rm   rn   s    rp   rq   $Veo3FirstLastFrameNode.define_schema  s   yy,A(P		";	    		%"V	    |5LM"#V,">	   !#!1!1!8!8E   "!#!1!1!8!8+/7  	 }mD|[AY   

  $ ; ! [2h ! 		..		++		##
 //8mnCS
 S	
rs   r!   r.   r   r(   r   rD   r   r   rL   r   c                   #    SU	;   a  US:X  a  [        S5      e[        U	   n	[        U [        SU	 S3SS9[        [        [        U[        [        U5      SS	9[        [        U5      SS	9S
9/[        USUSUU
UUS9S9S9I S h  vN n[        U [        SU	 S3SS9[        S [        UR                  S9S[        S9I S h  vN nUR                  (       a:  [        SUR                  R                    SUR                  R"                   S35      eUR$                  nUR&                  nU(       aC  UR(                  =(       d    / nU(       a  SUS    3OSn[        SU SU SUS:w  a  SOS S 35      eUR*                  (       a  UR*                  S   nUR,                  (       aQ  [.        R0                  " [2        R4                  " [7        [8        R:                  " UR,                  5      5      5      5      $ UR<                  (       a1  [.        R0                  " [?        UR<                  5      I S h  vN 5      $ [        S!5      e[        S"5      e GN GN N$7f)#Nr   r   z94K resolution is not supported by the veo-3.1-lite model.r   r   r   r   ru   rv   )r!   rI   	lastFramer@   T)ry   rz   r{   r|   rD   r   r}   r   r   r   r   c                 ,    U R                   (       a  S$ S$ r   r   r   s    rp   r   0Veo3FirstLastFrameNode.execute.<locals>.<lambda>[  r   rs   r   r   r   r   r   r   r   r   r"   r   r   r   r5   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   rw   r   r   r   r   r   r   r   r   r   )ro   r!   r.   r   r(   r   rD   r   r   rL   r   r   r   r   r   r   r   r   s                     rp   r   Veo3FirstLastFrameNode.execute)  sO     U?zT1WXX5!!({5';FK,!&%5/F{/S^i #:/Fz/R]h#
 0 ,%,$,"&"0#2)		"
 
8 &{5'7G0K%.33 9

 

 om.A.A.I.I-J(S`SfSfSkSkRllmnoo ))!7766<"G/6Bwqzl+BKD[M R"#611D#")M[Z 
 ??OOA&E''}}Y%<%<WVEUEUV[VnVnEo=p%qrr||}}+G+U%UVVLMMNOOy
8

< &Vs7   BII<IIE,I.I/IIIr   N)r   r   r   r   r   rq   strintr   re   boolr   r   r   rs   rp   r   r     s    T
 T
l MPMP MP 	MP
 MP MP MP [[MP KKMP MP MP MPrs   r   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)VeoExtensioniz  returnc                 ,   #    [         [        [        /$ 7fN)r   r   r   )selfs    rp   get_node_listVeoExtension.get_node_list{  s      ##"
 	
s   r   N)r   r   r   r   r   listtyper   	ComfyNoder   r   r   rs   rp   r   r   z  s)    
T$r||*<%= 
 
rs   r   r   c                     #    [        5       $ 7fr   )r   r   rs   rp   comfy_entrypointr    s     >s   ) r   ior   typing_extensionsr   comfy_api.latestr   r   r   r   comfy_api_nodes.apis.veor	   r
   r   r   r   r   r   comfy_api_nodes.utilr   r   r   r   r   r   r   r   r   r   r   r   r  r   rs   rp   <module>r     s      & A A      2.8/2!<
UPR\\ UPpRPbll RPjgPR\\ gPT
> 
 rs   