
    }i                     l   d Z ddlZddlZddlZddlZddlZddlZddlmZ d Z	d Z
 G d dej                        Z ej                  d      Z ej                  d	      Zd
efdZd Zdej&                  fdZd
efdZdej&                  fdZded
efdZdej&                  fdZded
efdZdefdZy)ak  
MIT License

Copyright (c) 2024-present Simon Sawicki <contact@grub4k.xyz>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

https://github.com/Grub4K/qpb
    N)defaultdictc                 F    t        j                  |       }t        |      }|S N)base64	b64decode_decode)valuedatadecodeds      =/usr/local/lib/python3.12/dist-packages/pytubefix/protobuf.pydecode_protobufr      s     E"DdmGN    c                     	 t        j                  | j                               }t        |      }t	        j
                  |      j                         }|S # t        $ r t        d|        w xY w)Nzinvalid input: )astliteral_evalstrip_encoder   	b64encodedecodeSyntaxError)r	   r
   resultencodeds       r   encode_protobufr   %   se    5.""6*113 5OE73445s   AA A-c                   $    e Zd ZdZdZdZdZdZdZy)WireTyper                  N)	__name__
__module____qualname__VARINTI64LENSGROUPEGROUPI32 r   r   r   r   0   s     F
C
CFF
Cr   r   s   <fs   <dreturnc                     t        | t              sd}t        |      dj                  d | j	                         D              S )Nztype to encode has to be a dictr   c              3   :   K   | ]  \  }}t        ||        y wr   )_encode_record).0wire_idr	   s      r   	<genexpr>z_encode.<locals>.<genexpr>B   s     V~wN5'2Vs   )
isinstancedict	TypeErrorjoinitems)r
   messages     r   r   r   =   s7    dD!3  88VVVVr   c                    t        | t        j                        r| nt        j                  |       }t	        t
              }t        |      }|r'|\  }}||   j                  |       t        |      }|r'|j                         D ]p  \  }}t        |      D ]F  \  }}t        |t              st        j                  t              5  t        |      ||<   d d d        H t        |      dk(  si|d   ||<   r t!        |      S # 1 sw Y   vxY wNr   r   )r2   ioBufferedIOBaseBytesIOr   list_read_recordappendr6   	enumeratebytes
contextlibsuppress	Exceptionr   lenr3   )r
   readerr   recordkeyr	   valuesindexs           r   r   r   E   s    b&7&78Tbjj>NFF&!F

Us5!f% 
 ||~ $V%f- 	/LE5eU+$$Y/ / 'u/ /	/
 v;! )F3K$ </ /s   DDrF   c                    t        |       }|y |\  }}|t        j                  k(  rt        |       }||fS |t        j                  k(  r| j                  d      }||fS |t        j                  k(  r| j                  d      }||fS |t        j                  k(  r| j                  t        |             }||fS d}t        |      )N   r   zUnknown wire type)		_read_tagr   r$   _read_varintr%   readr)   r&   r4   )rF   tagr0   	wire_typer	   r7   s         r   r>   r>   [   s    
F
C
{GYHOO#V$ E> 
hll	"A E> 
hll	"A E> 
hll	"L01
 E> &  r   c                 $   t        | t              r6| dk  rt        |       } t        |t        j
                        t        |       z   S t        | t              r dj                  t        t        |             }nit        | t              rt        |       }nMt        | t              r| j                         }n,t        | t              r| }ndt!        |        }t#        |      t        |t        j$                        t        t'        |            z   |z   S )Nr   r   zUnencodable type: )r2   int_signed_to_zigzag_encode_tagr   r$   _encode_varintr=   r5   mapr.   r3   r   strencoderA   typer4   r&   rE   )r
   r0   r   r7   s       r   r.   r.   o   s    $!8$T*D7HOO4~d7KKK$((3~t45	D$	$-	D#	++-	D%	 &tDzl3  w-s7|0LLwVVr   c                 x    d}d}d}|dz  r.| j                  d      }|sy |\  }||dz  |z  z  }|dz  }|dz  r.|S )Nr      r         )rO   )rF   shiftr
   byter   s        r   rN   rN      sa    EDD

Q#--
 
 Kr   r	   c                     | j                         dz   dz  xs d}t        |      }t        |dz
        D ]  }| dz  dz  ||<   | dz  }  | |d<   t        |      S )N   r^   r   r]   r\   )
bit_length	bytearrayrangerA   )r	   data_lengthr
   rJ   s       r   rV   rV      sr    ##%)a/41K[!D{Q' k)K7U! DH;r   c                 D    t        |       }|y |dz	  t        |dz        fS )Nr   r^   )rN   r   )rF   r	   s     r   rM   rM      s,     E}A:x...r   rQ   c                 *    | yt        | dz  |z        S )Nr   r   )rV   )r0   rQ   s     r   rU   rU      s    7a<9455r   c                 &    | dz  }| dk  r| dz
  }|S r9   r*   )r	   r   s     r   rT   rT      s"    aZFqy1Mr   )__doc__r   r   rB   enumr:   structcollectionsr   r   r   IntEnumr   Struct_float_struct_double_structrA   r   r   r;   r>   r.   rN   rS   rV   rM   rU   rT   r*   r   r   <module>rs      s   *     	  #5t||  e$u%WU W,** (WU W***  # % /b'' /6H 6 6S r   