'Parses torrent download url from search results'

@plugin.internet(log)
def entries_from_search(self, name, url=None):

    name = normalize_unicode(name)
    if (not url):
        url = (u'http://www.newtorrents.info/search/%s' % quote(name.encode(u'utf-8'), safe=':/~?=&%'))
    log.debug((u'search    url:    %s' % url))
    html = requests.get(url).text
    html = re.sub(u'(</SCR.*?)...(.*?IPT>)', u'\\1\\2', html)
    soup = get_soup(html)
    torrents = []
    for link in soup.find_all(u'a', attrs={u'href': re.compile(u'down.php')}):
        torrent_url = (u'http://www.newtorrents.info%s' % link.get(u'href'))
        release_name = link.parent.next.get(u'title')
        seed = link.find_next(u'td', attrs={u'class': re.compile(u's')}).renderContents()
        if (seed == u'n/a'):
            seed = 0
        else:
            try:
                seed = int(seed)
            except ValueError:
                log.warning((u'Error    converting    seed    value    (%s)    from    newtorrents    to    integer.' % seed))
                seed = 0
        torrents.append(Entry(title=release_name, url=torrent_url, torrent_seeds=seed, search_sort=torrent_availability(seed, 0)))
    torrents.sort(reverse=True, key=(lambda x: x.get(u'search_sort', 0)))
    if (not torrents):
        dashindex = name.rfind(u'-')
        if (dashindex != (-1)):
            return self.entries_from_search(name[:dashindex])
        else:
            return torrents
    else:
        if (len(torrents) == 1):
            log.debug(u'found    only    one    matching    search    result.')
        else:
            log.debug((u'search    result    contains    multiple    matches,    sorted    %s    by    most    seeders' % torrents))
        return torrents
