'Search for name from iptorrents'

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

    categories = config.get(u'category', u'All')
    if (not isinstance(categories, list)):
        categories = [categories]
    categories = [(c if isinstance(c, int) else CATEGORIES[c]) for c in categories]
    filter_url = u'&'.join(((str(c) + u'=') for c in categories))
    entries = set()
    for search_string in entry.get(u'search_strings', [entry[u'title']]):
        query = normalize_unicode(search_string)
        query = quote_plus(query.encode(u'utf8'))
        url = u'{base_url}/t?{filter}&q={query}&qf='.format(base_url=BASE_URL, filter=filter_url, query=query)
        log.debug((u'searching    with    url:    %s' % url))
        req = requests.get(url, cookies={u'uid': str(config[u'uid']), u'pass': config[u'password']})
        if ((u'/u/' + str(config[u'uid'])) not in req.text):
            raise plugin.PluginError(u'Invalid    cookies    (user    not    logged    in)...')
        soup = get_soup(req.content, parser=u'html.parser')
        torrents = soup.find(u'table', {u'id': u'torrents'})
        results = torrents.findAll(u'tr')
        for torrent in results:
            if (torrent.th and (u'ac' in torrent.th.get(u'class'))):
                continue
            if torrent.find(u'td', {u'colspan': u'99'}):
                log.debug(u'No    results    found    for    search    %s', search_string)
                break
            entry = Entry()
            link = torrent.find(u'a', href=re.compile(u'download'))[u'href']
            entry[u'url'] = u'{base}{link}?torrent_pass={key}'.format(base=BASE_URL, link=link, key=config.get(u'rss_key'))
            entry[u'title'] = torrent.find(u'a', href=re.compile(u'details')).text
            seeders = torrent.findNext(u'td', {u'class': u'ac    t_seeders'}).text
            leechers = torrent.findNext(u'td', {u'class': u'ac    t_leechers'}).text
            entry[u'torrent_seeds'] = int(seeders)
            entry[u'torrent_leeches'] = int(leechers)
            entry[u'search_sort'] = torrent_availability(entry[u'torrent_seeds'], entry[u'torrent_leeches'])
            size = torrent.findNext(text=re.compile(u'^([\\.\\d]+)    ([GMK]?)B$'))
            size = re.search(u'^([\\.\\d]+)    ([GMK]?)B$', size)
            entry[u'content_size'] = parse_filesize(size.group(0))
            log.debug(u'Found    entry    %s', entry)
            entries.add(entry)
    return entries
