
    Cc[                     
   d Z g dZddlmZ ddlmZ ddlmZmZm	Z
 ddlmZmZmZmZ ddlmZ  G d d	e
      Z	 G d
 de	      Z G d de      Z G d de      Z G d de      ZeZ eee	       edd      d               Zy)a  Read and write Ogg Speex comments.

This module handles Speex files wrapped in an Ogg bitstream. The
first Speex stream found is used.

Read more about Ogg Speex at http://www.speex.org/. This module is
based on the specification at http://www.speex.org/manual2/node7.html
and clarifications after personal communication with Jean-Marc,
http://lists.xiph.org/pipermail/speex-dev/2006-July/004676.html.
)OggSpeexOpendelete    )
StreamInfo)VCommentDict)OggPageOggFileTypeerror)cdataget_sizeloadfileconvert_error)PaddingInfoc                       e Zd Zy)r
   N__name__
__module____qualname__     2/usr/lib/python3/dist-packages/mutagen/oggspeex.pyr
   r
          r   r
   c                       e Zd Zy)OggSpeexHeaderErrorNr   r   r   r   r   r       r   r   r   c                   .    e Zd ZdZdZdZdZd Zd Zd Z	y)OggSpeexInfoa[  OggSpeexInfo()

    Ogg Speex stream information.

    Attributes:
        length (`float`): file length in seconds, as a float
        channels (`int`): number of channels
        bitrate (`int`): nominal bitrate in bits per second. The reference
            encoder does not set the bitrate; in this case, the bitrate will
            be 0.
    r   c                 
   t        |      }|j                  d   j                  d      s*t        |      }|j                  d   j                  d      s*|j                  st	        d      t        j                  |j                  d   dd       | _        t        j                  |j                  d   dd       | _        t        dt        j                  |j                  d   dd             | _        |j                  | _        y )	Nr      Speex   z.page has ID header, but doesn't start a stream$   (   0   4   8   )r   packets
startswithfirstr   r   uint_lesample_ratechannelsmaxint_lebitrateserialselffileobjpages      r   __init__zOggSpeexInfo.__init__5   s    w,,q/,,[97#D ,,q/,,[9zz%@B B ==aB)?@dll1ob&<=1ell4<<?2b+ABCkkr   c                     t        j                  || j                  d      }|t        |j                  t        | j                        z  | _        y )NT)	finishing)r   	find_lastr-   r   positionfloatr(   lengthr.   s      r   
_post_tagszOggSpeexInfo._post_tagsA   s@      $++F<%%mmeD,<,<&==r   c                      d| j                   z  S )NzOgg Speex, %.2f seconds)r8   )r/   s    r   pprintzOggSpeexInfo.pprintG   s    )DKK77r   N)
r   r   r   __doc__r8   r)   r,   r2   r9   r;   r   r   r   r   r   $   s'    
 FHG
">8r   r   c                   (     e Zd ZdZ fdZd Z xZS )OggSpeexVCommentz,Speex comments embedded in an Ogg bitstream.c                 b   g }d}|s^t        |      }|j                  |j                  k(  r7|j                  |       |j                  xs t	        |j
                        dkD  }|s^t        j                  |      d   }t        t        | '  |d       t	        |      | j                  z
  | _        y )NF   r   framing)r   r-   appendcompletelenr$   
to_packetssuperr>   r2   _size_padding)r/   r0   infopagesrD   r1   data	__class__s          r   r2   zOggSpeexVComment.__init__N   s    7#D{{dkk)T"==CS->-B	 
 !!%(+.tU.CD	DJJ.r   c                    |j                  d       t        |      }|j                  d   j                  d      s*t        |      }|j                  d   j                  d      s*|j                  }t        |      }|j                  |k7  rt        |      }|j                  |k7  r|g}|d   j
                  s~t        |d   j                        dkD  sct        |      }|j                  |d   j                  k(  r|j                  |       |d   j
                  st        |d   j                        dkD  sct        j                  |d      }t        |      t        |d         z
  }| j                  d      }t        |d         t        |      z
  }	t        |	|      }
|
j                  |      }|d|z  z   |d<   t        j                  ||      }t        j                  |||       y	)
z2Write tag data into the Speex comment packet/page.r   r   r@   F)strictrA       N)seekr   r$   r%   r-   rD   rE   rC   rF   r   writer   _get_padding_from_packets_try_preservereplace)r/   r0   padding_funcr1   r-   	old_pagesr$   content_sizevcomment_datapadding_leftrJ   new_padding	new_pagess                r   _injectzOggSpeexVComment._injectZ   s    	Q w,,q/,,[97#D ,,q/,,[9
 wkkV#7#D kkV# F	R=))S21F1F-G!-K7#D{{il111  & R=))S21F1F-G!-K
 $$Yu=(3wqz?:

5
171:]);;<6''5 #W{%::
66w	J	I6r   )r   r   r   r<   r2   r^   __classcell__)rM   s   @r   r>   r>   K   s    6
/&7r   r>   c                   :    e Zd ZdZeZeZeZ	dgZ
dZdZed        Zy)r   zOggSpeex(filething)

    An Ogg Speex file.

    Arguments:
        filething (filething)

    Attributes:
        info (`OggSpeexInfo`)
        tags (`mutagen._vorbis.VCommentDict`)
    zaudio/x-speexNc                 .    |j                  d      d|v z  S )Ns   OggSr   )r%   )filenamer0   headers      r   scorezOggSpeex.score   s    !!'*kV.CDEr   )r   r   r   r<   r   _Infor>   _Tagsr   _Error_mimesrJ   tagsstaticmethodrd   r   r   r   r   r      s>    
 EE FFDDF Fr   r   FT)methodwritablec                 r    t        |       }| j                  j                  d       |j                  |        y)z delete(filething)

    Arguments:
        filething (filething)
    Raises:
        mutagen.MutagenError

    Remove tags from a file.
    r   N)r   r0   rR   r   )	filethingts     r   r   r      s.     	A1HHYr   N)r<   __all__mutagenr   mutagen._vorbisr   mutagen.oggr   r	   r
   OggErrormutagen._utilr   r   r   r   mutagen._tagsr   r   r   r>   r   r   IOErrorr   r   r   r   <module>rx      s   	 )  ( ? ? B B %	H 		% 	$8: $8N57| 57pF{ F4  w	& ' r   