o
    {#i+                     @   sP   d dl Z d dlZd dlZd dlmZ dd Zdd Zdd Zd	d
 Zdd Z	dS )    N)HTMLParseErrorc              	   C   sx   g }t |}|| }|D ]}|r,| }zt| |}W n	 ty&   Y qw || qt|dkr:td| |S )a7  Parses input html to find all matches for the input starting point.

    :param str html:
        HTML to be parsed for an object.
    :param str preceding_regex:
        Regex to find the string preceding the object.
    :rtype list:
    :returns:
        A list of dicts created from parsing the objects.
    r   No matches for regex )recompilefinditerend parse_for_object_from_startpointr   appendlen)htmlpreceding_regexresultregex
match_itermatchstart_indexobj r   T/var/www/GraceOrthoHospital/venv_grace/lib/python3.10/site-packages/pytube/parser.pyparse_for_all_objects   s    


r   c                 C   s8   t |}|| }|std| | }t| |S )a#  Parses input html to find the end of a JavaScript object.

    :param str html:
        HTML to be parsed for an object.
    :param str preceding_regex:
        Regex to find the string preceding the object.
    :rtype dict:
    :returns:
        A dict created from parsing the object.
    r   )r   r   searchr   r   r   )r   r   r   r   r   r   r   r   parse_for_object(   s   


r   c           	      C   s  | |d } | d dvrt d| dd  d}d}| d g}d}dd	d
dd}|t| k r~t|dkr6nH|dvr<|}| | }|d }||| krS|  |d7 }q)|dv ra|dkr`|d7 }q)n|| v rt|dkro|dvst|| |d7 }|t| k s/| d| }|S )a  Parses input html to find the end of a JavaScript object.

    :param str html:
        HTML to be parsed for an object.
    :param int start_point:
        Index of where the object starts.
    :rtype dict:
    :returns:
        A dict created from parsing the object.
    Nr   ){[z$Invalid start point. Start of HTML:
   r      }]"/)r   r   r   r   ) 
)r   r   \   )(,=:r   !&|?r   r   ;)r   r
   popkeysr	   )	r   start_point	last_char	curr_charstackicontext_closerscurr_contextfull_objr   r   r   find_object_from_startpoint<   sF   

r8   c                 C   sV   t | |}zt|W S  tjjy*   zt|W  Y S  ttfy)   t	dw w )zJSONifies an object parsed from HTML.

    :param str html:
        HTML to be parsed for an object.
    :param int start_point:
        Index of where the object starts.
    :rtype dict:
    :returns:
        A dict created from parsing the object.
    zCould not parse object.)
r8   jsonloadsdecoderJSONDecodeErrorastliteral_eval
ValueErrorSyntaxErrorr   )r   r0   r7   r   r   r   r   {   s   
r   c                 C   s
  g }| dd }t d}t d}t|dkr|drK||}| \}}t|| d }|d|t|  }	||	 |t|	d d }n2||}z| \}}W n tyk   t|d }|d }Y nw |d| }
||
 ||d }t|dks|S )a+  Parses the throttling array into a python list of strings.

    Expects input to begin with `[` and close with `]`.

    :param str js_array:
        The javascript array, as a string.
    :rtype: list:
    :returns:
        A list of strings representing splits on `,` in the throttling array.
    r   Nr&   zfunction\([^)]*\)r   function)	r   r   r
   
startswithr   spanr8   r	   AttributeError)js_arrayresultscurr_substringcomma_regex
func_regexr   match_start	match_endfunction_textfull_function_defcurr_elr   r   r   throttling_array_split   s0   






rO   )
r=   r9   r   pytube.exceptionsr   r   r   r8   r   rO   r   r   r   r   <module>   s    !?