
    _Ogg\                        S r SSKJrJrJrJr  SSKrSSKrSSKrSSK	r	SSK
Jr  \	R                  S:  r\(       a  SSKJr  OSSKJr  SSKJrJrJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#J$r$J%r%J&r&J'r'  \RP                  " S5        \RR                  " S\RT                  5      r+\+RX                  r-S r.\." S5      r/\RR                  " S5      r0\RR                  " S5      r1S r2SSSSSS S4S jr3S7S jr4S\-   S-   r5S\-   S-   r6S\-   S-   r7\4" \5\6\7S9r8\4" \5\6\7S S!9r9S" r:S8S# jr;\RR                  " S$5      r<S9S% jr=S& r>S' r?S( r@\!\\\S).rA\B" \C" \#R                  " 5       5       V s/ s H	  o S   S4PM     sn 5      rE\ER                  \A5        S* rGS+ rHS,rIS-rJS.rKS:S/ jrLS0 rM\RR                  " S15      rN\RR                  " S25      rOS3 rPS;S4 jrQS8S5 jrRS<S6 jrSgs  sn f )=zq
This module provides functions not used directly by the imdb package,
but useful for Cinemagoer-based programs.
    )absolute_importdivisionprint_functionunicode_literalsN)_i   )escape)IMDbimdbURL_character_baseimdbURL_movie_baseimdbURL_person_base)	IMDbError)	Character)Company)COUNTRY_LANG)Movie)Person)TAGS_TO_MODIFY_tagAttrre_characterRef
re_nameRefre_titleRefimdbpyz(http://.+?)(?=\s|$)c                    ^  U 4S jnU$ )z4Make a function to pretty-print strings for the web.c                 t   > ST-    [        U SS9n [        U [        5      (       a  U R                  TS5      n U $ )Nz|Encode the given string using the %s encoding, and replace
        chars outside the given charset with XML char references.   )quotexmlcharrefreplace)r   
