/ PornAPI / Soundgasm / __pycache__ / track.cpython-312.pyc
track.cpython-312.pyc
 1 2  @�h���ddlmZddlZddlmZddlmZddlmZddl	m
 3  Z
 4  ddlZddlm
Z
Gd	�d
 5  �ZGd�d�Zy)
�)�
BeautifulSoupN�)�	dual_mode)�AsyncHttpClient)�
read_metadata)�List)�Pathc�\�eZdZdZdedefd�Zeddeddfd��Zed	eddfd
 6  ��Z	d�Z
 7  y)
�SoundgasmTrackzZ
 8      Represents a Soundgasm track with lazy-fetched metadata and download capability.
 9      �title�page_urlc��||_||_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
10  y�N)rr
�	audio_url�description�duration�bitrate�sample_rate�codec�channels�tags�bits_per_sample)�selfrr
s   �;/root/projects/PAPI/Python_Tests/PornAPI/Soundgasm/track.py�__init__zSoundgasmTrack.__init__sR����
11  � ��
�%)���'+���&*��
�#'���'+���!%��
12  �$(��
�&*��	�+/���N�http_client�returnc��K�|jr|Sd}|}|�$t�}|j��d{���d}	|j|j��d{���j��d{���}t
|d�}|jdtjd���}|r<tjd|jxsd	�}|r|jd
13  �|_|jdd�
�}|r|j
14  j�|_|js ||r|jddd��d{���SSt!||j��d{���}	|	r�|	jd�|_|	jd�|_|	jd�|_|	jd�|_|	jd�|_|	jd�|_|	jd�|_|r|jddd��d{���|S7���7���7���7��7��7�#|r|jddd��d{���7wwxYw�w)zu
15          Fetch and populate audio URL, description, and media metadata for this track.
16          Returns self.
17          FNT�html.parser�scriptzm4a:\s*)�stringzm4a:\s*"([^"]+)"���divzjp-description��class_rrrrrrr)rr�
18  __aenter__�getr
�textr�find�re�compile�searchr"�group�stripr�	__aexit__rrrrrrrr)
19  rr�manage�http�html�soupr!�m�desc�metas
20            r�
fetch_detailszSoundgasmTrack.fetch_detailss������>�>��K������<�"�$�D��/�/�#�#�#��F�	7� $������ 7�7�=�=�?�?�D� ��}�5�D��Y�Y�x��
2122  �:�0F�Y�G�F���I�I�1�6�=�=�3F�B�G���%&�W�W�Q�Z�D�N��9�9�U�+;�9�<�D��#'�9�9�?�?�#4�� ��>�>����n�n�T�4��6�6�6��'�t�T�^�^�<�<�D�� $���� 4��
�#�x�x�	�2���#'�8�8�M�#:�� �!�X�X�g�.��
23  � $���� 4��
�'+�x�x�0A�'B��$� �H�H�V�,��	���n�n�T�4��6�6�6���7
$��8��?��.7��=��7����n�n�T�4��6�6�6��s��2I�H�I�H-�H!�H-�0H$�1B5H-�&I�>H'�?I�H-�H)�B H-�?I�H+�I�!H-�$H-�'I�)H-�+I�-I�I	�I�I�	file_pathc��^K�t�4�d{���}|js|j|��d{���|jstd��|j	|jt|���d{���ddd��d{���y7�~7�[7�7�#1�d{���7swYyxYw�w)zW
24          Download the audio file to the specified path using streaming writes.
25          NzAudio URL could not be found.)rrr9�RuntimeError�read_into_filer	)rr:r3s   r�downloadzSoundgasmTrack.downloadFs�����
26  #�$�	G�	G���>�>��(�(��.�.�.��>�>�"�#B�C�C��%�%�d�n�n�d�9�o�F�F�F�	G�	G�	G��.��
G��	G��	G�	G�	G�sg�B-�B�B-�!B�B�AB�:B�;B�?B-�
27  B�B-�B�B�B-�B*�B!�B*�&B-c�"�d|j�d�S)z8
28          Return a concise debug representation.
29          z<SoundgasmTrack title='z'>)r)rs r�__repr__zSoundgasmTrack.__repr__Rs��)�����B�7�7rr)�__name__�
30  __module__�__qualname__�__doc__�strrrrr9r>r@�rrrrsi���0�c�0�S�0��&��&�JZ�&��&�P�	G��	G��	G��	G�8rrc�*�eZdZdZededefd��Zy)�TrackzK
31      Factory that constructs a SoundgasmTrack from a public track URL.
32      �refrc��K�t|t�std��|jd�st	d��t�4�d{���}|j
|��d{���}|jdk7rtd|j����|j��d{���}t|d�}|jdd	�
33  �}|st	d��|jj�}t||�j|��d{���cddd��d{���S7��7��7��7�7�
#1�d{���7swYyxYw�w)za
34          Create a SoundgasmTrack by fetching the page and extracting title and metadata.
35          z!Track reference must be a string.zhttps://soundgasm.net/zInvalid Soundgasm URL.N��zFailed to fetch track: HTTP r r%zjp-titler&zTrack title not found.)�
36  isinstancerE�	TypeError�
37  startswith�
38  ValueErrorrr)�statusr<r*rr+r0rr9)�clsrIr3�respr4r5�	title_tagrs        r�__new__z
Track.__new__^s ����
39  �#�s�#��?�@�@��~�~�6�7��5�6�6�"�$�
40  	H�
41  	H�����#��&�D��{�{�c�!�"�%A�$�+�+��#O�P�P�����$�D� ��}�5�D��	�	�%�
42  �	�;�I�� �!9�:�:��N�N�(�(�*�E�'��s�3�A�A�$�G�G�
43  	H�
44  	H�
45  	H��&��%��H��
46  	H��
47  	H�
48  	H�
49  	H�s�AD>�D�	D>�D)�!D!�">D)� D#�!A(D)�	D%�
50  D)�
D>�D'�D>�!D)�#D)�%D)�'D>�)D;�/D2�0D;�7D>N)rArBrCrDrrErrTrFrrrHrHYs-����H��H��H��HrrH)�bs4rr,�base.decoratorsr�	base.httpr�
51  base.utilsr�typingr�aiofiles�pathlibr	rrHrFrr�<module>r\s6���	�'�'�&����K8�K8�\H�Hr