
    i                         d Z ddlmZ ddlmZ ddlmZmZmZ ddddddd	Z	d
gZ
dZdZdZdZdZdZdZdZdZdZd Zd Zy)z"Nyaa.si (Anime Bittorrent tracker)    )	urlencode)html)eval_xpath_getindexextract_textint_or_zerozhttps://nyaa.si/NFHTML)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsfilesTz6//table[contains(@class, "torrent-list")]//tr[not(th)]z.//td[1]/a[1]z.//td[2]/a[last()]z
.//td[3]/az.//td[4]/text()z.//td[6]/text()z.//td[7]/text()z.//td[8]/text()c                 x    t        | |d   d      }t        dz   |z   |d<   t        j                  d|d          |S )Npageno)qp?urlzquery_url --> %s)r   base_urlloggerdebug)queryparamsargss      #/root/searxng/searx/engines/nyaa.pyrequestr   *   sH    !	
D sNT)F5M
LL#VE]3M    c                 (   g }t        j                  | j                        }|j                  t              D ]W  }d}d}d}t        |t        dd      }|r|j                  j                  d      }|j                  t              d   }t        |      }	t        |j                  j                  d      z   }
|j                  t              D ]&  }|j                  j                  d      }d|v r|}%|}( t        |j                  t                    }t        |j                  t                    }t        |j                  t                     }t        |t"        dd      }d}|j%                  ||      }|j'                  |
|	||||||dd		       Z |S )
Nr    titlehrefmagnetz5Category: "{category}". Downloaded {downloads} times.)category	downloadsztorrent.html)	r   r!   contentseedleechfilesizetorrentfile
magnetlinktemplate)r   
fromstringtextxpathxpath_resultsr   xpath_categoryattribgetxpath_titler   r   xpath_torrent_linksr   xpath_seedsxpath_leechesxpath_downloadsxpath_filesizeformatappend)respr   domresultr)   magnet_linktorrent_linkr$   page_ar!   r"   linkr   r'   r(   r%   r&   s                    r   responserC   7   s   G
//$))
$C))M* 9
 'v~q"E**73H k*1-V$ &--++F33LL!45 	#D++//&)C3!  #	# 6<<45 FLL78  _ =>	 'v~q"E J..(i.H"$+)*
	
[9
v Nr   )__doc__urllib.parser   lxmlr   searx.utilsr   r   r   about
categoriespagingr   r0   r1   r4   r5   r9   r6   r7   r8   r   rC    r   r   <module>rL      s    ( "   ""&	 Y
	  I "" "!#	@r   