.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
google_play.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Google Play Apps & Google Play Movies
3"""
4
5from urllib.parse import urlencode
6from lxml import html
7from searx.utils import (
8 eval_xpath,
9 extract_url,
10 extract_text,
11 eval_xpath_list,
12 eval_xpath_getindex,
13)
14
15about = {
16 "website": "https://play.google.com/",
17 "wikidata_id": "Q79576",
18 "use_official_api": False,
19 "require_api_key": False,
20 "results": "HTML",
21}
22
23send_accept_language_header = True
24
25play_categ = None # apps|movies
26base_url = 'https://play.google.com'
27search_url = base_url + "/store/search?{query}&c={play_categ}"
28
29
30def request(query, params):
31
32 if play_categ not in ('movies', 'apps'):
33 raise ValueError(f"unknown google play category: {play_categ}")
34
35 params["url"] = search_url.format(
36 query=urlencode({"q": query}),
37 play_categ=play_categ,
38 )
39 params['cookies']['CONSENT'] = "YES+"
40
41 return params
42
43
44def response(resp):
45
46 if play_categ == 'movies':
47 return response_movies(resp)
48 if play_categ == 'apps':
49 return response_apps(resp)
50
51 raise ValueError(f"Unsupported play category: {play_categ}")
52
53
55
56 results = []
57 dom = html.fromstring(resp.text)
58
59 for section in eval_xpath(dom, '//c-wiz/section/header/..'):
60 sec_name = extract_text(eval_xpath(section, './header'))
61 for item in eval_xpath(section, './/a'):
62 url = base_url + item.get('href')
63 div_1, div_2 = eval_xpath(item, './div')[:2]
64 title = extract_text(eval_xpath(div_2, './div[@title]'))
65 metadata = extract_text(eval_xpath(div_2, './div[@class]'))
66 img = eval_xpath(div_1, './/img')[0]
67 img_src = img.get('src')
68 results.append(
69 {
70 "url": url,
71 "title": title,
72 "content": sec_name,
73 "img_src": img_src,
74 'metadata': metadata,
75 'template': 'videos.html',
76 }
77 )
78 return results
79
80
81def response_apps(resp):
82
83 results = []
84 dom = html.fromstring(resp.text)
85
86 if eval_xpath(dom, '//div[@class="v6DsQb"]'):
87 return []
88
89 spot = eval_xpath_getindex(dom, '//div[@class="ipRz4"]', 0, None)
90 if spot is not None:
91 url = extract_url(eval_xpath(spot, './a[@class="Qfxief"]/@href'), search_url)
92 title = extract_text(eval_xpath(spot, './/div[@class="vWM94c"]'))
93 content = extract_text(eval_xpath(spot, './/div[@class="LbQbAe"]'))
94 img = extract_text(eval_xpath(spot, './/img[@class="T75of bzqKMd"]/@src'))
95
96 results.append({"url": url, "title": title, "content": content, "img_src": img})
97
98 more = eval_xpath_list(dom, '//c-wiz[@jsrenderer="RBsfwb"]//div[@role="listitem"]', min_len=1)
99 for result in more:
100 url = extract_url(eval_xpath(result, ".//a/@href"), search_url)
101 title = extract_text(eval_xpath(result, './/span[@class="DdYX5"]'))
102 content = extract_text(eval_xpath(result, './/span[@class="wMUdtb"]'))
103 img = extract_text(
104 eval_xpath(
105 result,
106 './/img[@class="T75of stzEZd" or @class="T75of etjhNc Q8CSx "]/@src',
107 )
108 )
109
110 results.append({"url": url, "title": title, "content": content, "img_src": img})
111
112 for suggestion in eval_xpath_list(dom, '//c-wiz[@jsrenderer="qyd4Kb"]//div[@class="ULeU3b neq64b"]'):
113 results.append({"suggestion": extract_text(eval_xpath(suggestion, './/div[@class="Epkrse "]'))})
114
115 return results