§
   $ˆZ�v‘hã                   ó‚   — d Z ddlZdZdddœZdddœZdZd	d
dœZdZdZd„ Z	d„ Z
d„ Zd„ Zd„ Z G d„ de¦  «        Zdd„ZdS )uø  Paging of the genre listing (docs/plan/genre-browser/010 Â§VÃ½pis). Pure: no Kodi, no network.

TMDb discover stops at page 500 (10 000 titles), Drama has far more. Sorted by date the listing therefore walks a
cursor: a page asks for titles released on or before the date of the last title it looked at, and skips the titles of
that date it has already seen. Only when a whole TMDb page lies on that one date does it ask for the next TMDb page of
the same date. So it goes from today back to the oldest title without holes or duplicates.

Sorted by rating or popularity the 500-page limit stays (10 000 titles is more than anyone pages through): the cursor is
the TMDb page and the position on it.

Films and series together ("Oboje") and the rules of the filter PÅ¯vod (wcs/quality/rules.py: one discover query per
rule) are several cursors merged by the sort key; a query is named '<media>' or '<media>/<rule>'. A title two rules
found shows once (the page remembers the titles of the last SEEN looked at). A cursor only moves over titles that were
looked at, so a filter that drops titles never loses one, and a page cut short by the request limit goes on where it
stopped. Every cursor is plain JSON (it lives in a window property and in the stack of previous pages).
é    Niô  Úprimary_release_dateÚfirst_air_date)ÚmovieÚtvÚrelease_date)ÚdateÚratingÚ
popularityzvote_average.desczpopularity.desc)r	   r
   i,  Ú_seenc                 ó:   — |                       dd¦  «        d         S )z/'movie' of a query name 'movie' or 'movie/svc'.ú/é   r   )Úsplit)Únames    ú_/Users/chudy/Library/Application Support/Kodi/addons/plugin.video.milionar/wcs/genres/cursor.pyÚmedia_ofr      s   € à�:Š:�c˜1ÑÔ˜aÔ Ð ó    c                 óš   — |                      t          |          ¦  «        p+|                      d¦  «        p|                      d¦  «        pdS )Nr   r   Ú )ÚgetÚ	ITEM_DATE)ÚmediaÚitems     r   Údate_ofr   "   sB   € Ø�8Š8•I˜eÔ$Ñ%Ô%Ðe¨¯ª°.Ñ)AÔ)AÐeÀTÇXÂXÐN^ÑE_ÔE_ÐeÐceÐer   c                 ó>   — |dk    rd„ | D ¦   «         S d„ | D ¦   «         S )zA cursor at the first page.r   c                 ó   — i | ]
}|d dg ddœ“ŒS )r   r   F)ÚlteÚpageÚskipÚdone© ©Ú.0Úms     r   ú
<dictcomp>zstart.<locals>.<dictcomp>)   s&   € ÐUÐUÐUÈ�˜2 q°"¸eÐDÐDÐUÐUÐUr   c                 ó   — i | ]	}|d dddœ“Œ
S )r   r   F)r   r   r    r!   r"   s     r   r%   zstart.<locals>.<dictcomp>*   s$   € ÐEÐEÐE¸ˆA˜ 1¨eÐ4Ð4ÐEÐEÐEr   r!   )ÚmediasÚsorts     r   Ústartr)   &   s3   € àˆv‚~€~ØUÐUÈfÐUÑUÔUÐUØEÐE¸fÐEÑEÔEÐEr   c                 ó  — t          |¦  «        }|dk    rTt          |          }|dz   |d<   |                     |dz   ¦  «        pd}|d         r|r|d         |k     r|d         ||dz   <   nt          |         |d<   |d         |d<   |S )z9The discover parameters of the next TMDb page of `media`.r   z.descÚsort_byz.lter   r   r   )ÚdictÚ
DATE_FIELDr   ÚSORT_BY)r   Úbaser(   ÚstateÚparamsÚfieldÚlimits          r   Ú
params_forr4   -   sœ   € å�$‰ZŒZ€FØˆv‚~€~Ý˜5Ô!ˆØ! G™OˆˆyÑØ—
’
˜5 6™>Ñ*Ô*Ð0¨bˆØ�Œ<ð 	2 ð 	2¨%°¬,¸Ò*>Ð*>Ø%*¨5¤\ˆF�5˜6‘>Ñ"øå# DœMˆˆyÑØ˜6”]€Fˆ6�NØ€Mr   c                 óæ   — |dk    rt          | |¦  «        }nO|dk    r%t          |                     d¦  «        pd¦  «        }n$t          |                     d¦  «        pd¦  «        }|| dk    rdndfS )zDThe merge key: the larger comes first (film before series on a tie).r   r	   Úvote_averager   r
   r   r   )r   Úfloatr   )r   r   r(   Úvalues       r   Ú_keyr9   <   s~   € àˆv‚~€~Ý˜˜tÑ$Ô$ˆˆØ	�Ò	Ð	Ý�d—h’h˜~Ñ.Ô.Ð3°!Ñ4Ô4ˆˆå�d—h’h˜|Ñ,Ô,Ð1°Ñ2Ô2ˆØ˜ Ò(Ð(�1�1¨aÐ0Ð0r   c                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	Ú_Walkerz0One media's cursor while a page is put together.c                 ó¨   — |t          |¦  «        c| _        | _        ||||f\  | _        | _        | _        | _        g dd c| _        | _        | _	        d S ©Nr   )
r   r   r   r/   r(   r0   ÚfetchÚbufferÚ	page_sizeÚlte_at_fetch)Úselfr   r/   r(   r0   r>   s         r   Ú__init__z_Walker.__init__J   sT   € Ø $¥h¨t¡n¤nÐˆŒ	�4”:Ø7;¸TÀ5È%Ð7OÑ4ˆŒ	�4”9˜dœj¨$¬*Ø9;¸QÀÐ6ˆŒ�T”^ TÔ%6Ð%6Ð%6r   c                 ó   — | j         d          S )Nr    )r0   ©rB   s    r   Úactivez_Walker.activeO   s   € Ø”:˜fÔ%Ð%Ð%r   c           	      óò  ‡ ‡‡— ‰                       ‰ j        t          ‰ j        ‰ j        ‰ j        ‰ j        ¦  «        ¦  «        }|€dS t          |¦  «        ‰ _        ‰ j        dk    rO‰ j        d         ‰ _        t          ‰ j        d         ¦  «        Š‰ j        d         Šˆˆˆ fd„|D ¦   «         ‰ _
        n't          |‰ j        d         d…         ¦  «        ‰ _
        ‰ j
        s‰                      ¦   «          dS )zIFetch the TMDb page the cursor points at; False when TMDb did not answer.NFr   r   r   c                 ób   •— g | ]+}‰r%t          ‰j        |¦  «        p‰‰k    r
