from urllib import quote
from lxml import html
from searx.engines.xpath import extract_text
from urlparse import urljoin

url = 'https://1337x.to/'
search_url = url + 'search/{search_term}/{pageno}/'
categories = ['videos']
paging = True


def request(query, params):
    params['url'] = search_url.format(search_term=quote(query), pageno=params['pageno'])

    return params


def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    for result in dom.xpath('//table[contains(@class, "table-list")]/tbody//tr'):
        href = urljoin(url, result.xpath('./td[contains(@class, "name")]/a[2]/@href')[0])
        title = extract_text(result.xpath('./td[contains(@class, "name")]/a[2]'))

        results.append({'url': href,
                        'title': title,
                        'content': ''})

    return results

@@ -85,16 +85,57 @@
 ct_text%0A
+from searx.utils import get_torrent_size%0A
 from url
@@ -746,122 +746,640 @@
 '))%0A
-%0A        results.append(%7B'url': href,%0A                        'title': title,%0A                        'content': '
+        seed = extract_text(result.xpath('.//td%5Bcontains(@class, %22seeds%22)%5D'))%0A        leech = extract_text(result.xpath('.//td%5Bcontains(@class, %22leeches%22)%5D'))%0A        filesize_info = extract_text(result.xpath('.//td%5Bcontains(@class, %22size%22)%5D/text()'))%0A        filesize, filesize_multiplier = filesize_info.split()%0A        filesize = get_torrent_size(filesize, filesize_multiplier)%0A%0A        results.append(%7B'url': href,%0A                        'title': title,%0A                        'seed': seed,%0A                        'leech': leech,%0A                        'filesize': filesize,%0A                        'template': 'torrent.html
 '%7D)%0A

Add torrent infos