
    i                     n    d Z ddlmZ ddlmZ ddlmZ dddddZd	gZd
Zd
Z	dZ
e
dz   ZdZ	 dZ	 d Zd Zy)a  BT4G_ (bt4g.com) is not a tracker and doesn't store any content and only
collects torrent metadata (such as file names and file sizes) and a magnet link
(torrent identifier).

This engine does not parse the HTML page because there is an API in XML (RSS).
The RSS feed provides fewer data like amount of seeders/leechers and the files
in the torrent file.  It's a tradeoff for a "stable" engine as the XML from RSS
content will change way less than the HTML page.

.. _BT4G: https://bt4g.com/

Configuration
=============

The engine has the following additional settings:

- :py:obj:`bt4g_order_by`
- :py:obj:`bt4g_category`

With this options a SearXNG maintainer is able to configure **additional**
engines for specific torrent searches.  For example a engine to search only for
Movies and sort the result list by the count of seeders.

.. code:: yaml

  - name: bt4g.movie
    engine: bt4g
    shortcut: bt4gv
    categories: video
    bt4g_order_by: seeders
    bt4g_category: 'movie'

Implementations
===============

    )datetime)quote)etreezhttps://bt4gprx.comFXML)websiteuse_official_apirequire_api_keyresultsfilesTzR/search?q={search_term}&orderby={order_by}&category={category}&p={pageno}&page=rss	relevanceallc                 x    t         }|d   rd}t        j                  t        |       |t        |d         |d<   |S )N
time_rangetimepageno)search_termorder_bycategoryr   url)bt4g_order_by
search_urlformatr   bt4g_category)queryparamsr   s      #/root/searxng/searx/engines/bt4g.pyrequestr   K   sI    Hl%%%Lh	 & F5M M    c                 "   g }t        j                  | j                        }t        |      dk(  rg S |j	                  d      D ]  }|j                  d      j                  }|j                  d      j                  }|j                  d      j                  j                  d      }|j                  d      j                  }|j                  d      j                  }|j                  |||d	d	|d
   t        j                  |d      dd        |S )Nr   z./channel/itemtitleguiddescriptionz<br>linkpubDatezN/A   z%a,%d %b %Y %H:%M:%S %zztorrent.html)r   r    
magnetlinkseedleechfilesizepublishedDatetemplate)r   r   contentlenxpathfindtextsplitappendr   strptime)	respr
   search_resultsentryr    r#   fullDescriptionr&   r$   s	            r   responser8   Z   s    GYYt||,N >a	%%&67 


7#((zz&!&&**]388>>vFZZ',,
**Y',,(+A.!)!2!27<U!V*		

& Nr   N)__doc__r   urllib.parser   lxmlr   about
categoriespagingtime_range_supportr   r   r   r   r   r8    r   r   <module>rA      sq   #J    %		 Y
	  gg
 
r   