o
    "i                     @   s   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
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ zd dlmZ W n eya   d dlZY nw G dd dZG dd dZdS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)jsonable_encoder)remove_none_from_dict)RequestOptions)UnprocessableEntityError)ChapterResponse)ChapterSnapshotsResponse)GetChaptersResponse)HttpValidationErrorc                   @     e Zd ZdefddZdddedeje de	fd	d
Z
dddededeje defddZdddededeje dejfddZdddededeje dejfddZdddededeje defddZdddedededeje ddf
ddZdS )ChaptersClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   ^/var/www/html/voicebot/backend/venv/lib/python3.10/site-packages/elevenlabs/chapters/client.py__init__      
zChaptersClient.__init__Nrequest_options
project_idr   returnc                C   s2  | j jjdtj| j   ddt| dt|dur!|dndtt	i | j 
 |dur5|di ni |durI|ddurI|dnd	d
|durT|dnd
d}d|j  krcdk rmn ntt| S |jdkr|ttt| z| }W n ty   t|j|jdw t|j|d)a?  
        Returns a list of your chapters for a project together and its metadata.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.get_all(
            project_id="project_id",
        )
        GET/v1/projects/	/chaptersNadditional_query_parametersadditional_headerstimeout_in_seconds<   r   max_retriesparamsheaderstimeoutretriesr(      ,    status_codebodyr   httpx_clientrequesturllibparseurljoinget_base_urlr   getr   get_headersr2   pydanticparse_obj_asr   jsonr
   r   r   r   textr   r   r   	_response_response_jsonr   r   r   get_all   sB   	

zChaptersClient.get_all
chapter_idc                C   s:  | j jjdtj| j   ddt| dt| t|dur%|dndtt	i | j 
 |dur9|di ni |durM|ddurM|dnd	d
|durX|dnd
d}d|j  krgdk rqn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a   
        Returns information about a specific chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.get(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        r    r!   r"   
/chapters/Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r   r<   r2   r=   r>   r   r?   r
   r   r   r   r@   r   r   rE   r   rB   rC   r   r   r   r;   P   sD   	

zChaptersClient.getc                C   s<  | j jjdtj| j   ddt| dt| t|dur%|dndtt	i | j 
 |dur9|di ni |durM|ddurM|dnd	d
|durX|dnd
d}d|j  krgdk rrn n	ttj| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Delete a chapter by its chapter_id.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.delete(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        DELETEr!   r"   rF   Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r   r<   r2   r=   r>   typingAnyr?   r
   r   r   r   r@   rH   r   r   r   delete   sD   	

zChaptersClient.deletec                C   s\  | j jjdtj| j   ddt| dt| dt|dur&|dnd|dur6tt	|di ndtt	i | j 
 |durI|d	i ni |dur]|d
dur]|d
ndd|durh|dndd}d|j  krwdk rn n	ttj| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Starts conversion of a specific chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.convert(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        POSTr!   r"   rF   /convertNr$   additional_body_parametersr%   r&   r'   r   r(   r*   r?   r+   r,   r-   r(   r.   r/   r0   r1   rJ   rH   r   r   r   convert   sJ   	

zChaptersClient.convertc                C   s<  | j jjdtj| j   ddt| dt| dt|dur&|dndtt	i | j 
 |dur:|di ni |durN|d	durN|d	nd
d|durY|dndd}d|j  krhdk rrn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Gets information about all the snapshots of a chapter, each snapshot corresponds can be downloaded as audio. Whenever a chapter is converted a snapshot will be automatically created.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.get_all_snapshots(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        r    r!   r"   rF   
/snapshotsNr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r   r<   r2   r=   r>   r   r?   r
   r   r   r   r@   rH   r   r   r   get_all_snapshots   sD   	

z ChaptersClient.get_all_snapshotschapter_snapshot_idc                C   sT  | j jjdtj| j   ddt| dt| dt| dt|dur+|dnd|dur;tt	|d	i ndtt	i | j 
 |durN|d
i ni |durb|ddurb|dndd|durm|dndd}d|j  kr}dk r~dS  |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Stream the audio from a chapter snapshot. Use GET /v1/projects/{project_id}/chapters/{chapter_id}/snapshots to return the chapter snapshots of a chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - chapter_snapshot_id: str. The chapter_snapshot_id of the chapter snapshot. You can query GET /v1/projects/{project_id}/chapters/{chapter_id}/snapshots to the all available snapshots for a chapter.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.chapters.stream_snapshot(
            project_id="project_id",
            chapter_id="chapter_id",
            chapter_snapshot_id="chapter_snapshot_id",
        )
        rN   r!   r"   rF   /snapshots//streamNr$   rP   r%   r&   r'   r   r(   rQ   r.   r/   r0   r1   r   r5   r6   r7   r8   r9   r:   r   r;   r   r<   r2   r
   r=   r>   r   r?   r   r   r@   r   r   rE   rV   r   rB   rC   r   r   r   stream_snapshot3  sL   "	