|d          ‰v °)|‘Œ,S )Úid)r   r   )r#   Úrr   ÚseenrB   s     €€€r   ú
<listcomp>z _Walker.load.<locals>.<listcomp>\   sN   ø€ ÐzÐzÐz °cÐz½wÀtÄzÐSTÑ?UÔ?UÐ?\ÐY\ÐadÒ>dÐ>dÐijÐkoÔipÐtxÐixÐix˜1ÐixÐixÐixr   T)r>   r   r4   r/   r(   r0   Úlenr@   rA   Úsetr?   ÚlistÚ
_page_done)rB   Úresultsr   rK   s   ` @@r   Úloadz_Walker.loadR   sè   øøø€ à—*’*˜TœZ­°D´JÀÄ	È4Ì9ÐVZÔV`Ñ)aÔ)aÑbÔbˆØˆ?Ø�5Ý˜W™œˆŒØŒ9˜ÒÐØ $¤
¨5Ô 1ˆDÔÝ�t”z &Ô)Ñ*Ô*ˆDØ”*˜UÔ#ˆCØzÐzÐzÐzÐzÐz gÐzÑzÔzˆDŒKˆKå˜w t¤z°&Ô'9Ð':Ð':Ô;Ñ<Ô<ˆDŒKØŒ{ð 	Ø�OŠOÑÔÐØˆtr   c                 ó   — | j         d         S r=   ©r?   rE   s    r   Úheadz_Walker.headc   s   € ØŒ{˜1Œ~Ðr   c                 óÈ  — | j                              d¦  «        }| j        dk    rŒt          | j        |¦  «        p| j        d         }| j        d         r8|| j        d         k    r'| j        d                              |d         ¦  «         n:| j                             |d|d         g¬¦  «         n| j        dxx         dz  cc<   | j         s|                      ¦   «          |S )z1Look at the next title: the cursor moves past it.r   r   r   r   rI   r   )r   r   r   )	r?   Úpopr(   r   r   r0   ÚappendÚupdaterP   )rB   r   Úwhens      r   Útakez_Walker.takef   så   € àŒ{�Š˜qÑ!Ô!ˆØŒ9˜ÒÐÝ˜4œ: tÑ,Ô,ÐA°´
¸5Ô0AˆDØŒz˜%Ô ð G T¨T¬Z¸Ô->Ò%>Ð%>Ø”
˜6Ô"×)Ò)¨$¨t¬*Ñ5Ô5Ð5Ð5à”
×!Ò! d°¸$¸t¼*¸Ð!ÑFÔFÐFÐFàŒJ�vÐÐÔ !Ñ#ÐÐÑØŒ{ð 	Ø�OŠOÑÔÐØˆr   c                 ó|  — | j         sd| j        d<   d	S | j        dk    rQ| j        d         | j        k    r7| j        dxx         dz  cc<   | j        d         t          k    rd| j        d<   d	S d	S d	S | j                             | j        d         dz   d¬¦  «         | j        d         t          k    rd| j        d<   d	S d	S )
z³Every title of the fetched TMDb page was looked at. Only an empty page ends a cursor: TMDb answers a full
        page with 19 titles now and then (measured on Drama, 2026-10-27).Tr    r   r   r   r   r   )r   r   N)r@   r0   r(   rA   Ú	LAST_PAGErY   rE   s    r   rP   z_Walker._page_doneu   sç   € ð Œ~ð 
	*Ø!%ˆDŒJ�vÑÐÐØŒY˜&Ò Ð ØŒz˜%Ô  DÔ$5Ò5Ð5Ø”
˜6Ð"Ð"Ô" aÑ'Ð"Ð"Ñ"Ø”:˜fÔ%­	Ò1Ð1Ø)-�D”J˜vÑ&Ð&Ð&ð 6Ð5à1Ð1ð ŒJ×Ò 4¤:¨fÔ#5¸Ñ#9ÀÐÑBÔBÐBØŒz˜&Ô!¥IÒ-Ð-Ø%)�”
˜6Ñ"Ð"Ð"ð .Ð-r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rC   rF   rR   rU   r[   rP   r!   r   r   r;   r;   G   sw   € € € € € Ø:Ð:ðEð Eð Eð
&ð &ð &ðð ð ð"ð ð ðð ð ð*ð *ð *ð *ð *r   r;   é   é   c                 ó€  ‡ ‡‡‡— |rt          j        |¦  «        nt          t          ‰¦  «        ‰¦  «        Šˆ ˆˆˆfd„‰D ¦   «         }‰                     t
          g ¦  «        }	ddddddœ}
