mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-25 14:24:56 +00:00
search returns python dict rather than pbuf object
Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
parent
c7601d3e24
commit
8d3b1ea458
@ -11,7 +11,6 @@ GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZ
|
|||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
filepath = os.path.join( os.path.dirname( os.path.realpath(__file__) ), 'device.properties')
|
filepath = os.path.join( os.path.dirname( os.path.realpath(__file__) ), 'device.properties')
|
||||||
print(filepath)
|
|
||||||
config.read(filepath)
|
config.read(filepath)
|
||||||
device = {}
|
device = {}
|
||||||
for (key, value) in config.items('angler'):
|
for (key, value) in config.items('angler'):
|
||||||
|
@ -15,6 +15,7 @@ import googleplay_pb2
|
|||||||
import config
|
import config
|
||||||
import base64
|
import base64
|
||||||
import struct
|
import struct
|
||||||
|
import itertools
|
||||||
|
|
||||||
ssl_verify = True
|
ssl_verify = True
|
||||||
|
|
||||||
@ -301,6 +302,8 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
def executeRequestApi2(self, path, datapost=None,
|
def executeRequestApi2(self, path, datapost=None,
|
||||||
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
||||||
|
if self.authSubToken == None:
|
||||||
|
raise Exception("You need to login before executing any request")
|
||||||
if (datapost is None and path in self.preFetch):
|
if (datapost is None and path in self.preFetch):
|
||||||
data = self.preFetch[path]
|
data = self.preFetch[path]
|
||||||
else:
|
else:
|
||||||
@ -319,24 +322,70 @@ class GooglePlayAPI(object):
|
|||||||
data = response.content
|
data = response.content
|
||||||
|
|
||||||
message = googleplay_pb2.ResponseWrapper.FromString(data)
|
message = googleplay_pb2.ResponseWrapper.FromString(data)
|
||||||
|
if message.commands.displayErrorMessage != "":
|
||||||
|
raise DecodeError(message.commands.displayErrorMessage)
|
||||||
self._try_register_preFetch(message)
|
self._try_register_preFetch(message)
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def search(self, query, nb_result, offset=None):
|
def search(self, query, nb_result, offset=None):
|
||||||
|
if self.authSubToken == None:
|
||||||
|
raise Exception("You need to login before executing any request")
|
||||||
path = "search?c=3&q=%s" % requests.utils.quote(query)
|
path = "search?c=3&q=%s" % requests.utils.quote(query)
|
||||||
|
|
||||||
if (offset is not None):
|
if (offset is not None):
|
||||||
path += "&o=%d" % int(offset)
|
path += "&o=%d" % int(offset)
|
||||||
|
|
||||||
headers = self.getDefaultHeaders()
|
data = self.executeRequestApi2(path)
|
||||||
|
# TODO: can response contain more than 1 cluster?
|
||||||
url = self.FDFE + path
|
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
|
||||||
response = requests.get(url, headers=headers,
|
# cluster has more than 1 doc usually, and each doc has some
|
||||||
verify=ssl_verify)
|
# childs representing the applications. So we chain together every child
|
||||||
data = response.content
|
# of every doc
|
||||||
cluster = googleplay_pb2.SearchClusterResponse.FromString(data)
|
apps = itertools.chain.from_iterable([doc.child for doc in cluster.doc])
|
||||||
return cluster.preFetch[0].response.wrapper.wrapper.cluster[0].doc[0]
|
output = []
|
||||||
|
for a in apps:
|
||||||
|
elem = {
|
||||||
|
"docId": a.docid,
|
||||||
|
"title": a.title,
|
||||||
|
"author": a.creator,
|
||||||
|
"offer": [{
|
||||||
|
"micros": o.micros,
|
||||||
|
"currencyCode": o.currencyCode,
|
||||||
|
"formattedAmount": o.formattedAmount,
|
||||||
|
"checkoutFlowRequired": o.checkoutFlowRequired,
|
||||||
|
"offerType": o.offerType
|
||||||
|
} for o in a.offer],
|
||||||
|
"images": [{
|
||||||
|
"imageType": img.imageType,
|
||||||
|
"width": img.Dimension.width if hasattr(img.Dimension, "width") else 0,
|
||||||
|
"height": img.Dimension.height if hasattr(img.Dimension, "height") else 0,
|
||||||
|
"url": img.imageUrl,
|
||||||
|
"supportsFifeUrlOptions": img.supportsFifeUrlOptions
|
||||||
|
} for img in a.image],
|
||||||
|
"versionCode": a.details.appDetails.versionCode,
|
||||||
|
"installationSize": a.details.appDetails.installationSize,
|
||||||
|
"numDownloads": a.details.appDetails.numDownloads,
|
||||||
|
"uploadDate": a.details.appDetails.uploadDate,
|
||||||
|
"files": [{
|
||||||
|
"fileType": f.fileType,
|
||||||
|
"version": f.versionCode,
|
||||||
|
"size": f.size
|
||||||
|
} for f in a.details.appDetails.file],
|
||||||
|
"unstable": a.details.appDetails.unstable,
|
||||||
|
"containsAds": a.details.appDetails.containsAds,
|
||||||
|
"dependencies": [{
|
||||||
|
"packageName": d.packageName,
|
||||||
|
"version": d.version
|
||||||
|
} for d in a.details.appDetails.dependencies.dependency],
|
||||||
|
"category": {
|
||||||
|
"appType": a.relatedLinks.categoryInfo.appType,
|
||||||
|
"appCategory": a.relatedLinks.categoryInfo.appCategory
|
||||||
|
},
|
||||||
|
"detailsUrl": a.detailsUrl
|
||||||
|
}
|
||||||
|
output.append(elem)
|
||||||
|
return output
|
||||||
|
|
||||||
def details(self, packageName):
|
def details(self, packageName):
|
||||||
"""Get app details from a package name.
|
"""Get app details from a package name.
|
||||||
@ -412,16 +461,16 @@ class GooglePlayAPI(object):
|
|||||||
versionCode can be grabbed by using the details() method on the given
|
versionCode can be grabbed by using the details() method on the given
|
||||||
app."""
|
app."""
|
||||||
|
|
||||||
|
if self.authSubToken == None:
|
||||||
|
raise Exception("You need to login before executing any request")
|
||||||
|
|
||||||
path = "purchase"
|
path = "purchase"
|
||||||
|
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'ot': str(offerType),
|
'ot': str(offerType),
|
||||||
'doc': packageName,
|
'doc': packageName,
|
||||||
'vc': str(versionCode)
|
'vc': str(versionCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
url = self.FDFE + path
|
url = self.FDFE + path
|
||||||
response = requests.post(url, headers=headers,
|
response = requests.post(url, headers=headers,
|
||||||
params=params, verify=ssl_verify)
|
params=params, verify=ssl_verify)
|
||||||
|
Loading…
Reference in New Issue
Block a user