'Get a specified number of results for a query'

def _get_n_results(self, query, n):

    entries = []
    res = {u'_type': u'playlist', u'id': query, u'title': query}
    for pagenum in itertools.count():
        webpage = self._download_webpage(u'http://www.google.com/search', (u'gvsearch:' + query), note=(u'Downloading    result    page    %s' % (pagenum + 1)), query={u'tbm': u'vid', u'q': query, u'start': (pagenum * 10), u'hl': u'en'})
        for (hit_idx, mobj) in enumerate(re.finditer(u'<h3    class="r"><a    href="([^"]+)"', webpage)):
            if (not re.search((u'id="vidthumb%d"' % (hit_idx + 1)), webpage)):
                continue
            entries.append({u'_type': u'url', u'url': mobj.group(1)})
        if ((len(entries) >= n) or (not re.search(u'id="pnnext"', webpage))):
            res[u'entries'] = entries[:n]
            return res