t          |t          d„ |D ¦   «         ¦  «        ¦  «        }g }t          |¦  «        |k     �rØd„ |D ¦   «         }d}|dt          d||
d         z
  ¦  «        …         }|rYt          |¦  «        d	k    rF|
dxx         t          |¦  «        z  cc<   t           |d
„ |D ¦   «         ¦  «        ¦  «        sd|
d<   �nN|D ]w}| 
                    ¦   «         r]|j        sV|
d         |k    rd}nG|
dxx         d	z  cc<   |                     ¦   «         sdx|
d<   }n| 
                    ¦   «         r|j        ¯V|r nŒx|rnÑd„ |D ¦   «         }|snÂt          |ˆfd„¬¦  «        }|                     ¦   «         }|
dxx         d	z  cc<   d                     |j        |d         ¦  «        }||	v r�Œ‰|� ||j        |¦  «        r<|	                     |¦  «         |	dt$           …= |                     |j        |f¦  «         t          |¦  «        |k     �°Øt          d„ |D ¦   «         ¦  «        |
d<   t          |¦  «        |k    p|
d         |
d<   |‰|
fS )u  One page of the listing.

    fetch(media, params) -> TMDb results (list) or None; queries: {query name: base discover params};
    accept(query name, item) -> bool (the PÅ¯vod filter; None keeps everything); parallel(callables) -> results runs
    the first fetches of several cursors at once (None: one after another).
    Returns (items [(media, item)], next cursor, info {'requests', 'looked', 'complete', 'end', 'failed'}):
    `complete` = the page is full or the listing ended; `end` = nothing comes after this page.
    c           	      óV   •— g | ]%}|‰v ¯t          |‰|         ‰‰|         ‰¦  «        ‘Œ&S r!   )r;   )r#   Únr>   Úqueriesr(   r0   s     €€€€r   rL   zpage.<locals>.<listcomp>�   s=   ø€ Ð\Ð\Ð\ÀÐQRÐV[ÐQ[ÐQ[�w�q˜' !œ* d¨E°!¬H°eÑ<Ô<ÐQ[ÐQ[ÐQ[r   r   F)ÚrequestsÚlookedÚcompleteÚendÚfailedc              3   óB   K  — | ]}|                      ¦   «         ¯d V — ŒdS )r   N)rF   ©r#   Úws     r   ú	<genexpr>zpage.<locals>.<genexpr>“   s/   è è € Ð(JÐ(J¨q¸q¿xºx¹z¼zÐ(J¨Ð(JÐ(JÐ(JÐ(JÐ(JÐ(Jr   c                 óH   — g | ]}|                      ¦   «         ¯|j        °|‘Œ S r!   ©rF   r?   rn   s     r   rL   zpage.<locals>.<listcomp>–   s,   € ÐDÐDÐD˜¨¯ª©
