'Search for name from torrentday.'

@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]
    params = {u'cata': u'yes', (u'c%s' % u','.join((str(c) for c in categories))): 1, u'clear-new': 1}
    entries = set()
    for search_string in entry.get(u'search_strings', [entry[u'title']]):
        url = u'https://www.torrentday.com/browse.php'
        params[u'search'] = normalize_unicode(search_string).replace(u':', u'')
        cookies = {u'uid': config[u'uid'], u'pass': config[u'passkey'], u'__cfduid': config[u'cfduid']}
        try:
            page = requests.get(url, params=params, cookies=cookies).content
        except RequestException as e:
            raise PluginError((u'Could    not    connect    to    torrentday:    %s' % e))
        soup = get_soup(page)
        for tr in soup.find_all(u'tr', {u'class': u'browse'}):
            entry = Entry()
            title = tr.find(u'a', {u'class': u'torrentName'})
            entry[u'title'] = title.contents[0]
            log.debug(u'title:    %s', title.contents[0])
            torrent_url = tr.find(u'td', {u'class': u'dlLinksInfo'})
            torrent_url = torrent_url.find(u'a').get(u'href')
            torrent_url = (((u'https://www.torrentday.com/' + torrent_url) + u'?torrent_pass=') + config[u'rss_key'])
            log.debug(u'RSS-ified    download    link:    %s', torrent_url)
            entry[u'url'] = torrent_url
            (seeders, leechers) = tr.find_all(u'td', {u'class': [u'seedersInfo', u'leechersInfo']})
            entry[u'torrent_seeds'] = int(seeders.contents[0].replace(u',', u''))
            entry[u'torrent_leeches'] = int(leechers.contents[0].replace(u',', u''))
            entry[u'search_sort'] = torrent_availability(entry[u'torrent_seeds'], entry[u'torrent_leeches'])
            size = tr.find(u'td', text=re.compile(u'([\\.\\d]+)    ([TGMKk]?)B')).contents[0]
            size = re.search(u'([\\.\\d]+)    ([TGMKk]?)B', str(size))
            entry[u'content_size'] = parse_filesize(size.group(0))
            entries.add(entry)
    return sorted(entries, reverse=True, key=(lambda x: x.get(u'search_sort')))
