on master help sign in
[fix] fixes google play engines and adds thumbnails to their results (#1612)

fix google play apps, google play apps, google play music engines xpath engine: thumbnail_xpath can define an optional thumbnail

commit87baa74a863ac74ae4c86bbfcb04148ba7f70696 authorVenca24 <Venca24@users.noreply.github.com> dateThu 25 Jul 2019, 07:46 (7 years ago) parentd0dd296
2 files changed+37−17
searx/engines/xpath.py+16−2 searx/settings.yml+21−15
searx/engines/xpath.py+16−2
@@ -7,6 +7,7 @@ search_url = None
77url_xpath = None
88content_xpath = None
99title_xpath = None
10+thumbnail_xpath = False
1011paging = False
1112suggestion_xpath = ''
1213results_xpath = ''
@@ -40,7 +41,9 @@ def extract_text(xpath_results):
4041 return ''.join(xpath_results)
4142 else:
4243 # it's a element
43− text = html.tostring(xpath_results, encoding='unicode', method='text', with_tail=False)
44+ text = html.tostring(
45+ xpath_results, encoding='unicode', method='text', with_tail=False
46+ )
4447 text = text.strip().replace('\n', ' ')
4548 return ' '.join(text.split())
4649
@@ -105,7 +108,18 @@ def response(resp):
105108 url = extract_url(result.xpath(url_xpath), search_url)
106109 title = extract_text(result.xpath(title_xpath))
107110 content = extract_text(result.xpath(content_xpath))
108− results.append({'url': url, 'title': title, 'content': content})
111+ tmp_result = {'url': url, 'title': title, 'content': content}
112+
113+ # add thumbnail if available
114+ thumbnail = None
115+ if thumbnail_xpath:
116+ thumbnail = extract_url(
117+ result.xpath(thumbnail_xpath), search_url
118+ )
119+ if thumbnail:
120+ tmp_result['img_src'] = thumbnail
121+
122+ results.append(tmp_result)
109123 else:
110124 for url, title, content in zip(
111125 (extract_url(x, search_url) for
searx/settings.yml+21−15
@@ -311,31 +311,37 @@ engines:
311311 shortcut : gos
312312
313313 - name : google play apps
314− engine : xpath
315− search_url : https://play.google.com/store/search?q={query}&c=apps
316− url_xpath : //a[@class="title"]/@href
317− title_xpath : //a[@class="title"]
318− content_xpath : //a[@class="subtitle"]
314+ engine : xpath
315+ search_url : https://play.google.com/store/search?q={query}&c=apps
316+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
317+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
318+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
319+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
320+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
319321 categories : files
320322 shortcut : gpa
321323 disabled : True
322324
323325 - name : google play movies
324− engine : xpath
325− search_url : https://play.google.com/store/search?q={query}&c=movies
326− url_xpath : //a[@class="title"]/@href
327− title_xpath : //a[@class="title"]/@title
328− content_xpath : //a[contains(@class, "subtitle")]
326+ engine : xpath
327+ search_url : https://play.google.com/store/search?q={query}&c=movies
328+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
329+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
330+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
331+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
332+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
329333 categories : videos
330334 shortcut : gpm
331335 disabled : True
332336
333337 - name : google play music
334− engine : xpath
335− search_url : https://play.google.com/store/search?q={query}&c=music
336− url_xpath : //a[@class="title"]/@href
337− title_xpath : //a[@class="title"]
338− content_xpath : //a[@class="subtitle"]
338+ engine : xpath
339+ search_url : https://play.google.com/store/search?q={query}&c=music
340+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
341+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
342+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
343+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
344+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
339345 categories : music
340346 shortcut : gps
341347 disabled : True