'Search for entries on MoreThanTV'

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

    params = {}
    if (u'category' in config):
        categories = (config[u'category'] if isinstance(config[u'category'], list) else [config[u'category']])
        for category in categories:
            params[CATEGORIES[category]] = 1
    if (u'tags' in config):
        tags = (config[u'tags'] if isinstance(config[u'tags'], list) else [config[u'tags']])
        tags = u',    '.join(tags)
        params[u'taglist'] = tags
    entries = set()
    params.update({u'tags_type': int(config[u'all_tags']), u'order_by': config[u'order_by'], u'search_submit': 1, u'order_way': config[u'order_way'], u'action': u'basic', u'group_results': 0})
    for search_string in entry.get(u'search_strings', [entry[u'title']]):
        params[u'searchstr'] = search_string.replace(u"'", u'')
        log.debug(u'Using    search    params:    %s', params)
        try:
            page = self.get((self.base_url + u'torrents.php'), params, config[u'username'], config[u'password'])
            log.debug(u'requesting:    %s', page.url)
        except RequestException as e:
            log.error(u'MoreThanTV    request    failed:    %s', e)
            continue
        soup = get_soup(page.content)
        for result in soup.findAll(u'tr', attrs={u'class': u'torrent'}):
            group_info = result.find(u'td', attrs={u'class': u'big_info'}).find(u'div', attrs={u'class': u'group_info'})
            title = group_info.find(u'a', href=re.compile(u'torrents.php\\?id=\\d+')).text
            url = (self.base_url + group_info.find(u'a', href=re.compile(u'torrents.php\\?action=download'))[u'href'])
            torrent_info = result.findAll(u'td', attrs={u'class': u'number_column'})
            size = re.search(u'(\\d+(?:[.,]\\d+)*)\\s?([KMG]B)', torrent_info[0].text)
            torrent_tags = u',    '.join([tag.text for tag in group_info.findAll(u'div', attrs={u'class': u'tags'})])
            e = Entry()
            e[u'title'] = title
            e[u'url'] = url
            e[u'torrent_snatches'] = int(torrent_info[1].text)
            e[u'torrent_seeds'] = int(torrent_info[2].text)
            e[u'torrent_leeches'] = int(torrent_info[3].text)
            e[u'torrent_internal'] = (True if group_info.find(u'span', attrs={u'class': u'flag_internal'}) else False)
            e[u'torrent_fast_server'] = (True if group_info.find(u'span', attrs={u'class': u'flag_fast'}) else False)
            e[u'torrent_sticky'] = (True if group_info.find(u'span', attrs={u'class': u'flag_sticky'}) else False)
            e[u'torrent_tags'] = torrent_tags
            e[u'content_size'] = parse_filesize(size.group(0))
            entries.add(e)
    return entries
