� L�gP0��~�ddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z ddl m Z ddlmZddlmZ ddlZn#e$rddlZYnwxYwejdkreZd d d d �Zd ddd �Zdddd �Zd�Zd,d�Zd�Zd-d�Zd,d�Zd.d�Z d/d�Z!d�Z"d�Z#d�Z$d�Z%d �Z&d!�Z'd"�Z(d0d$�Z)d%�Z*d&�Z+e+d'���Z,d(�Z-d)�Z.d*�Z/d+�Z0dS)1�)�divisionN)�Popen�PIPE)�log�ceil)� TemporaryFile)�warn��wraps)�r���)��� �b�h�i)i�����)i���i�)i�i���c��t|S�N)� FRAME_WIDTHS�� bit_depths �[/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/pydub/utils.py�get_frame_widthr&� �� � � "�"�Tc�L�t|}|s|���}|Sr)� ARRAY_TYPES�upper)r�signed�ts r�get_array_typer%*s&���I��A� �� �G�G�I�I�� �Hrc��t|Sr)� ARRAY_RANGESrs r�get_min_max_valuer(1rr�w+bc��d}|�|rt|���}d}t|t��rt||���}d} t|tj��rt||���}d}n#t $rYnwxYw||fS)NF)�modeT)r� isinstance� basestring�open�os�PathLike�AttributeError)�fdr+�tempfile�close_fds r�_fd_or_path_or_tempfiler55s����H� �z�h�z� �� %� %� %�����"�j�!�!�� �"�4� � � ���� � �b�"�+� &� &� ��b�t�$�$�$�B��H��� � � � � �� ���� �x�<�s�-A0�0 A=�<A=c�D�t|��}|rd|dz zSd|dz zS)z_ Converts the input db to a float, which represents the equivalent ratio in power. � �)�float)�db�using_amplitudes r� db_to_floatr<Ks3�� �r���B����b�2�g����b�2�g��rc��t|��}|�||z }|dkrtd�� S|rdt|d��zSdt|d��zS)z� Converts the input float to db, which represents the equivalent to the ratio in power represented by the multiplier passed in. Nr�infr8r7)r9r)�ratio�val2r;s r� ratio_to_dbrAWsg�� �%�L�L�E� ���� �� ��z�z��e� � �}���#��C��r�N�N�"�"��C��r�N�N�"�"rc���t|t��r|��fd�S��|j�ddlm}t |�|��|S)a> decorator for adding pydub effects to the AudioSegment objects. example use: @register_pydub_effect def normalize(audio_segment): ... or you can specify a name: @register_pydub_effect("normalize") def normalize_audio_segment(audio_segment): ... c�$��t|���Sr)�register_pydub_effect)�fn�names �r�<lambda>z'register_pydub_effect.<locals>.<lambda>zs���/��D�9�9�rNr )� AudioSegment)r,r-�__name__� audio_segmentrH�setattr)rErFrHs ` rrDrDls`����"�j�!�!�:���9�9�9�9�9� �|��{��+�+�+�+�+�+� �L�$��#�#�#� �Irc����tt���t���z ��}��fd�tt |����D��S)z� Breaks an AudioSegment into chunks that are <chunk_length> milliseconds long. if chunk_length is 50 then you'll get a list of 50 millisecond long audio segments back (except the last one, which can be shorter) c�6��g|]}�|�z|dz�z���S)r �)�.0rrJ� chunk_lengths ��r� <listcomp>zmake_chunks.<locals>.<listcomp>�sA��� 3� 3� 3�� �!�l�*�A��E�\�+A�A� B� 3� 3� 3r)r�lenr9�range�int)rJrP�number_of_chunkss`` r� make_chunksrV�sj�����C� �.�.��|�1D�1D�D�E�E�� 3� 3� 3� 3� 3��3�/�0�0�1�1� 3� 3� 3�3rc��tjdkr|�d��s|dz }tjgtjd�tj��z}|D]d}tj�||��}tj� |��r#tj |tj ��r|cS�edS)z0 Mimics behavior of UNIX which command. �ntz.exe�PATHN) r/rF�endswith�curdir�environ�split�pathsep�path�join�isfile�access�X_OK)�program� envdir_list�envdir� program_paths r�whichrh�s���  �w�$���w�/�/��7�7���6����9�+�� �6� 2� 8� 8��� D� D�D�K�� � ���w�|�|�F�G�4�4� � �7�>�>�,� '� '� �B�I�l�B�G�,L�,L� �� � � �� � rc�t�td��rdStd��rdStdt��dS)�Q Return enconder default application for system, either avconv or ffmpeg �avconv�ffmpegzGCouldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work�rhr �RuntimeWarningrNrr�get_encoder_namero��C�� �X�����x� �x�����x� � V�Xf�g�g�g��xrc�t�td��rdStd��rdStdt��dS)rj�avplay�ffplayzGCouldn't find ffplay or avplay - defaulting to ffplay, but may not workrmrNrr�get_player_namert�rprc�t�td��rdStd��rdStdt��dS)z; Return probe application, either avconv or ffmpeg �avprobe�ffprobezJCouldn't find ffprobe or avprobe - defaulting to ffprobe, but may not workrmrNrr�get_prober_namerx�sG�� �Y�����y� �y� � ���y� � Y�[i�j�j�j��yrc���tjdkrSttf}tjdkr|tjfz }t ||��rt j|��SnRt |t��r&|�tj ����St |t��r|Std� t|�������)z<Wrapper for os.fsdecode which was introduced in python 3.2 .)r r)r �z!type {0} not accepted by fsdecode) �sys� version_infor-�bytesr/r0r,�fsdecode�decode�getfilesystemencoding� TypeError�format�type)�filename� PathLikeTypess rr~r~�s��� ��6�!�!�#�U�+� � � �v� %� %� �b�k�^� +�M� �h� � .� .� )��;�x�(�(� (� )� �h�� &� &� @��?�?�3�#<�#>�#>�?�?� ?� �h� � +� +� ��O� �7�>�>�t�H�~�~�N�N� O� O�Orc�"�i}d}tj||��D]�}|�d����t|�d����t|�d����kr>d�|�d��|�d��g��}n|�d��}d�tjd |��D��}||t |�d ����<��|S) a| avprobe sometimes gives more information on stderr than on the json output. The information has to be extracted from stderr of the format of: ' Stream #0:0: Audio: flac, 88200 Hz, stereo, s32 (24 bit)' or (macOS version): ' Stream #0:0: Audio: vorbis' ' 44100 Hz, stereo, fltp, 320 kb/s' :type stderr: str :rtype: list of dict z}(?P<space_start> +)Stream #0[:\.](?P<stream_id>([0-9]+))(?P<content_0>.+)\n?(?! *Stream)((?P<space_end> +)(?P<content_1>.+))?� space_endN� space_start�,� content_0� content_1c�:�g|]}|�|�����SrN)�strip�rO�xs rrQz"get_extra_info.<locals>.<listcomp>�s%��I�I�I��q�I�!�'�'�)�)�I�I�Irz[:,]� stream_id)�re�finditer�grouprRr`r]rT)�stderr� extra_info� re_streamr� content_line�tokenss r�get_extra_infor��s���J�Q�I� �[��F� +� +�7�7�� �7�7�;� � � +��A�G�G�M�4J�4J�0K�0K�s���� �$�$�P&�P&�1&�1&��8�8�Q�W�W�[�%9�%9�1�7�7�;�;O�;O�$P�Q�Q�L�L��7�7�;�/�/�L�I�I�R�X�f�l�%C�%C�I�I�I��06� �3�q�w�w�{�+�+�,�,�-�-� �r�����c �`�t��}gd�} |t|��gz }d}d}n�#t$r�|dkr|dt|��dgz }n|dgz }t}t |dd� ��\}}|�d ��|���}|r|���YnwxYw|d d g|z}t||tt� ��} | � |���\} } | � dd��} | � dd��} tj | ��} | s| St| ��} d�| dD��}t|��d kr| S|d }d�}| |dD�]�}t!jd|��}t!jd|��}|r{||d|�d����||dt'|�d������||dt'|�d��������|r|||d|�d����||dt'|�d������||dt'|�d��������(t!jd|��r)||d|��||dd��||dd����ft!jd|��r'||d|��||dd ��||dd �����| S)!z\Return json dictionary with media info(codec, duration, size, bitrate...) from filepath )�-v�info� -show_format� -show_streamsNrwz-read_ahead_limitz cache:pipe:0�-�rbF)r3r�-of�json)�stdin�stdoutr�)�input�utf-8�ignorec�*�g|]}|ddk�|��S)� codec_type�audiorNr�s rrQz"mediainfo_json.<locals>.<listcomp> s&��N�N�N�1�1�\�?�g�3M�3M�Q�3M�3M�3Mr�streamsc�4�||vs ||dkr|||<dSdS�NrrN)�stream�prop�values r� set_propertyz$mediainfo_json.<locals>.set_property's0�� �v� � �����!2�!2� �F�4�L�L�L�"3�!2r�indexz*([su]([0-9]{1,2})p?) \(([0-9]{1,2}) bit\)$z$([su]([0-9]{1,2})p?)( \(default\))?$� sample_fmtr �bits_per_sampler�bits_per_raw_sampler z(flt)p?( \(default\))?$rz(dbl)p?( \(default\))?$�@)rxr~r��strrr5�seek�read�closer� communicaterr��loadsr�rRr��matchr�rT)�filepath�read_ahead_limit�prober� command_args�stdin_parameter� stdin_data�file� close_file�command�res�outputr�r�r�� audio_streamsr�r��token�m�m2s r�mediainfo_jsonr��s���� � �F����L� ���(�+�+�,�,� ���� � �� � � � � �Y� � � �0�#�6F�2G�2G�+�-� -�L�L� �S�E� !�L���2�8�T�E�R�R�R���j� � � �!� � � ��Y�Y�[�[� � � � �J�J�L�L�L��� �����u�f�%� �4�G� ���t�D� I� I� I�C��_�_�:�_�6�6�N�F�F� �]�]�7�H� -� -�F� �]�]�7�H� -� -�F� �:�f� � �D� ��� ���'�'�J�N�N��Y��N�N�N�M� �=���Q���� ��1� �F�!�!�!��F�7�O�,�<�<�� �H�A�5� I� I�� �X�<�e� D� D�� � <� �L���q�w�w�q�z�z� :� :� :� �L��!2�C����� � �O�O� D� D� D� �L��!6��A�G�G�A�J�J��� H� H� H� H� � <� �L���r�x�x��{�{� ;� ;� ;� �L��!2�C����� � �4D�4D� E� E� E� �L��!6��B�H�H�Q�K�K�8H�8H� I� I� I� I� �X�/�� 7� 7� <� �L���u� 5� 5� 5� �L��!2�B� 7� 7� 7� �L��!6�� ;� ;� ;� ;� �X�/�� 7� 7� <� �L���u� 5� 5� 5� �L��!2�B� 7� 7� 7� �L��!6�� ;� ;� ;�� �Ks�,�BB6�5B6c���t��}dddd|g}|ddg|z}t|t���}|���d�d ��}|jdkrG|g|z}t|t������d�d ��}t jd ��}i}tj d kr|� d d ��}|� d��D]c}|� |��} | rJ| � ��\} } } | r+ || n#t$ri|| <YnwxYw| || | <�^| || <�d|S)zWReturn dictionary with media info(codec, duration, size, bitrate...) from filepath r��quietr�r�r��old)r�rr�z6(?:(?P<inner_dict>.*?):)?(?P<key>.*?)\=(?P<value>.*?)$�win32� �� )rxrrr�r� returncoder��compiler{�platform�replacer]r��groups�KeyError) r�r�r�r�r�r��rgxr��line�mobj� inner_dict�keyr�s r� mediainfor�As���� � �F� �g���� �L��u�e�$�|�3�G� ��� %� %� %�C� �_�_� � �q� !� (� (�� 1� 1�F� �~�����(�\�)���w�t�,�,�,�8�8�:�:�1�=�D�D�W�M�M�� �*�N� O� O�C� �D� �|�w�������b�)�)��� � �T�"�"�"�"���y�y����� � "�%)�[�[�]�]� "�J��U�� "�*���$�$�$���*�*�*�')�D��$�$�$�*����(-��Z� ��%�%�!��S� �� �Ks�8E�E�Ec�D���i�t�����fd���}|S)Nc�N�� �dS#����d<�dcYSxYwr�rN)�cache�functions��r�wrapperzcache_codecs.<locals>.wrapperrs6��� ���8�O�� ��x�z�z�E�!�H���8�O�O�O���s� �$r )r�r�r�s` @r� cache_codecsr�os>���� �E� �8�_�_�������_�� �Nrc��t��}|dg}t|tt���}|���d�d��}|jdkrgSt jdkr|�dd��}tj d��}t��}t��}|� d ��D]�}|� |�����}|s�,|���\} } } | dd kr|�| ��| d d kr|�| ����||fS) Nz-codecs)r�r�rr�r�r�r�z)^([D.][E.][AVS.][I.][L.][S.]) (\w*) +(.*)r��Dr �E)rorrr�rr�r{r�r�r�r��setr]r�r�r��add) �encoderr�r�r�r��decoders�encodersr�r��flags�codecrFs r�get_supported_codecsr�}s@��� � �G�� �"�G� ���T� 2� 2� 2�C� �_�_� � �q� !� (� (�� 1� 1�F� �~����� � �|�w�������b�)�)�� �*�A� B� B�C��u�u�H��u�u�H�� � �T�"�"�  �  ��� � �$�*�*�,�,�'�'��� � �"�\�\�^�^���u�d� ��8�s�?�?� �L�L�� � � � ��8�s�?�?� �L�L�� � � �� �h� �rc�*�t��dSr��r�rNrr�get_supported_decodersr����� � !� !�!� $�$rc�*�t��dS)Nr r�rNrr�get_supported_encodersr��r�rc� �|���}|d�|d��|d�|d�����g}t�|d|d��S)z Left-Right -> Mid-Side rr �� split_to_mono�overlay� invert_phaserH�from_mono_audiosegments�rJ�channels r� stereo_to_msr�su�� � &� &� (� (�� �A�J� � �w�q�z� *� *�G�A�J�,>�,>�w�q�z�?V�?V�?X�?X�,Y�,Y� Z���,�,�W�Q�Z����D�D�Drc�,�|���}|d�|d��dz |d�|d�����dz g}t�|d|d��S)z Mid-Side -> Left-Right rr r r�r�s r� ms_to_stereor�s��� � &� &� (� (�� �A�J� � �w�q�z� *� *�Q� .��� �0B�0B�7�1�:�CZ�CZ�C\�C\�0]�0]�`a�0a� b���,�,�W�Q�Z����D�D�Dr)T)r)T)NTr)r�)1� __future__rr�r/r�r{� subprocessrr�mathrrr3r�warningsr � functoolsr �audioop� ImportError� pyaudioopr|r�r-rr!r'rr%r(r5r<rArDrVrhrortrxr~r�r�r�r�r�r�r�rrrNrr�<module>r s��������� � � � � � � � � � � � � � � � �"�"�"�"�"�"�"�"���������"�"�"�"�"�"������������� ��N�N�N�N��� � � ������� ������v����J� � � ��� �  � � ��� � ��!��� �#�#�#� � � � �#�#�#�����, � � � �#�#�#�#�*����0 3� 3� 3�  �  �  � � � � � � � � � �P�P�P�$���6G�G�G�G�T+�+�+�\ � � �� � ��� �<%�%�%�%�%�%�E�E�E�E�E�E�E�Es�?� A � A 
Memory