+
    `j%;                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHt ]! ]4      P#                  4       P$                  t]! R4      t]! ]P*                  P-                  R]R,          4      4      t]! ]P*                  P-                  R]R,          4      4      t]! ]P*                  P-                  R]R	,          4      4      t]! ]P*                  P-                  R
]R,          4      4      tRtRt]R,          tRtR] R2t]R,          t ]R,          t!]R,          t"Rt# ! R R]PH                  PJ                  4      t&R t']PP                  PS                  ^ R4        ^ RI*t+R t-R t.R t/R t0R^/R lt1R3R  lt2R! t3R" t4R# t5R$ t6R% t7R& t8R' t9R( t:R) t;R* t<R+ t=R, t>R- t?R. t@R/ tAR0 tBR1 tC]DR28X  d
   ]C! 4        R# R#   ], d    ^ RI+t+ Lji ; i)4zGKeep an OLED-safe clock dream on the TV when it would otherwise be off.N)Pathz/share/.ha_cache/tv_clockTV_CLOCK_CONFIGzclock_display.jsonTV_CLOCK_STATEz
state.jsonTV_CLOCK_APKzquiet-clock.apkTV_CLOCK_LOGzclock_display.logz'com.yingcong.tvclock/.ClockDreamServicezcom.yingcong.tvclockstreami"  zhttp://192.168.1.187:z/clock.m3u8z
ffmpeg.pidztime.txtzdate.txtz-/usr/share/fonts/noto/NotoSansCJK-Regular.ttcc                      a a ] tR t^"t o/ ]P
                  P                  P                  CRRRR/CtV 3R ltR t	Rt
VtV ;t# )ClockStreamHandlerz.m3u8application/vnd.apple.mpegurlz.tsz
video/mp2tc                   < V P                  R R4       V P                  RR4       V P                  RR4       V P                  RR4       \        SV `	  4        R# )	zAccess-Control-Allow-Origin*zAccess-Control-Allow-HeadersRangezAccess-Control-Expose-HeaderszContent-Length, Content-RangezCache-Controlzno-storeN)send_headersuperend_headers)self	__class__s   &*/share/.ha_cache/tv_clock/clock_display.pyr   ClockStreamHandler.end_headers)   sR    6<7A8:YZ*5    c                    R # N )r   _formatargss   &&*r   log_messageClockStreamHandler.log_message0   s    r   r   )__name__
__module____qualname____firstlineno__httpserverSimpleHTTPRequestHandlerextensions_mapr   r   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r	   r	   "   sC     
++
.
.
=
=0|N r   r	   c                  8   \         P                  R R R7       \        P                  ! \        \        \         4      R7      p \        P                  P                  R\        3V 4      p\        P                  ! VP                  RR R7      pVP                  4        V# )Tparentsexist_ok)	directoryz0.0.0.0ClockStreamHTTP)targetnamedaemon)
STREAM_DIRmkdir	functoolspartialr	   strr!   r"   ThreadingHTTPServerSTREAM_PORT	threadingThreadserve_foreverstart)handlerr"   threads      r   start_stream_serverr?   4   sq    TD1 2c*oNG[[,,i-EwOFV%9%9@QZ^_F
LLNMr   z/share/.ha_cachec                      \         P                  ! \        V 4      P                  4       4      #   \         d    \        T4      u # i ; ir   )jsonloadsr   	read_text	Exceptiondict)pathdefaults   &&r   	load_jsonrH   C   s<    zz$t*..011 G}s   ,/ AAc                    \        V 4      p V P                  P                  R R R7       V P                  V P                  R,           4      pVP                  \        P                  ! V^R7      R,           4       VP                  V 4       R# )Tr*   z.tmp)indent
N)	r   parentr3   with_suffixsuffix
write_textrA   dumpsreplace)rF   valuetmps   && r   	save_jsonrT   J   sc    :DKKdT2


