'Search for name from torrent411.'

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

    url_base = u'https://www.t411.al'
    if (not isinstance(config, dict)):
        config = {}
    category = config.get(u'category')
    if (category in list(CATEGORIES)):
        category = CATEGORIES[category]
    sub_categories = config.get(u'sub_category')
    if (not isinstance(sub_categories, list)):
        sub_categories = [sub_categories]
    filter_url = u''
    if isinstance(category, int):
        filter_url = (u'&cat=%s' % str(category))
        if (sub_categories[0] is not None):
            sub_categories = [SUB_CATEGORIES[c] for c in sub_categories]
            filter_url = ((filter_url + u'&') + u'&'.join([((urllib.parse.quote_plus((u'term[%s][]' % c[0])).encode(u'utf-8') + u'=') + str(c[1])) for c in sub_categories]))
    if ((u'series_season' in entry) and (u'series_episode' in entry)):
        season = entry[u'series_season']
        if (season in list(SEASONS)):
            filter_url = (((filter_url + (u'&term[%d][]' % SEASONS[season][0])) + u'=') + str(SEASONS[season][1]))
        episode = entry[u'series_episode']
        if (episode in list(EPISODES)):
            filter_url = (((filter_url + (u'&term[%d][]' % EPISODES[episode][0])) + u'=') + str(EPISODES[episode][1]))
    entries = set()
    for search_string in entry.get(u'search_strings', [entry[u'title']]):
        query = normalize_unicode(search_string)
        url_search = ((u'/torrents/search/?search=%40name+' + urllib.parse.quote_plus(query.encode(u'utf-8'))) + filter_url)
        opener = urllib.request.build_opener()
        opener.addheaders = [(u'User-agent', u'Mozilla/5.0')]
        response = opener.open((url_base + url_search))
        data = response.read()
        soup = get_soup(data)
        tb = soup.find(u'table', class_=u'results')
        if (not tb):
            continue
        for tr in tb.findAll(u'tr')[1:][:(-1)]:
            entry = Entry()
            nfo_link_res = re.search(u'torrents/nfo/\\?id=(\\d+)', str(tr))
            if (nfo_link_res is not None):
                tid = nfo_link_res.group(1)
            title_res = re.search(u'<a    href="//www.t411.al/torrents/([-A-Za-z0-9+&@#/%|?=~_|!:,.;]+)"    title="([^"]*)">', str(tr))
            if (title_res is not None):
                entry[u'title'] = native_str_to_text(title_res.group(2), encoding=u'utf-8')
            size = tr(u'td')[5].contents[0]
            entry[u'url'] = (u'https://www.t411.al/torrents/download/?id=%s' % tid)
            entry[u'torrent_seeds'] = tr(u'td')[7].contents[0]
            entry[u'torrent_leeches'] = tr(u'td')[8].contents[0]
            entry[u'search_sort'] = torrent_availability(entry[u'torrent_seeds'], entry[u'torrent_leeches'])
            size = re.search(u'([\\.\\d]+)    ([GMK]?)B', size)
            entry[u'content_size'] = parse_filesize(size.group(0))
            auth_handler = t411Auth(config[u'username'], config[u'password'])
            entry[u'download_auth'] = auth_handler
            entries.add(entry)
        return sorted(entries, reverse=True, key=(lambda x: x.get(u'search_sort')))