isinstancestrencode)sencodings    Q/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/imdb/helpers.pycgiPrint&makeCgiPrintEncoding.<locals>.cgiPrint=   sA    	EGO	P1Aa#67A     )r"   r$   s   ` r#   makeCgiPrintEncodingr(   ;   s     Or&   utf8z%\((.+?)\)sz!<if\s+(.+?)\s*>(.+?)</if\s+\1\s*>c                    ^  U 4S jnU$ )a  Create a function useful to handle text[::optional_note] values.
replaceTxtNotes is a format string, which can include the following
values: %(text)s and %(notes)s.
Portions of the text can be conditionally excluded, if one of the
values is absent. E.g.: <if notes>[%(notes)s]</if notes> will be replaced
with '[notes]' if notes exists, or by an empty string otherwise.
The returned function is suitable be passed as applyToValues argument
of the makeObject2Txt function.c                   >^ Tn[        U [        5      (       d  U $ U R                  SS5      nUS   n0 mU(       a  STS'   UR                  SU5      n[	        U5      S:X  a  STS'   UR                  S	US   5      nOUR                  S	S
5      nU4S jn[
        R                  U5      (       a1  [
        R                  XA5      n[
        R                  U5      (       a  M1  U$ )N::r   r   Ttextz%(text)s   notesz	%(notes)s c                 R   > U R                  S5      T;   a  U R                  S5      $ gNr   r.   r0   )group)matchobjkeysDicts    r#   _excludeFalseConditionalsCmakeTextNotes.<locals>._replacer.<locals>._excludeFalseConditionalsj   s&    ~~a H,~~a((r&   )r   r   splitreplacelenre_conditionalsearchsub)r!   outSssplitr-   r6   r5   replaceTxtNotess        @r#   	_replacer makeTextNotes.<locals>._replacerY   s    !S!!Hq!ay#HV||J-v;! $HW<<VAY7D<<R0D	 ##D))!%%&?FD ##D))r&   r'   )r@   rA   s   ` r#   makeTextNotesrC   P   s    4 r&   z / c                     U $ Nr'   xs    r#   <lambda>rH   x   s    1r&   Tc           	      \   ^ ^^^^^^^ T c  Sm Tc  SmTc  SmTc  SmSUUUUUU UU4S jjmT$ )a  "Return a function useful to pretty-print Movie, Person,
Character and Company instances.

*movieTxt* -- how to format a Movie object.
*personTxt* -- how to format a Person object.
*characterTxt* -- how to format a Character object.
*companyTxt* -- how to format a Company object.
*joiner* -- string used to join a list of objects.
*applyToValues* -- function to apply to values.
*_recurse* -- if True (default) manage only the given object.
z%(long imdb title)sz%(long imdb name)sc                   >^  Uc  SnOUS:  a  gUS-  n[        T [        [        45      (       a&  TR                  T  Vs/ s H	  nT" X!S9PM     sn5      $ [        T [        5      (       aL  TR                  [        T R                  5       5       VVs/ s H  u  p4T" X1S9< ST" XAS9< 3PM     snn5      $ 0 n[        T [        5      (       a  T R                  US'   TnOw[        T [        5      (       a  T R                  US	'   TnOP[        T [        5      (       a  T R                  US
'   TnO)[        T [        5      (       a  T R                  US'   TnOT $ U 4S jn[        R                  U5      (       a1  [        R!                  Xv5      n[        R                  U5      (       a  M1  ["        R%                  U5       H  nT R'                  U5      =(       d    [)        T US5      n	[        U	[*        5      (       d'  T
(       d  U	(       a  [+        U	5      n	U	(       a  T" XS9n	OU	(       a  T" [+        U	5      5      n	U	(       d  Sn	O [        U	[*        5      (       d  [+        U	5      n	UR-                  SU-   S-   U	5      nM     U$ s  snf s  snnf )zPretty-print objects.Nr      r0   r   )_limitRecursionr,   movieIDpersonIDcharacterID	companyIDc                    > U R                  S5      nTR                  U5      =(       d    [        TUS 5      nU(       a  U R                  S5      $ gr2   )r3   getgetattr)r4   	conditionproceedobjs      r#   r6   EmakeObject2Txt.<locals>.object2txt.<locals>._excludeFalseConditionals   sB     q)Iggi(IGCD,IG~~a((r&   z%(z)s)r   listtuplejoindictitemsr   rM   r   rN   r   rO   r   rP   r;   r<   r=   re_substfindallrR   rS   r   r9   )rV   rL   okvobjDataoutsr6   keyvalue_recurseapplyToValuescharacterTxt
companyTxtjoinermovieTxt
object2txt	personTxts   `         r#   rl   "makeObject2Txt.<locals>.object2txt   s>    "Oq 1cD%=));;), .),A !+1 N), . / /T"";; "#))+.0.TQ (K'KM.0 
 c5!!!$GIDV$$"%,,GJDY''%(__GM"DW%%#&==GK DJ	 ##D))!%%&?FD ##D))##D)CGGCL;GCd$;EeS)) #E
&uNE%c%j1s++E
<<s
T 159D * e .
0s   JJ
rE   r'   )rk   rm   rh   ri   rj   rg   rf   rl   s   ```````@r#   makeObject2Txtro   v   sD     ((	+)
; ;x r&   c                 h   ^ ^^^^ [        T5      mSUUUU U4S jjnT Ul        TUl        TUl        U$ )aT  Make a function used to pretty-print movies and persons refereces;
movieTxt and personTxt are the strings used for the substitutions.
movieTxt must contains %(movieID)s and %(title)s, while personTxt
must contains %(personID)s and %(name)s and characterTxt %(characterID)s
and %(name)s; characterTxt is optional, for backward compatibility.c                 .  >^^^ Tc  0 mUU	U
U4S jnUU	UU4S jnUUUU	4S jnU R                  SS5      R                  SS5      n [        SU 5      n [        R                  " X@5      n [        R                  " XP5      n [
        R                  " X`5      n U $ )	z)Substitute movies and persons references.c                    > U R                  S5      nTR                  U5      nU(       a%  UR                  nTU[        T" U5      TS5      S.-  nU$ )Nr   r   )rM   title)r3   rR   rM   r   )match
to_replaceitemrM   	_cgiPrintr"   rk   
titlesRefss       r#   _replaceMovie;makeModCGILinks.<locals>.modCGILinks.<locals>._replaceMovie   sV    QJ>>*-D,,%& :!6BUV) 
 r&   c                    > U R                  S5      nTR                  U5      nU(       a%  UR                  nTU[        T" U5      TS5      S.-  nU$ )Nr   r   )rN   name)r3   rR   rN   r   )rt   ru   rv   rN   rw   r"   	namesRefsrm   s       r#   _replacePerson<makeModCGILinks.<locals>.modCGILinks.<locals>._replacePerson   sV    QJ==,D==& (	* 5xATU* 
 r&   c                    > U R                  S5      nTc  U$ TR                  U5      nU(       a*  UR                  nUc  U$ TU[        T" U5      TS5      S.-  nU$ )Nr   r   )rO   r|   )r3   rR   rO   r   )rt   ru   rv   rO   rw   characterRefsrh   r"   s       r#   _replaceCharacter?makeModCGILinks.<locals>.modCGILinks.<locals>._replaceCharacter   sr    QJ#!! $$Z0D"..&%%)#.	* 5xATU- 
 r&   <z&lt;>z&gt;z<a href="\1">\1</a>)r9   _re_hrefsubr   r=   r   r   )r!   rx   r}   r   ry   r~   r   rw   rh   r"   rk   rm   s    ```   r#   modCGILinks$makeModCGILinks.<locals>.modCGILinks   s     M		 				 			 	 IIc6"**37.2OOM-NN>- 15r&   rE   )r(   rk   rm   rh   )rk   rm   rh   r"   r   rw   s   ```` @r#   makeModCGILinksr      s:     %X.I/ /` $K%K+Kr&   z	<a href="ztt%(movieID)s">%(title)s</a>znm%(personID)s">%(name)s</a>zch%(characterID)s">%(name)s</a>)rk   rm   rh   ascii)rk   rm   rh   r"   c                 x    [        U R                  S0 5      R                  5       5      nUR                  5         U$ )z4Return a sorted list of seasons of the given series.episodes)rX   rR   keyssort)mseasonss     r#   sortedSeasonsr     s.    155R(--/0GLLNNr&   c                 R   / nUnUc  [        U 5      nO[        U[        [        45      (       d  U/nU Ho  n[        U R	                  S0 5      R	                  U0 5      R                  5       5      nUR                  5         U H  nUR                  U S   U   U   5        M     Mq     U$ )zwReturn a sorted list of episodes of the given series,
considering only the specified season(s) (every season, if None).r   )r   r   rY   rX   rR   r   r   append)r   seasonr   r   r!   eps_indxes          r#   sortedEpisodesr     s     HG~"&5$-00hGj"-11!R8==?@AOOAjM!,Q/0  
 Or&   z\b(nm|tt|ch|co)([0-9]{7,8})\bc                 T   Uc  / nUc  0 n[        U0 UD6n[        R                  U 5      nU(       d  gUR                  S5      nUR                  S5      nUS:X  a  UR	                  XqS9$ US:X  a  UR                  XqS9$ US:X  a  UR                  XqS9$ US:X  a  UR                  XqS9$ g)	a:  Return a Movie, Person, Character or Company object for the given URL;
info is the info set to retrieve, args and kwds are respectively a list
and a dictionary or arguments to initialize the data access system.
Returns None if unable to correctly parse the url; can raise
exceptions if unable to retrieve the data.Nr   r.   tt)infonmchco)r	   _re_imdbIDurlr<   r3   	get_movie
get_personget_characterget_company)urlr   argskwdsiart   imdbtypeimdbIDs           r#   	get_byURLr   4  s     ||	t	t	B  %E{{1~H[[^F4||F|..	T	}}V}//	T	22	T	~~f~00r&   c                 "    U R                  5       $ )a7  Given an URL string or a Movie, Person or Character instance,
returns an URL to the full-size version of the cover/headshot,
or None otherwise.  This function is obsolete: the same information
are available as keys: 'full-size cover url' and 'full-size headshot',
respectively for movies and persons/characters.)get_fullsizeURL)rV   s    r#   fullSizeCoverURLr   R  s       r&   c                      [        U S5      S   $ )zReturn a key (the ones used to access information in Movie and
other classes instances) converted to the style of the XML output.r0   r   )r   rd   s    r#   keyToXMLr   [  s     CQr&   c                 *    [        [        U 5      5      $ )zTranslate a given key.)r   r   r   s    r#   translateKeyr   a  s    Xc]r&   )personmovie	charactercompanyc                     U R                  S5      nU(       a"  U R                  S5      S:X  a  [        U5      nU$ U R                  $ )zKReturn the name of the tag, taking it from the 'key' attribute,
if present.rd   keytypeint)rR   r   tag)r   keyAttrs     r#   tagToKeyr   s  s<     ggenG779&'lG77Nr&   c                 p    U R                  S5      nUS:X  a  [        U5      nU$ US:X  a  [        U5      nU$ )z0Return tagValue, handling some type conversions.typer   float)rR   r   r   )r   tagValuetagTypes      r#   _valueWithTyper   ~  s?    ggfoG%x= O 
G	?Or&   )	imdbindexkindyear)r   )r   countryc           	      ^	  ^^ SmUc  0 nUc  0 n[        U 5      mU R                  5       =(       d    S/S   nU R                  =(       d    SR                  5       nU(       dW  TS:X  aQ  U R                  5       nU(       a:  US   R                  (       a&  US   R                  =(       d    SR                  5       nU R	                  S5      nU(       a%  XT'   UR                  U/ 5      R                  T5        U R                  [        ;   Gam  [        T   " 5       mU R	                  S5      n	U	(       a
  U(       d  U	nOUn	U	Tl	        / n
U R	                  S5      nTS:X  aN  UTl
        [        n
U R                  S	5      nUb,  TR                  UR                  5        U R                  U5        OTS
:X  a7  UTl        [         n
U R                  S5      nU(       d  U R                  S5      nOITS:X  a  UTl        [         n
U R                  S5      nO$TS:X  a  UTl        [&        n
U R                  S5      nWb,  TR)                  UR                  5        U R                  U5        U
 HV  nUTR*                  ;   a  M  U R                  U5      nUc  M+  [-        XR                  5      TR*                  [        U5      '   MX     U R                  S5      nUb"  UR                  Tl        U R                  U5        U R                  S5      nUb*  [1        USX#US9TR*                  S'   U R                  U5        U R                  S5      nUb$  [1        USUX4S9nUTl        U R                  U5        U(       d  T$ U4S jnOU(       aU  U R                  S5      nUb4  UR                  =(       d    SR                  5       nU(       a  USU-  -  nU$ [-        X5      nU$ Ub'  [        U5      nU[4        ;   a	  / mU4S jnO0 mU4S jnO	0 mUU4S jnU R                  5        HV  n[        U5      nU R                  [        ;   a  UTR7                  5       ;   a  M8  [1        USUX4S9nU(       d  MM  U" UU5        MX     U(       a6  T[        ;   a,  UTl        UTl        [=        UR?                  5       5      Tl         T$ )z!Recursively parse a tree of tags.Nr   r0   rv   infosetzaccess-systemidr   rs   r   zlong imdb canonical namer|   r   r   r/   z
episode-ofF)	_topLevel_as_infoset2keys_key2infosetz
episode ofzcurrent-rolec                 <   > TR                   R                  X05      $ rE   )dataupdaterd   re   rv   s     r#   rH   parseTags.<locals>.<lambda>  s    DII$4$4c\$Br&   z::%sc                 &   > TR                  U5      $ rE   )r   r   s     r#   rH   r     s    E(:r&   c                 (   > TR                  X05      $ rE   r   r   s     r#   rH   r     s    SL(Ar&   c                 *   > TR                  TU05      $ rE   r   )rd   re   rv   r|   s     r#   rH   r     s    DKKu$>r&   )!r   getchildrenr-   striprR   
setdefaultr   r   _MAP_TOP_OBJaccessSystemrM   
_titleTagsfind	set_titleremoverN   	_nameTagsrO   rP   _companyTagsset_namer   r   r/   	parseTagscurrentRole_TAGS_TO_LIST_additional_keysinfoset2keyskey2infosetrX   r   current_info)r   r   r   r   r   
firstChildtagStr
tagContentr   itemAs	tagsToGettheIDttitletheNametdataTagnotesTag	episodeOfcRolecr_addertagNotesr/   firstChildNamesubTag	subTagKeysubItemrv   r|   s                              @@r#   r   r     s    DC=D//#-vq1Jhhn"##%Fdfn__&
*Q-,, m((.B557Fggi G$T  "-44T:
ww,D!#)F"	7? DL"IXXg&F!v{{+

6"x %%	((#=>!hhv.G$#( %	((6*"!&(	((6*"gll+

7#ADII~hhqkG"/=g||/T		(7+,  88G$!DJJJx HH\*	 &/	U47=I'KDIIl# JJy!(5Es)6SB!DJJu KB	88G$]](b//1E&5.(  $C0F		!*-]*D:FDAF>//#V$	77l"yD4I4I4K'KFe*7T79g& $ T\))' !3!3!56Kr&   c                 R    SSK n[        UR                  R                  U 5      5      $ )zeParse a XML string, returning an appropriate object (usually an
instance of a subclass of _Container.r   N)
lxml.etreer   etree
fromstring)xmllxmls     r#   parseXMLr    s!     TZZ**3/00r&   z (?:[(])([a-zA-Z]+?)(?: title[)])z\(.*?\)c                    / n[        U R                  S5      =(       d    / U R                  S5      =(       d    / -   5      nU H  nUR                  S5      n[        U5      S:X  a  [        R                  US   5      nU(       a  UR                  5       S   nOTUS   R                  S5      S   n[        R                  SU5      R                  5       n[        R                  " U5      nOS	nUR                  XCS   45        M     U$ )
zdGiven a movie, return a list of tuples in (lang, AKA) format;
lang can be None, if unable to detect.akaszakas from release infor,   r.   r   r   ,r0   N)setrR   r8   r:   _re_akas_langr<   groups_re_akas_countryr=   r   r   r   )r   lang_and_akar  akalanguager   s         r#   akasLanguagesr    s     L		&!'REII6N,O,USUVWDiios8q=$++CF3H#??,Q/ a&,,s+A.*..r7;AAC'++G4HX1v./% & r&   c                     U R                  5       nU S   R                  5       nUR                  5       n/ n[        R                  " SXV5      R	                  5       nUR                  XS   S45        [        U 5       H^  u  pIU	R                  5       n[        R                  " SXV5      R	                  5       nU(       a
  X4:X  a  US-  nUR                  XU45        M`     UR                  SS9  U(       a  U V
s/ s H  oS   PM	     sn
$ U$ s  sn
f )a,  Return a list of movie AKAs, sorted by their similarity to
the given title.
If _titlesOnly is not True, similarity information are returned.
If _preferredLang is specified, AKAs in the given language will get
a higher score.
The return is a list of title, or a list of tuples if _titlesOnly is False.rs   Nr   Treverse)guessLanguagelowerdifflibSequenceMatcherratior   r  r   )r   rs   _titlesOnly_preferredLangr  m_titlel_titlescoresscorer  rG   s              r#   sortAKAsBySimilarityr  3  s     ""$HGn""$GkkmGF##D';AACE
MM5.$/0&u-))+''g?EEGn8QJEu8,- . KKK$%f!f%%M &s   8Dc           	      ^   / n[        U 5       H  u  pEX:X  d  M  UR                  U5        M     U(       ar  / nU HG  nUR                  [        R                  " SUR	                  5       UR	                  5       5      U5        MI     UR                  SS9  U Vs/ s H  owS   PM	     nnU$ s  snf )zReturn a list of AKAs of a movie, in the specified language.
If _searchedTitle is given, the AKAs are sorted by their similarity
to it.NTr  r   )r  r   r  r  r  r   )r   lang_searchedTitler  r  r  r  rG   s           r#   getAKAsInLanguager!  P  s     D&u-KK . CMM'11$		2@2F2F2HJKNP  	D!$%f!f%K &s   B*c                 F   U(       a  UOSn [         R                  " XP5      S   nSU ;   a  US-  nSU ;  a  US-  nOUS-  nU(       a  USU-  -  nU(       a  US	U-  -  nU(       a  S
R	                  U5      nUSU-  -  nUS-  nU$ ! [         a    [        SU -  5      ef = f)z%Return resized and cropped image url.z(https://m.media-amazon.com/images/\w/\w+r   z)Image url not matched. Original url: "%s"z@@@z._V1_z@._V1_zSX%s_zSY%s_r  zCR%s_z.jpg)rer^   
IndexErrorr   rZ   )imagewidthheightcropcustom_regexregexStringresultImagecropValss           r#   resizeImager.  b  s     #/,4_KOjj4Q7 u}s
%wxw&w''88D>w))6K-  OCuMNNOs   B B )Nr)   rE   )NNN)TNNN)TN)NNNN)T__doc__
__future__r   r   r   r   r  gettextr$  sysimdb.localer   
hexversionPY2cgir   htmlimdbr	   r
   r   r   imdb._exceptionsr   imdb.Characterr   imdb.Companyr   imdb.linguisticsr   
imdb.Movier   imdb.Personr   
imdb.utilsr   r   r   r   r   
textdomaincompileI_re_hrefr=   r   r(   r$   r]   r;   rC   ro   r   	_movieTxt
_personTxt_characterTxtmodHtmlLinksmodHtmlLinksASCIIr   r   r   r   r   r   r   r   r[   rX   valuesr   r   r   r   r   r   r   r   r  r  r
  r  r  r!  r.  rF   s   0r#   <module>rJ     s   $ S R   	 
 	nny  W V & $   )   Y Y   8  ::-rtt4ll	  ' ::n%@A#L !Dt"5!,tTn;~ ,,/MM	..1OO
4412	Z,9;#Y*1>-46 
& 

;<<!  	 D1F1F1H,IJ,IqtTl,IJK   \ " +
	'zz1 

=>::j) 
6:$g Ks   8G+