
    *i                     ~     S SK J r    S SKJr  S SKJr   " S S\5      rg! \ a	    S SKJ r    N'f = f! \ a     N&f = f)    )
HTMLParser)prettyPrinter)retrieve_urlc            	       Z    \ rS rSrSrSrSrSrSSSS	S
SSSS.r " S S\	5      r
SS jrSrg)nyaasi    z1Class used by qBittorrent to search for torrents.zhttps://nyaa.sizNyaa.siT0_01_03_02_05_06_04_0)allanimebooksmusicpicturessoftwaretvmoviesc                   N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )nyaasi.NyaasiParser;   z>Parses Nyaa.si browse page for search results and stores them.c                    >  [         TU ]  5         X l        X0l        Xl        SU l        SU l        g! [         a    [        R                  " U 5         NCf = f)zConstruct a nyaasi html parser.

Parameters:
:param list res: a list to store the results in
:param str url: the base url of the search engine
:param str use_magnet: whether to link to magnet links or torrent
                       files
N)	super__init__	TypeErrorr   
engine_urluse_magnet_linksresultscurr
td_counter)selfresurl
use_magnet	__class__s       -/app/qBittorrent/data/nova3/engines/nyaasi.pyr   nyaasi.NyaasiParser.__init__>   sR    * "
 "O$.!LDI DO  *##D)*s   2  AAc                     US:X  a  U R                  U5        gUS:X  a<  U R                  S:X  a+   [        U5      nUR                  S5      U R                  S'   ggg! [
         a    SU R                  S'    gf = f)z+Tell the parser what to do with which tags.atd   zdata-timestamppub_dater   N)start_ar$   dictgetr#   KeyError)r%   tagattr	attr_dicts       r*   handle_starttag#nyaasi.NyaasiParser.handle_starttagS   ss    czT"A!5/ $T
I,5MM:J,KDIIj) "6   /,.DIIj)/s   )A A87A8c                 2    US:X  a  U R                  5         gg)z"Handle the closing of table cells.r.   N)start_td)r%   r5   s     r*   handle_endtag!nyaasi.NyaasiParser.handle_endtag^   s    d{     c                    [        U5      nSU;   a_  SU;  aY  US   R                  S5      (       a@  US   U R                  US   -   S.nU R                  (       d  U R                  US'   X0l        g	g	SU;   a  U R                  (       a  US   R                  S5      (       d  US   R	                  S5      (       d  g	U R
                  (       dN  US   R	                  S5      (       a5  U R                  US   -   U R                  S
'   U =R                  S-  sl        g	US   R                  S5      (       a:  U R
                  (       a(  US   U R                  S
'   U =R                  S-  sl        g	g	g	g	g	)z"Handle the opening of anchor tags.titleclasshrefz/view/)name	desc_linkr    zmagnet:?z.torrentNlink   )r2   
startswithr    r#   endswithr!   r$   )r%   r6   paramshits       r*   r1   nyaasi.NyaasiParser.start_ac   sE   $ZF& WF%:v11(;; &w%)__vf~%EG yy(,C% #I ! 6!diif~00<<"6N33J?? ,,v//
;;(,&.(HDIIf%OOq(OF^..z:: 11(.vDIIf%OOq(O 2 ; '0!r>   c                     U R                   S:  a  U =R                   S-  sl         U R                   S:  a4  U R                  R                  U R                  5        SU l        SU l         gg)z'Handle the opening of a table cell tag.r   rF      Nr   )r$   r"   appendr#   )r%   s    r*   r;   nyaasi.NyaasiParser.start_td   sU     !#1$ !###DII. 	"$ $r>   c                     U R                   S:  a  U R                   S::  a  U R                   S:X  a  UR                  5       U R                  S'   g
U R                   S:X  a(   [        UR                  5       5      U R                  S'   g
U R                   S:X  a(   [        UR                  5       5      U R                  S	'   g
g
g
g
! [         a    SU R                  S'    g
f = f! [         a    SU R                  S	'    g
f = f)zExtract data about the torrent.r   rM   rF   size   seedsr      leechN)r$   stripr#   int
ValueError)r%   datas     r*   handle_datanyaasi.NyaasiParser.handle_data   s     "t!';??a'(,

DIIf%__)0-0->		'* __)0-0->		'*
 % (<" & 0-/		'*0 & 0-/		'*0s$    &C &C! CC!C=<C=)r#   r    r"   r$   r!   )T)__name__
__module____qualname____firstlineno____doc__r   r8   r<   r1   r;   rZ   __static_attributes____classcell__)r)   s   @r*   NyaasiParserr   ;   s)    L	!*		/	 
	)<	%	 	r>   rc   c                    [        SR                  U R                  U R                  R	                  U5      U5      5      n/ nSnU R                  X@R                  U R                  5      n [        USR                  U5      -   5      nUR                  U5        U H  n[        U5        M     [        U5      S:  a  OUSS2	 US-  nM^  UR                  5         g)z
Retreive and parse engine search results by category and query.

Parameters:
:param what: a string with the search tokens, already escaped
             (e.g. "Ubuntu+Linux")
:param cat:  the name of a search category, see supported_categories.
z%{0}/?f=0&s=seeders&o=desc&c={1}&q={2}rF   z&p={}K   N)strformatr'   supported_categoriesr3   rc   use_magent_linksr   feedr   lenclose)	r%   whatcatr'   hitspageparserr&   eachs	            r*   searchnyaasi.search   s     96$((3377< !
 ""443H3HIsW^^D%99:CKKd#  4y2~QAID  	r>    N)r   )r\   r]   r^   r_   r`   r'   rC   ri   rh   r   rc   rs   ra   ru   r>   r*   r   r       sM    ;
CD
  hz hXr>   r   N)	r   ModuleNotFoundErrorhtml.parsernovaprinterr   helpersr   objectr   ru   r>   r*   <module>r{      sM   &'%
	)$
cV c  '&'  		s   ! 3 00<<