
     j              	       b   d Z ddlZddlZddlmZmZmZ ddlZddlZddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZmZ  ej(                   ej*                         	      Zd
ej.                  dej0                  dee   dee   fdZddddeej6                     dee   dee   fdZ G d d      Zy)z|This module contains functions to list all available voices and a class to find the
correct voice based on their attributes.    N)AnyListOptional)Unpack   )SEC_MS_GEC_VERSIONVOICE_HEADERS
VOICE_LIST)DRM)VoiceVoicesManagerFindVoicesManagerVoice)cafilesessionssl_ctxproxyreturnc                   K   | j                  t         dt        j                          dt         t        j
                  t              ||d      4 d{   }t        j                  |j                          d{         }ddd      d{    D ]*  }d|vri |d<   d|d   vrg |d   d<   d|d   vs#g |d   d<   , |S 7 p7 K7 9# 1 d{  7  sw Y   IxY ww)	a  
    Private function that makes the request to the voice list URL and parses the
    JSON response. This function is used by list_voices() and makes it easier to
    handle client response errors related to clock skew.

    Args:
        session (aiohttp.ClientSession): The aiohttp session to use for the request.
        ssl_ctx (ssl.SSLContext): The SSL context to use for the request.
        proxy (Optional[str]): The proxy to use for the request.

    Returns:
        List[Voice]: A list of voices and their attributes.
    z&Sec-MS-GEC=z&Sec-MS-GEC-Version=T)headersr   sslraise_for_statusNVoiceTagContentCategoriesVoicePersonalities)
getr
   r   generate_sec_ms_gecr   headers_with_muidr	   jsonloadstext)r   r   r   urldatavoices         </DATA/.local/lib/python3.12/site-packages/edge_tts/voices.py__list_voicesr%      s       {{,l3#:#:#<"=
12	4%%m4    
**388:%56  U" "E*eJ&7757E*12uZ'8868E*23  K) &6   s`   AC"CC"#C=C	
>CC"C(C";C"	CC"CCCC")	connectorr   r&   c                   K   t        j                  | d      4 d{   }	 t        |t        |       d{   }ddd      d{    |S 7 07 # t         j                  $ rI}|j
                  dk7  r t        j                  |       t        |t        |       d{  7  }Y d}~md}~ww xY w7 i# 1 d{  7  sw Y   S xY ww)a  
    List all available voices and their attributes.

    This pulls data from the URL used by Microsoft Edge to return a list of
    all available voices.

    Args:
        connector (Optional[aiohttp.BaseConnector]): The connector to use for the request.
        proxy (Optional[str]): The proxy to use for the request.

    Returns:
        List[Voice]: A list of voices and their attributes.
    T)r&   	trust_envNi  )aiohttpClientSessionr%   _SSL_CTXClientResponseErrorstatusr   handle_client_response_error)r&   r   r   r"   es        r$   list_voicesr0   :   s       $$yDIIW	A&w%@@D JI K J@** 	Axx3,,Q/&w%@@@D	A JIII Ks   C
AC
B4AAAC
B2	C
AB/&9B*B" B*%B4*B//B42C
4C:B=;CC
c                   ^    e Zd ZdZd	dZe	 d
deee      dd fd       Z	de
e   dee   fdZy)VoicesManagerzF
    A class to find the correct voice based on their attributes.
    r   Nc                      g | _         d| _        y )NF)voicescalled_create)selfs    r$   __init__zVoicesManager.__init__[   s    02#(    custom_voicesc                    K   t               }|t                d{   n|}|D cg c]  }i |d|d   j                  d      d   i! c}|_        d|_        |S 7 ?c c}w w)z\
        Creates a VoicesManager object and populates it with all available voices.
        NLanguageLocale-r   T)r2   r0   splitr4   r5   )clsr9   r6   r4   r#   s        r$   createzVoicesManager.create_   sx      (5(={}$$=NT
NTU@u@j%/"7"7"<Q"?@f
 " %
s    A#A
A#$AA#A#kwargsc                     | j                   st        d      | j                  D cg c]&  }|j                         |j                         k  s%|( }}|S c c}w )zM
        Finds all matching voices based on the provided attributes.
        z9VoicesManager.find() called before VoicesManager.create())r5   RuntimeErrorr4   items)r6   rA   r#   matching_voicess       r$   findzVoicesManager.findn   s_     !!K 
  ${{
*eflln.ME{ 	 
 
s   &AA)r   N)N)__name__
__module____qualname____doc__r7   classmethodr   r   r   r@   r   r   r   rF    r8   r$   r2   r2   V   s[    ) 48$T%[1	 V$56 4@R;S r8   r2   )rJ   r   r   typingr   r   r   r)   certifityping_extensionsr   	constantsr   r	   r
   drmr   r   r   r   create_default_contextwherer+   r*   
SSLContextstrr%   BaseConnectorr0   r2   rL   r8   r$   <module>rW      s   ,  
 & &   $ D D  @ @%3%%]W]]_=$""$-0^^$DLSM$	%[$P 59QU7001AI#	%[8$ $r8   