4;;/
0CNN4::eA.56KKr   c                 V    R  V P                  R4       4       w  rV^<,          V,           # )c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   )int).0parts   & r   	<genexpr>minutes.<locals>.<genexpr>S   s     ;*:$CII*:s   :)split)rR   hourminutes   &  r   minutesr`   R   s&    ;%++c*:;LD"9vr   c                     V P                   ^<,          V P                  ,           p\        VR,          4      p\        VR,          4      pW48:  d   Y2u;8*  ;'       d    V8  # u # W#8  ;'       g    W$8  # )<   waking_start
waking_end)r^   r_   r`   )nowconfigcurrentr<   ends   &&   r   within_waking_hoursri   W   se    hhmcjj(GF>*+E
&&
'C|%%#%%%%,,w},r   timeoutc                    V  R 2p\         P                  ! RRV.R^
R7       \         P                  ! RRV.VORRVR7      # )z:5555adbconnectT)capture_outputrj   z-s)rn   textrj   )
subprocessrun)iprj   r   r/   s   &$* r   run_adbrs   `   sJ    t5\FNNE9f-dBO>>	f$t$Tg r   c                      \         P                  ! W3VR 7      ;_uu_ 4         RRR4       R#   + '       g   i     R# ; i  \         d     R# i ; i)rj   NTF)socketcreate_connectionOSError)rr   portrj   s   &&&r   tcp_openrz   h   s@    %%rj'BB CBBB s*   !A /A A 	A  A AAc                 @  a \        V R 4      '       g   R# \        V RRR4      pVP                  ;'       g    RVP                  ;'       g    R,           o\        S9   ;'       d;    \
        ;QJ d    V3R lR 4       F  '       g   K   R# 	  R# ! V3R lR 4       4      # )	  Fshelldumpsysdreams c              3   ,   <"   T F	  qS9   x  K  	  R # 5ir   r   )rX   markerro   s   & r   rZ   "dream_is_active.<locals>.<genexpr>u   s      %%[6$%[s   T)mCurrentDreamzisDreaming=truezmDreaming=true)rz   rs   stdoutstderr	COMPONENTany)rr   resultro   s   & @r   dream_is_activer   p   s    BR)X6FMMRFMM$7$7R8D   %%[%   %%[% " r   c                    \        V R 4      '       g   R# \        V RRR\        4      pVP                  ^ 8X  d   RVP                  9   d   R# \
        P                  4       '       g   \        P                  ! R\
        4       R# \        V RR	\        \
        4      ^ZR
7      pVP                  ^ 8w  dF   \        P                  ! RVP                  ;'       g    VP                  P                  4       4       R# R# )r|   Fr}   pmrF   zpackage:Tzclock APK missing: %sinstallz-rru   zAPK install failed: %s)rz   rs   PACKAGE
returncoder   APK_PATHexistsloggingerrorr6   r   strip)rr   found	installeds   &  r   ensure_installedr   z   s    BBvw7E1u||!;??-x8ItS]BGIq .1A1A1U1UYEUEU0\0\0^_r   c                 Z   \        V 4      '       g   R # RRRRR\        3R	3pV Fd  p\        V R.VO5!  pVP                  ^ 8w  g   K$  \        P
                  ! RRP                  V4      VP                  P                  4       4        R # 	  \        P                  ! ^4       \        V 4      # )
Fsettingsputsecurescreensaver_componentsr}   zADB command failed (%s): %s )r   r   r   screensaver_enabled1)cmdr   zstart-dreaming)r   r   rs   r   r   r   joinr   r   timesleepr   )rr   commandscommandr   s   &   r   start_dreamr      s    BA	UH&>	J+H
 W/w/!MM7'9JFMML_L_Lab	 
 	JJqM2r   c                       \        \        P                  4       P                  4       4      p \        P
                  ! V ^ 4       R#   \        \        \        3 d     R# i ; i)    TF)	rW   FFMPEG_PID_PATHrC   r   oskillrx   
ValueErrorFileNotFoundErrorpids    r   ffmpeg_is_runningr      sM    /++-3356
QZ!23 s   AA A A c                      \        \        P                  4       P                  4       4      p \        P
                  ! V ^4        \        P                  4        R#   \        \        \        3 d     L/i ; i  \         d     R# i ; i)   N)