zChaptersClient.stream_snapshot)__name__
__module____qualname__r   r   strrK   Optionalr	   r   rD   r   r;   rL   rM   rR   r   rU   r[   r   r   r   r   r      |    
5
9
9
<
>r   c                   @   r   )AsyncChaptersClientr   c                C   r   r   r   r   r   r   r   r   x  r   zAsyncChaptersClient.__init__Nr   r   r   r   c                   s:  | j jjdtj| j   ddt| dt|dur"|dndtt	i | j 
 |dur6|di ni |durJ|ddurJ|dnd	d
|durU|dnd
dI dH }d|j  krgdk rqn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)aO  
        Returns a list of your chapters for a project together and its metadata.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.get_all(
            project_id="project_id",
        )
        r    r!   r"   r#   Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   r4   rA   r   r   r   rD   {  sD   	

zAsyncChaptersClient.get_allrE   c                   sB  | j jjdtj| j   ddt| dt| t|dur&|dndtt	i | j 
 |dur:|di ni |durN|ddurN|dnd	d
|durY|dnd
dI dH }d|j  krkdk run ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Returns information about a specific chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.get(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        r    r!   r"   rF   Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   rG   rH   r   r   r   r;     sF   	

zAsyncChaptersClient.getc                   sD  | j jjdtj| j   ddt| dt| t|dur&|dndtt	i | j 
 |dur:|di ni |durN|ddurN|dnd	d
|durY|dnd
dI dH }d|j  krkdk rvn n	ttj| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a	  
        Delete a chapter by its chapter_id.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.delete(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        rI   r!   r"   rF   Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   rJ   rH   r   r   r   rM     sF   	

zAsyncChaptersClient.deletec                   sd  | j jjdtj| j   ddt| dt| dt|dur'|dnd|dur7tt	|di ndtt	i | j 
 |durJ|d	i ni |dur^|d
dur^|d
ndd|duri|dnddI dH }d|j  kr{dk rn n	ttj| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Starts conversion of a specific chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.convert(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        rN   r!   r"   rF   rO   Nr$   rP   r%   r&   r'   r   r(   rQ   r.   r/   r0   r1   rJ   rH   r   r   r   rR     sL   	

zAsyncChaptersClient.convertc                   sD  | j jjdtj| j   ddt| dt| dt|dur'|dndtt	i | j 
 |dur;|di ni |durO|d	durO|d	nd
d|durZ|dnddI dH }d|j  krldk rvn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Gets information about all the snapshots of a chapter, each snapshot corresponds can be downloaded as audio. Whenever a chapter is converted a snapshot will be automatically created.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.get_all_snapshots(
            project_id="project_id",
            chapter_id="chapter_id",
        )
        r    r!   r"   rF   rS   Nr$   r%   r&   r'   r   r(   r)   r.   r/   r0   r1   rT   rH   r   r   r   rU   Z  sF   	

z%AsyncChaptersClient.get_all_snapshotsrV   c                   s\  | j jjdtj| j   ddt| dt| dt| dt|dur,|dnd|dur<tt	|d	i ndtt	i | j 
 |durO|d
i ni |durc|ddurc|dndd|durn|dnddI dH }d|j  krdk rdS  |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Stream the audio from a chapter snapshot. Use GET /v1/projects/{project_id}/chapters/{chapter_id}/snapshots to return the chapter snapshots of a chapter.

        Parameters:
            - project_id: str. The project_id of the project, you can query GET https://api.elevenlabs.io/v1/projects to list all available projects.

            - chapter_id: str. The chapter_id of the chapter. You can query GET https://api.elevenlabs.io/v1/projects/{project_id}/chapters to list all available chapters for a project.

            - chapter_snapshot_id: str. The chapter_snapshot_id of the chapter snapshot. You can query GET /v1/projects/{project_id}/chapters/{chapter_id}/snapshots to the all available snapshots for a chapter.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.chapters.stream_snapshot(
            project_id="project_id",
            chapter_id="chapter_id",
            chapter_snapshot_id="chapter_snapshot_id",
        )
        rN   r!   r"   rF   rW   rX   Nr$   rP   r%   r&   r'   r   r(   rQ   r.   r/   r0   r1   rY   rZ   r   r   r   r[     sN   "	

z#AsyncChaptersClient.stream_snapshot)r\   r]   r^   r   r   r_   rK   r`   r	   r   rD   r   r;   rL   rM   rR   r   rU   r[   r   r   r   r   rb   w  ra   rb   ) rK   urllib.parser7   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.jsonable_encoderr   core.remove_none_from_dictr   core.request_optionsr	   !errors.unprocessable_entity_errorr
   types.chapter_responser    types.chapter_snapshots_responser   types.get_chapters_responser   types.http_validation_errorr   pydantic.v1v1r=   ImportErrorr   rb   r   r   r   r   <module>   s,     a