¬
ÐD¸1¼8ÐD�!ÐDÐDÐDr   Nrh   r   c                 ó   — g | ]	}|j         ‘Œ
S r!   )rR   rn   s     r   rL   zpage.<locals>.<listcomp>›   s   € Ð 7Ð 7Ð 7¨A ¤Ð 7Ð 7Ð 7r   Trl   c                 ó    — g | ]}|j         ¯	|‘ŒS r!   rT   rn   s     r   rL   zpage.<locals>.<listcomp>«   s   € Ð0Ð0Ð0�q q¤xÐ0�Ð0Ð0Ð0r   c                 óT   •— t          | j        |                      ¦   «         ‰¦  «        S ©N)r9   r   rU   )ro   r(   s    €r   ú<lambda>zpage.<locals>.<lambda>®   s   ø€ ­$¨q¬w¸¿º¹¼À$Ñ*GÔ*G€ r   )Úkeyri   z{}:{}rI   c              3   óP   K  — | ]!}|                      ¦   «          o|j         V — Œ"d S rv   rr   rn   s     r   rp   zpage.<locals>.<genexpr>¸   s5   è è € ÐGÐG¸!˜!Ÿ(š(™*œ*�nÐ5¨Q¬X¨ÐGÐGÐGÐGÐGÐGr   rk   rj   )ÚcopyÚdeepcopyr)   ÚtupleÚ
setdefaultÚSEEN_KEYÚmaxÚsumrM   ÚallrF   r?   rR   r[   Úformatr   r   rX   ÚSEEN)r>   rg   r(   ÚcursorÚsizeÚmax_requestsÚacceptÚparallelÚwalkersrK   ÚinfoÚitemsÚhungryÚstuckÚbatchÚwalkerÚreadyr   Úidentityr0   s   ```                @r   r   r   …   sM  øøøø€ ð &,ÐL�DŒM˜&Ñ!Ô!Ð!µµu¸W±~´~ÀtÑ1LÔ1L€EØ\Ð\Ð\Ð\Ð\Ð\Ð\ÀgÐ\Ñ\Ô\€GØ×Ò�H bÑ)Ô)€DØ Q°EÀ%ÐSXÐYÐY€Då�|¥SÐ(JÐ(J°GÐ(JÑ(JÔ(JÑ%JÔ%JÑKÔK€LØ€EÝ
ˆe‰*Œ*�tÒ
Ñ
ØDÐD˜WÐDÑDÔDˆØˆØÐ?�˜A˜|¨d°:Ô.>Ñ>Ñ?Ô?Ð?Ô@ˆØð 	�˜E™
œ
 Qš˜Ø�ÐÐÔ¥ E¡
¤
Ñ*ÐÐÑÝ�x�xÐ 7Ð 7°Ð 7Ñ 7Ô 7Ñ8Ô8Ñ9Ô9ð Ø!%��X‘ÙØð 
	ð 
	ˆFØ—-’-‘/”/ð ¨&¬-ð Ø˜
Ô# |Ò3Ð3Ø �EØØ�ZÐ Ð Ô  AÑ%Ð Ð Ñ Ø—{’{‘}”}ð Ø-1Ð1�D˜‘N UØð —-’-‘/”/ð ¨&¬-ð ð ð Ø�ðàð 	ØØ0Ð0˜GÐ0Ñ0Ô0ˆØð 	ØÝ�UÐ GÐ GÐ GÐ GÐHÑHÔHˆØ�{Š{‰}Œ}ˆØˆXˆˆŒ˜!Ñˆˆ‰Ø—>’> &¤,°°T´
Ñ;Ô;ˆØ�tÐÐÙØˆ>˜V˜V F¤K°Ñ6Ô6ˆ>Ø�KŠK˜Ñ!Ô!Ð!Ø�V•t�e�V�Ø�LŠL˜&œ,¨Ð-Ñ.Ô.Ð.õE ˆe‰*Œ*�tÒ
Ñ
õF ÐGÐG¸wÐGÑGÔGÑGÔG€Dˆ�KÝ˜5‘z”z TÒ)Ð8¨T°%¬[€DˆÑØ�%˜ÐÐr   )Nrb   rc   NN)ra   rz   r]   r-   r   ÚSORTSr.   rƒ   r~   r   r   r)   r4   r9   Úobjectr;   r   r!   r   r   ú<module>r”      sò   ððð ð  €€€à€	Ø-Ð5EÐFÐF€
Ø$Ð,<Ð=Ð=€	Ø(€Ø(Ð8IÐ
JÐ
J€Ø
€Ø€ð!ð !ð !ð
fð fð fðFð Fð Fðð ð ð1ð 1ð 1ð;*ð ;*ð ;*ð ;*ð ;*ˆfñ ;*ô ;*ð ;*ð|5ð 5ð 5ð 5ð 5ð 5r   