You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

  1. import itertools
  2. import re
  3. from .common import SearchInfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse,
  6. )
  7. class GoogleSearchIE(SearchInfoExtractor):
  8. """Information Extractor for Google Video search queries."""
  9. _MORE_PAGES_INDICATOR = r'id="pnnext" class="pn"'
  10. _MAX_RESULTS = 1000
  11. IE_NAME = u'video.google:search'
  12. _SEARCH_KEY = 'gvsearch'
  13. def _get_n_results(self, query, n):
  14. """Get a specified number of results for a query"""
  15. res = {
  16. '_type': 'playlist',
  17. 'id': query,
  18. 'entries': []
  19. }
  20. for pagenum in itertools.count(1):
  21. result_url = u'http://www.google.com/search?tbm=vid&q=%s&start=%s&hl=en' % (compat_urllib_parse.quote_plus(query), pagenum*10)
  22. webpage = self._download_webpage(result_url, u'gvsearch:' + query,
  23. note='Downloading result page ' + str(pagenum))
  24. for mobj in re.finditer(r'<h3 class="r"><a href="([^"]+)"', webpage):
  25. e = {
  26. '_type': 'url',
  27. 'url': mobj.group(1)
  28. }
  29. res['entries'].append(e)
  30. if (pagenum * 10 > n) or not re.search(self._MORE_PAGES_INDICATOR, webpage):
  31. return res