ó
    3ë”hÂ  ã                   óp   • S r SSKrSSKJr  SSKJr  SSKJr  SSKrSSK	J
r
  SSKJr  S	rS
r " S S5      rg)zÝDRM module is used to handle DRM operations with clock skew correction.
Currently the only DRM operation is generating the Sec-MS-GEC token value
used in all API requests to Microsoft Edge's online text-to-speech service.é    N)Údatetime)Útimezone)ÚOptionalé   )ÚTRUSTED_CLIENT_TOKEN)ÚSkewAdjustmentErrorl    !l
 g    eÍÍAc                   óÆ   • \ rS rSr% SrSr\\S'   \S\SS4S j5       r	\S\4S	 j5       r
\S
\S\\   4S j5       r\S\R                  SS4S j5       r\S\4S j5       rSrg)ÚDRMé   z<
Class to handle DRM operations with clock skew correction.
g        Úclock_skew_secondsÚskew_secondsÚreturnNc                 ó6   • [         =R                  U -  sl        g)a  
Adjust the clock skew in seconds in case the system clock is off.

This method updates the `clock_skew_seconds` attribute of the DRM class
to the specified number of seconds.

Args:
    skew_seconds (float): The number of seconds to adjust the clock skew to.

Returns:
    None
N)r
   r   )r   s    ÚD/var/www/auris/envauris/lib/python3.13/site-packages/edge_tts/drm.pyÚadj_clock_skew_secondsÚDRM.adj_clock_skew_seconds   s   € ô 	×Ò ,Ñ.Öó    c                  óˆ   • [         R                  " [        R                  5      R	                  5       [
        R                  -   $ )z
Gets the current timestamp in Unix format with clock skew correction.

Returns:
    float: The current timestamp in Unix format with clock skew correction.
)ÚdtÚnowÚtzÚutcÚ	timestampr
   r   © r   r   Úget_unix_timestampÚDRM.get_unix_timestamp*   s*   € ô vŠv”b—f‘f‹~×'Ñ'Ó)¬C×,BÑ,BÑBÐBr   Údatec                 ó¤   •  [         R                  " U S5      R                  [        R                  S9R                  5       $ ! [         a     gf = f)a  
Parses an RFC 2616 date string into a Unix timestamp.

This function parses an RFC 2616 date string into a Unix timestamp.

Args:
    date (str): RFC 2616 date string to parse.

Returns:
    Optional[float]: Unix timestamp of the parsed date string, or None if parsing failed.
z%a, %d %b %Y %H:%M:%S %Z)ÚtzinfoN)r   ÚstrptimeÚreplacer   r   r   Ú
ValueError)r   s    r   Úparse_rfc2616_dateÚDRM.parse_rfc2616_date4   sF   € ð	ä—’˜DÐ"<Ó=ß‘¤§¡Ð'ß‘“ðøô
 ó 	Ùð	ús   ‚?A Á
AÁAÚec                 ó„  • U R                   c  [        S5      U eU R                   R                  SS5      nUb  [        U[        5      (       d  [        S5      U e[
        R                  U5      nUb  [        U[        5      (       d  [        SU 35      U e[
        R                  5       n[
        R                  X#-
  5        g)a  
Handle a client response error.

This method adjusts the clock skew based on the server date in the response headers
and raises a SkewAdjustmentError if the server date is missing or invalid.

Args:
    e (Exception): The client response error to handle.

Returns:
    None
NzNo server date in headers.ÚDatezFailed to parse server date: )
Úheadersr   ÚgetÚ
isinstanceÚstrr
   r#   Úfloatr   r   )r%   Úserver_dateÚserver_date_parsedÚclient_dates       r   Úhandle_client_response_errorÚ DRM.handle_client_response_errorJ   s°   € ð 9‰9ÑÜ%Ð&BÓCÈÐJØ%&§Y¡Y§]¡]°6¸4Ó%@ˆØÑ¤j°¼c×&BÑ&BÜ%Ð&BÓCÈÐJÜ.1×.DÑ.DÀ[Ó.QÐØÑ%¬ZÐ8JÌE×-RÑ-RÜ%Ø/°¨}Ð=óàðô ×,Ñ,Ó.ˆÜ×"Ñ"Ð#5Ñ#CÕDr   c                  óú   • [         R                  5       n U [        -  n X S-  -  n U [        S-  -  n U S [         3n[
        R                  " UR                  S5      5      R                  5       R                  5       $ )a¥  
Generates the Sec-MS-GEC token value.

This function generates a token value based on the current time in Windows file time format
adjusted for clock skew, and rounded down to the nearest 5 minutes. The token is then hashed
using SHA256 and returned as an uppercased hex digest.

Returns:
    str: The generated Sec-MS-GEC token value.

See Also:
    https://github.com/rany2/edge-tts/issues/290#issuecomment-2464956570
i,  éd   z.0fÚascii)
r
   r   Ú	WIN_EPOCHÚS_TO_NSr   ÚhashlibÚsha256ÚencodeÚ	hexdigestÚupper)ÚticksÚstr_to_hashs     r   Úgenerate_sec_ms_gecÚDRM.generate_sec_ms_gece   s~   € ô" ×&Ñ&Ó(ˆð 	”Ñˆð 	˜‘Ñˆð 	”˜3‘Ñˆð ˜s˜Ô$8Ð#9Ð:ˆô ~Š~˜k×0Ñ0°Ó9Ó:×DÑDÓF×LÑLÓNÐNr   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r,   Ú__annotations__Ústaticmethodr   r   r+   r   r#   ÚaiohttpÚClientResponseErrorr0   r>   Ú__static_attributes__r   r   r   r
   r
      sÂ   ‡ ñð !$Ð˜Ó#àð/¨Uð /°tó /ó ð/ð ðC ó Có ðCð ð ð ¨°%©ó ó ðð* ðE¨×(CÑ(Cð EÈó Eó ðEð4 ðO ó Oó óOr   r
   )rD   r7   r   r   r   r   Útypingr   rG   Ú	constantsr   Ú
exceptionsr   r5   r6   r
   r   r   r   Ú<module>rM      s:   ðñOó Ý #Ý #Ý ã å +Ý +à€	Ø
€÷rOò rOr   