mirror of https://github.com/blackjack4494/yt-dlc
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
11 years ago
|
from __future__ import unicode_literals
|
||
|
|
||
12 years ago
|
import itertools
|
||
|
import re
|
||
|
|
||
|
from .common import SearchInfoExtractor
|
||
|
|
||
|
|
||
|
class GoogleSearchIE(SearchInfoExtractor):
|
||
11 years ago
|
IE_DESC = 'Google Video search'
|
||
12 years ago
|
_MAX_RESULTS = 1000
|
||
11 years ago
|
IE_NAME = 'video.google:search'
|
||
12 years ago
|
_SEARCH_KEY = 'gvsearch'
|
||
10 years ago
|
_TEST = {
|
||
|
'url': 'gvsearch15:python language',
|
||
|
'info_dict': {
|
||
|
'id': 'python language',
|
||
|
'title': 'python language',
|
||
|
},
|
||
|
'playlist_count': 15,
|
||
|
}
|
||
12 years ago
|
|
||
|
def _get_n_results(self, query, n):
|
||
|
"""Get a specified number of results for a query"""
|
||
|
|
||
11 years ago
|
entries = []
|
||
12 years ago
|
res = {
|
||
|
'_type': 'playlist',
|
||
|
'id': query,
|
||
11 years ago
|
'title': query,
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
for pagenum in itertools.count():
|
||
|
webpage = self._download_webpage(
|
||
8 years ago
|
'http://www.google.com/search',
|
||
|
'gvsearch:' + query,
|
||
|
note='Downloading result page %s' % (pagenum + 1),
|
||
|
query={
|
||
|
'tbm': 'vid',
|
||
|
'q': query,
|
||
|
'start': pagenum * 10,
|
||
|
'hl': 'en',
|
||
|
})
|
||
11 years ago
|
|
||
|
for hit_idx, mobj in enumerate(re.finditer(
|
||
|
r'<h3 class="r"><a href="([^"]+)"', webpage)):
|
||
|
|
||
|
# Skip playlists
|
||
|
if not re.search(r'id="vidthumb%d"' % (hit_idx + 1), webpage):
|
||
|
continue
|
||
12 years ago
|
|
||
11 years ago
|
entries.append({
|
||
12 years ago
|
'_type': 'url',
|
||
|
'url': mobj.group(1)
|
||
11 years ago
|
})
|
||
12 years ago
|
|
||
11 years ago
|
if (len(entries) >= n) or not re.search(r'id="pnnext"', webpage):
|
||
11 years ago
|
res['entries'] = entries[:n]
|
||
12 years ago
|
return res
|