
    }i<                     F    d dl Z d dlZd dlZd dlmZ d Zd Zd Zd Zd Z	y)    N)HTMLParseErrorc                    g }t        j                  |      }|j                  |       }|D ]3  }|s|j                         }	 t	        | |      }|j                  |       5 |st        d|       |S # t        $ r Y Sw xY w)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.
    No matches for regex )recompilefinditerend parse_for_object_from_startpointappendr   )htmlpreceding_regexresultregex
match_itermatchstart_indexobjs           ;/usr/local/lib/python3.12/dist-packages/pytubefix/parser.pyparse_for_all_objectsr      s     FJJ'E%J #))+K#6t[I c"# 4_4EFGGM "  	s   A33	A?>A?c                     t        j                  |      }|j                  |       }|st        d|       |j	                         }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   s        r   parse_for_objectr   (   sO     JJ'E\\$F4_4EFGG**,K+D+>>    c                    | |d } | d   dvrt        d| dd        d}d}| d   g}d}dd	d
ddd}|t        |       k  r|sn}|dvr|}| |   }|d   }|||   k(  r|j                          |dz  }?|dv r|dk(  r2|dz  }N||j                         v r|dk(  r|dvs|j	                  |       |dz  }|t        |       k  r| 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   ;)r   lenpopkeysr   )	r   start_point	last_char	curr_charstackicontext_closerscurr_contextfull_objs	            r   find_object_from_startpointr=   <   s5    DAwiDT#2YKPQQ II!WIE	A O c$i-K'!IG	Ry 55IIKFA ++D Q O0022!S(Y>z-zLL+	Q9 c$i-< BQxHOr   c                     t        | |      }	 t        j                  |      S # t        j                  j                  $ r7 	 t        j                  |      cY S # t        t        f$ r t        d      w xY ww xY 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.)
r=   jsonloadsdecoderJSONDecodeErrorastliteral_eval
ValueErrorSyntaxErrorr   )r   r5   r<   s      r   r
   r
   |   ss     +4=H<zz(##<<'' <	<##H--K( 	< !:;;	<<s!   # A7AA7A33A7c                 r   g }| dd }t        j                  d      }t        j                  d      }t        |      dkD  r|j                  d      ru|j	                  |      }|j                         \  }}t        ||j                         d         }|d|t        |      z    }	|j                  |	       |t        |	      dz   d }n@|j	                  |      }	 |j                         \  }}|d| }
|j                  |
       ||d }t        |      dkD  r|S # t        $ r t        |      dz
  }|dz   }Y Jw xY w)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   r2   
startswithr   spanr=   r   AttributeError)js_arrayresultscurr_substringcomma_regex
func_regexr   match_start	match_endfunction_textfull_function_defcurr_els              r   throttling_array_splitrV      sJ    Gab\N**T"K01J
n

!$$Z0%%n5E%*ZZ\"K7

UVXM ./N	C<N0N ONN,-+C0A,BQ,F,GHN&&~6E,).&Y
 %\k2GNN7#+IJ7N- n

!0 N " ,!.1A5'!O	,s   D D65D6)
rC   r?   r   pytubefix.exceptionsr   r   r   r=   r
   rV    r   r   <module>rY      s,    
  	 /B?(=@<*)r   