'Search for entries on 1337x'

@plugin.internet(log)
def search(self, task, entry, config):

    if (not isinstance(config, dict)):
        config = {}
    order_by = u''
    sort_order = u''
    if isinstance(config.get(u'order_by'), str):
        if (config[u'order_by'] != u'leechers'):
            order_by = u'/{0}/desc'.format(config[u'order_by'])
            sort_order = u'sort-'
    entries = set()
    for search_string in entry.get(u'search_strings', [entry[u'title']]):
        query = u'{0}search/{1}{2}/1/'.format(sort_order, quote(search_string.encode(u'utf8')), order_by)
        log.debug(u'Using    search    params:    %s;    ordering    by:    %s', search_string, (order_by or u'default'))
        try:
            page = task.requests.get((self.base_url + query))
            log.debug(u'requesting:    %s', page.url)
        except RequestException as e:
            log.error(u'1337x    request    failed:    %s', e)
            continue
        soup = get_soup(page.content)
        if (soup.find(u'div', attrs={u'class': u'tab-detail'}) is not None):
            for link in soup.find(u'div', attrs={u'class': u'tab-detail'}).findAll(u'a', href=re.compile(u'^/torrent/')):
                li = link.parent.parent.parent
                title = str(link.text).replace(u'...', u'')
                info_url = (self.base_url + str(link.get(u'href'))[1:])
                seeds = int(li.find(u'span', class_=u'green').string)
                leeches = int(li.find(u'span', class_=u'red').string)
                size = str(li.find(u'div', class_=u'coll-4').string)
                size = parse_filesize(size)
                e = Entry()
                e[u'url'] = info_url
                e[u'title'] = title
                e[u'torrent_seeds'] = seeds
                e[u'torrent_leeches'] = leeches
                e[u'search_sort'] = torrent_availability(e[u'torrent_seeds'], e[u'torrent_leeches'])
                e[u'content_size'] = size
                entries.add(e)
    return entries