rW   r   rC   r   r   r   rx   r   r   unlinkr   s    r   stop_streamr      sq    /++-3356
R  Z!23   s$   AA A7 A43A47BBc                  B   \         P                  P                  4       p R p\        P	                  V P                  R4      R,           4       \        P	                  V P                   RV P                   RV P                   RWP                  4       ,           R24       R# )u   一二三四五六日z%H:%MrK   u   年u   月u   日　星期N)dtdatetimere   TIME_TEXT_PATHrO   strftimeDATE_TEXT_PATHyearmonthdayweekday)re   weekdayss     r   update_clock_textr      st    
++//
C&Hcll73d:;88*C		{#cggYl8KKM;R:SSUVr   c            
         \         R ,          p \        4       '       d   V P                  4       '       d   R# \        4        \         P	                  RRR7       \         P                  R4       F  pVP                  4        K  	   V P                  4        \        4        R\         R\         R\         R\         R2	p. RNR	NR
NRNRNRNRNRNRNRNRNRNRNRNRNVNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR NR"NR#NR$NR%NR&NR'NR(NR)NRNR*NR+NR NR,NR-NR.NR/NR0N\        \         R1,          4      N\        V 4      Np\        \        R2,          R34      ;_uu_ 4       p\        P                   ! V\        P"                  V\        P$                  RR47      pR5R5R54       \&        P)                  \        XP*                  4      4       \,        P.                  ! 4       ^,           p\,        P.                  ! 4       V8  d   V P                  4       '       d"   V P1                  4       P2                  ^ 8  d   R# VP5                  4       e%   \6        P8                  ! R6\        R2,          4       R7# \,        P:                  ! R84       K  \6        P8                  ! R94       R7#   \         d     ELi ; i  + '       g   i     EL; i):z
clock.m3u8Tr*   zsegment-*.tszdrawtext=fontfile=z
:textfile=z:reload=1:fontcolor=0x606060:fontsize=132:x='(w-text_w)/2+220*sin(floor(t/60)*1.7)':y='h/2-110+120*cos(floor(t/60)*1.3)',drawtext=fontfile=zv:reload=1:fontcolor=0x404040:fontsize=52:x='(w-text_w)/2+220*sin(floor(t/60)*1.7)':y='h/2+55+120*cos(floor(t/60)*1.3)'ffmpegz-hide_bannerz	-loglevelwarningz-rez-flavfiz-izcolor=c=black:s=1280x720:r=1zanullsrc=r=48000:cl=stereoz-vfz-c:vlibx264z-presetveryfastz-tune
stillimagez
-profile:vmainz-levelz3.1z-pix_fmtyuv420pz-g2z-keyint_minz-sc_threshold0z-c:aaacz-b:a32kz-ar48000hlsz	-hls_timez-hls_list_size6z
-hls_flagsz1delete_segments+omit_endlist+independent_segmentsz-hls_segment_filenamezsegment-%05d.tsz
ffmpeg.logab)stdinr   r   start_new_sessionNz#clock stream encoder exited; see %sFg      ?z!clock stream did not become ready)r2   r   r   r   r3   globr   r   r   	FONT_PATHr   r   r6   open
DEPLOY_DIRrp   PopenDEVNULLSTDOUTr   rO   r   r   	monotonicstatst_sizepollr   r   r   )playlistolddrawtextr   
ffmpeg_logprocdeadlines          r   ensure_streamr      s   L(Hx00MTD1~.

 /  YK ("# $ 'K ("# $.		.  "-/8"$B 	   # %A 		 	
 	
 
 %
 '1
 3:
 <H 	  ' ). 0: <E 	  ! #& (7 9< 	    % ', .5 	  ! #& (8 := 	 J 	  "%Z2C%C!D 	HG 
j<'	.	.*:--j$$
 
/
 s488}-~~"$H
..
X
%??!8!81!<99;"MM?lAZ[

3MM56_  @ 
/	.	.s   J !8J.J+*J+.J?	c                 l   a  ^ RI pVP                  S .^
R7      w  r#\        V 3R lV 4       R4      pWV3# )r   N)known_hostsrj   c              3   `   <"   T F#  qP                   P                  S8X  g   K  Vx  K%  	  R # 5ir   )	cast_infohost)rX   itemrr   s   & r   rZ   get_cast.<locals>.<genexpr>   s"     E%$>>+>+>"+D%s   .
.)pychromecastget_chromecastsnext)rr   r   castsbrowsercasts   f    r   get_castr      s<    !11rdB1ONEE%EtLD$&&r   c                 t   \        4       '       g   R #  \        V 4      w  rp Vf*    VP                  4        Ve   VP                  4        R # R # VP	                  ^
R7       VP
                  P                  R8w  d*    VP                  4        Ve   VP                  4        R # R # VP                  P                  4        \        P                  ! ^4       VP                  P
                  pVP                  R\        39  d*    VP                  4        Ve   VP                  4        R # R # VP                  R8g  VP                  4        Ve   VP                  4        # #   TP                  4        Te   TP                  4        i i ; i  \         d#   p\        P                   ! RT4        Rp?R # Rp?ii ; i)FNru   CC1AD845ERRORzCast status failed: %s)r   r   stop_discovery
