§
    SÜ¶i«  ã                   ó„   — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
Z
ddlmZ ddlmZ d	Zd
Z G d„ d¦  «        ZdS )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)ÚDictÚOptionalé   )ÚTRUSTED_CLIENT_TOKEN)ÚSkewAdjustmentErrorl    !l
 g    eÍÍAc                   ó,  — e Zd ZU dZdZeed<   ededdfd„¦   «         Zedefd„¦   «         Z	ed	e
dee         fd
„¦   «         Zedej        ddfd„¦   «         Zede
fd„¦   «         Zede
fd„¦   «         Zedee
e
f         dee
e
f         fd„¦   «         ZdS )ÚDRMzD
    Class to handle DRM operations with clock skew correction.
    g        Úclock_skew_secondsÚskew_secondsÚreturnNc                 ó0   — t           xj        | z  c_        dS )aW  
        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    úO/root/projects/openclaw-proxy/venv/lib/python3.11/site-packages/edge_tts/drm.pyÚadj_clock_skew_secondszDRM.adj_clock_skew_seconds   s   € õ 	ÐÔ ,Ñ.ÐÔÐÐó    c                  ó|   — t          j        t          j        ¦  «                             ¦   «         t
          j        z   S )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_timestampzDRM.get_unix_timestamp+   s(   € õ Œv•b”f‰~Œ~×'Ò'Ñ)Ô)­CÔ,BÑBÐBr   Údatec                 ó°   — 	 t          j        | d¦  «                             t          j        ¬¦  «                             ¦   «         S # t          $ r Y dS w xY w)aN  
        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_datezDRM.parse_rfc2616_date5   sZ   € ð	å”˜DÐ"<Ñ=Ô=ß’¥¤Ñ'Ô'ß’‘”ðøõ
 ð 	ð 	ð 	Ø44ð	øøøs   ‚AA Á
AÁAÚec                 ó¬  — | j         €t          d¦  «        | ‚| j                              dd¦  «        }|t          |t          ¦  «        st          d¦  «        | ‚t
                               |¦  «        }|t          |t          ¦  «        st          d|› ¦  «        | ‚t
                               ¦   «         }t
           	                    ||z
  ¦  «         dS )aS  
        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_errorz DRM.handle_client_response_errorK   sÕ   € ð Œ9ÐÝ%Ð&BÑCÔCÈÐJØ%&¤Y§]¢]°6¸4Ñ%@Ô%@ˆØÐ¥j°½cÑ&BÔ&BÐÝ%Ð&BÑCÔCÈÐJÝ.1×.DÒ.DÀ[Ñ.QÔ.QÐØÐ%­ZÐ8JÍEÑ-RÔ-RÐ%Ý%Ø=°Ð=Ð=ñô àðõ ×,Ò,Ñ.Ô.ˆÝ×"Ò"Ð#5¸Ñ#CÑDÔDÐDÐDÐDr   c                  ó   — t                                ¦   «         } | t          z  } | | dz  z  } | t          dz  z  } | d›t          › }t          j        |                     d¦  «        ¦  «                             ¦   «          	                    ¦   «         S )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_geczDRM.generate_sec_ms_gecf   s   € õ" ×&Ò&Ñ(Ô(ˆð 	•Ñˆð 	˜‘Ñˆð 	•˜3‘Ñˆð Ð:Ð:Õ$8Ð:Ð:ˆõ Œ~˜k×0Ò0°Ñ9Ô9Ñ:Ô:×DÒDÑFÔF×LÒLÑNÔNÐNr   c                  óN   — t          j        d¦  «                             ¦   «         S )za
        Generates a random MUID.

        Returns:
            str: The generated MUID.
        é   )ÚsecretsÚ	token_hexr7   r   r   r   Úgenerate_muidzDRM.generate_muidˆ   s!   € õ Ô  Ñ$Ô$×*Ò*Ñ,Ô,Ð,r   r%   c                 óz   — |                       ¦   «         }d|vsJ ‚dt                               ¦   «         › d|d<   |S )zÞ
        Returns a copy of the given headers with the MUID header added.

        Args:
            headers (dict): The original headers.

        Returns:
            dict: The headers with the MUID header added.
        ÚCookiezmuid=ú;)Úcopyr   r?   )r%   Úcombined_headerss     r   Úheaders_with_muidzDRM.headers_with_muid’   sL   € ð #Ÿ<š<™>œ>ÐØÐ/Ð/Ð/Ð/Ð/Ø%C­S×->Ò->Ñ-@Ô-@Ð%CÐ%CÐ%CÐ˜Ñ"ØÐr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r)   Ú__annotations__Ústaticmethodr   r   r(   r   r!   ÚaiohttpÚClientResponseErrorr-   r:   r?   r   rE   r   r   r   r   r      s†  € € € € € € ðð ð !$Ð˜Ð#Ð#Ñ#àð/¨Uð /°tð /ð /ð /ñ „\ð/ð ðC ð Cð Cð Cñ „\ðCð ð ð ¨°%¬ð ð ð ñ „\ðð* ðE¨Ô(Cð EÈð Eð Eð Eñ „\ðEð4 ðO ð Oð Oð Oñ „\ðOðB ð-˜3ð -ð -ð -ñ „\ð-ð ð  4¨¨S¨¤>ð  °d¸3À¸8´nð  ð  ð  ñ „\ð ð  ð  r   r   )rI   r3   r=   r   r   r   r   Útypingr   r   rL   Ú	constantsr   Ú
exceptionsr	   r1   r2   r   r   r   r   ú<module>rQ      sÔ   ððOð Oð €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø #Ð #Ð #Ð #Ð #Ð #Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !à €€€à +Ð +Ð +Ð +Ð +Ð +Ø +Ð +Ð +Ð +Ð +Ð +à€	Ø
€ðL ð L ð L ð L ð L ñ L ô L ð L ð L ð L r   