from . import Searcher, urljoin_partial, ResultItem from ..settings import option class SearchEngine(Searcher): base_url = option['rutor_url'] search_path = '/search/0/0/100/2/{}' name = 'RuTor.org' icon = 'searcher_rutor.png' enabled = option.get_boolean('rutor_enable') # @UndefinedVariable def process(self, body): url_constructor = urljoin_partial(self.base_url) rows = list(filter(lambda x: len(x.findall('.//a')) == 3, body.findall('.//tr'))) for r in rows: links = r.findall('.//a') url = url_constructor(links[0].get('href').strip()) title = links[2].text seeders = int(list(r.findall('.//span[@class="green"]')[0].itertext())[0].strip()) leachers = int(list(r.findall('.//span[@class="red"]')[0].itertext())[0].strip()) size = list( list(filter(lambda x: len(list(x.itertext())) == 1 and list(x.itertext())[0].strip().endswith(('GB', 'MB')), r.findall('.//td')) )[0].itertext() )[0].strip() yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)