disconnectwaitstatusapp_idmedia_controllerupdate_statusr   r   
content_id
STREAM_URLidle_reasonrD   r   debug)rr   r   r   r   r   excs   &     r   cast_clock_is_activer     sy   &.rl#t	"| ""$!   IIbI!{{!!Z/ ""$!   !!//1JJqM**11F  z(:: ""$!   %%0""$!   ""$!   .4sR   F
 E  $F
 -E  >$F
 &AE  $F
 ,E  :$F
  'FF
 
F7F22F7c                    \        4       '       g   R #  \        V 4      w  rp Vf*    VP                  4        Ve   VP                  4        R # R # VP	                  ^R7       VP
                  P                  \        RRRR7       VP
                  P                  ^R7       \        P                  ! ^4       VP
                  P                  pVP                  \        8H  ;'       d    VP                  R9    VP                  4        Ve   VP                  4        # #   TP                  4        Te   TP                  4        i i ; i  \         d    \        P                   ! R4        R # i ; i)Fru   r
   LIVEr   )stream_typetitlez"failed to start clock Cast session)PLAYING	BUFFERING)r   r   r   r   r   r   
play_mediar   block_until_activer   r   r   r   player_staterD   r   	exception)rr   r   r   r   r   s   &    r   
start_castr    sC   ??&.rl#t	"| ""$!   IIbI!!!,,;"" -  !!44R4@JJqM**11F$$
2ffv7J7JNf7ff""$!   ""$!   >?s:   E D $E BD 'D 7$E 'EE !E,+E,c                 R    \        V R 4      '       d   \        V 4      # \        V 4      # r|   )rz   r   r  rr   s   &r   clock_is_activer  1  s$    "*2t"4"4?2R:Nr:RRr   c                 R    \        V R 4      '       d   \        V 4      # \        V 4      # r  )rz   r   r  r  s   &r   start_clockr  5  s#    D2b>r   c           
      8   \         P                  V P                  R R4      P                  RR4      4      pRV^,          ,           p\        P                  ! \        P                  \        P
                  4      ;_uu_ 4       pVP                  \        P                  \        P                  ^4       \        ^4       F>  pR F  pR F  pVP                  W%V34       K  	  K!  	  \        P                  ! R4       K@  	  RRR4       R#   + '       g   i     R# ; i)r\   r   -g?Ns   )z255.255.255.255z192.168.1.255)   	   )bytesfromhexrQ   rv   AF_INET
SOCK_DGRAM
setsockopt
SOL_SOCKETSO_BROADCASTrangesendtor   r   )macrawpacketsock_	broadcastry   s   &      r   send_wolr(  ;  s    
--C,44S"=
>C38#F	v~~v'8'8	9	9T))6+>+>BqAA	"DKKD(9: # B JJsO	  
:	9	9	9s   A=DD	c                     \         P                  ! 4       V ,           p\         P                  ! 4       V8  d:   \        P                  ! ^R7      pV'       d   V# \         P                  ! ^4       KS  R# )   ru   N)r   r   
tv_controldiscover_tvr   )timeout_secondsr   rr   s   &  r   discover_untilr.  G  sH    ~~/1H
..
X
%##A.I

