diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-05-13 19:53:52 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-05-13 19:53:52 +0200 |
commit | 99a5ae3f8ed30ee7b6fb723232895d7836afbc2d (patch) | |
tree | 50b5440db38f438e4b32c69e4761fdb9f0fe3355 /youtube_dl | |
parent | c7563c528b60146baf28dffcacdc7e7fad5e8bd4 (diff) |
Simplify generic search IE (Closes #839)
Diffstat (limited to 'youtube_dl')
-rwxr-xr-x | youtube_dl/InfoExtractors.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 3e737b8d1..ce959a6df 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -190,21 +190,21 @@ class InfoExtractor(object): class SearchInfoExtractor(InfoExtractor): """ - Base class for search queries extractors + Base class for paged search queries extractors. They accept urls in the format _SEARCH_KEY(|all|[0-9]):{query} + Instances should define _SEARCH_KEY and _MAX_RESULTS. """ - _max_results = 0 # The maximum number of results the extractor can get @classmethod - def _VALID_URL(cls): - return r'%s(?P<prefix>|\d+|all):(?P<query>[\s\S]+)' % cls._SEARCH_KEY + def _make_valid_url(cls): + return r'%s(?P<prefix>|[1-9][0-9]*|all):(?P<query>[\s\S]+)' % cls._SEARCH_KEY @classmethod def suitable(cls, url): - return re.match(cls._VALID_URL() , url) is not None + return re.match(cls._make_valid_url(), url) is not None def _real_extract(self, query): - mobj = re.match(self._VALID_URL(), query) + mobj = re.match(self._make_valid_url(), query) if mobj is None: raise ExtractorError(u'Invalid search query "%s"' % query) @@ -213,14 +213,14 @@ class SearchInfoExtractor(InfoExtractor): if prefix == '': return self._get_n_results(query, 1) elif prefix == 'all': - return self._get_n_results(query, self._max_results) + return self._get_n_results(query, self._MAX_RESULTS) else: n = int(prefix) if n <= 0: raise ExtractorError(u'invalid download number %s for query "%s"' % (n, query)) - elif n > self._max_results: - self._downloader.report_warning(u'%s returns max %i results (you requested %i)' % (self._SEARCH_KEY, self._max_results, n)) - n = self._max_results + elif n > self._MAX_RESULTS: + self._downloader.report_warning(u'%s returns max %i results (you requested %i)' % (self._SEARCH_KEY, self._MAX_RESULTS, n)) + n = self._MAX_RESULTS return self._get_n_results(query, n) def _get_n_results(self, query, n): @@ -1378,7 +1378,7 @@ class GenericIE(InfoExtractor): class YoutubeSearchIE(SearchInfoExtractor): """Information Extractor for YouTube search queries.""" _API_URL = 'https://gdata.youtube.com/feeds/api/videos?q=%s&start-index=%i&max-results=50&v=2&alt=jsonc' - _max_results = 1000 + _MAX_RESULTS = 1000 IE_NAME = u'youtube:search' _SEARCH_KEY = 'ytsearch' @@ -1422,7 +1422,7 @@ class YoutubeSearchIE(SearchInfoExtractor): class GoogleSearchIE(SearchInfoExtractor): """Information Extractor for Google Video search queries.""" _MORE_PAGES_INDICATOR = r'id="pnnext" class="pn"' - _max_results = 1000 + _MAX_RESULTS = 1000 IE_NAME = u'video.google:search' _SEARCH_KEY = 'gvsearch' @@ -1453,7 +1453,7 @@ class GoogleSearchIE(SearchInfoExtractor): class YahooSearchIE(SearchInfoExtractor): """Information Extractor for Yahoo! Video search queries.""" - _max_results = 1000 + _MAX_RESULTS = 1000 IE_NAME = u'screen.yahoo:search' _SEARCH_KEY = 'yvsearch' |