1r   c                      \         P                  ! 4       p \         P                  ! V R 7      R8w  d   V # \         P                  ! ^R7      # )r  Unknownru   )r+  
_get_tv_ipget_power_stater,  r  s    r   
current_ipr3  Q  s9    				 B!!R(I5	!!!,,r   c                 2    \         P                  ! R V R7      # )Standbyr  )r+  js_keyr  s   &r   standbyr7  X  s    Y2..r   c                     \         P                  R R R7       \        P                  ! \        P                  R\        P
                  ! \        4      \        P                  ! 4       .R7       \        4       p \        \        RRR^ /4      p \        \        / 4      p VP                  RR 4      '       g   \        P                  ! ^<4       KB  \        4       '       d   \!        4        \#        \$        P&                  P)                  4       V4      p\+        4       pV'       EdO   \-        V4      pV'       gQ   V'       d8   VP                  R4      R8X  d"   \        P.                  ! R	4       \1        V4       \3        4        R
VR&   EM[V'       d   RVR&   WAR&   ^ VR&   EMCVP                  R4      R8X  dU   \5        VP                  R^ 4      4      ^,           pWaR&   V^8  d&   \        P.                  ! R4       \3        4        RVR&   EMVP                  R4      R8X  d4   \7        V4      '       d!   \        P.                  ! RV4       RVR&   WAR&   EM\9        V4       \3        4        RVR&   WAR&   EMpV'       EdY   VP                  R4      R8X  d   RVR&   \5        VP                  R^
4      4      ^<,          p\        P                  ! 4       \;        VP                  R^ 4      4      ,
          V8  d   \        P                  ! 4       VR&   RVR&   \=        \        V4       \        P.                  ! R4       VP                  R. 4       F  p\?        V4       K  	  \A        \5        VP                  R^4      4      4      pV'       d3   \7        V4      '       d"   \        P.                  ! RV4       RVR&   WAR&   M+\        PB                  ! R4       RVR&   M\3        4        R
VR&   \=        \        V4       \        P                  ! \I        ^
\5        VP                  R^4      4      4      4       EK    \D         d    \        PF                  ! R4        L_i ; i)Tr*   z%%(asctime)s %(levelname)s %(message)s)levelformathandlersmodeunknownlast_wake_attemptenabledclockz4waking hours ended; putting clock display in standby	off_hoursrr   inactive_checksz?clock exited by viewer; suspending until the TV next powers offviewingwakingzclock dream started on %soffwake_retry_minutesz2TV is off during waking hours; sending Wake-on-LANtv_macsboot_timeout_secondsz"TV woke; clock dream started on %sz1TV did not become controllable after wake attemptzclock display loop failedcheck_interval_seconds)%r   r3   r   basicConfigINFOFileHandlerLOG_PATHStreamHandlerr?   rH   
STATE_PATHCONFIG_PATHgetr   r   r   r   ri   r   r   re   r3  r  infor7  r   rW   r  r   floatrT   r(  r.  r   rD   r  max)	stream_serverstaterf   awake_hoursrr   activemissesretry_secondsr"  s	            r   r   r   \  sG   TD1ll6%%h/1F1F1HI
 ()Mj696I1"MNE
;+G	;::i..

2 ""!#-bkkoo.?HKBr(,"%))F"3w">%[\M$/E&M$+E&M"$$K/0E+,YYv&'1 !+<a!@AAEF/5+,{%fg#(1fYYv&(2"2%@"E(/f&(d %R(M$-E&M"$$K99V$	1$)E&M #FJJ/CR$H IB N99;uyy1Da'H!II]Z15E-.$,E&Mj%0LL!UV%zz)R8   9'FJJ7Ms,S(TUBk"oo%I2N(/f&(d([\(-f +fj%( 	

3r3vzz*BBGHIJ  	;9:	;s.   .P+ A/P+ <AP+ C+P+ 8E7P+ +!QQ__main__)g      ?)E__doc__r   r   r4   http.serverr!   rA   r   r   rv   rp   sysr9   r   pathlibr   __file__resolverL   HEREr   environrQ  rP  rO  r   rM  r   r   r2   r8   r   r   r   r   r   r"   r#   r	   r?   rF   inserttvmodr+  ImportErrorrH   rT   r`   ri   rs   rz   r   r   r   r   r   r   r   r   r  r  r  r  r(  r.  r3  r7  r   r   r   r   r   <module>rg     s   M      	   
   H~&&-.
2::>>"3T<P5PQR"**..!1:3LMN


~t6G/GHI

~z<O/OPQ5	
 ("
$[M=
|+j(j(;	== $ % &

-r  "	:z'44S	-/TKn zF i  s   2G G! G!