Implemented new Download API

Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
Domenico Iezzi 2017-09-16 14:57:21 +02:00
parent 2f68991ad1
commit 361a5777e4
3 changed files with 47 additions and 38 deletions

View File

@ -341,7 +341,7 @@ class GooglePlayAPI(object):
verify=ssl_verify) verify=ssl_verify)
data = response.content data = response.content
cluster = googleplay_pb2.SearchClusterResponse.FromString(data) cluster = googleplay_pb2.SearchClusterResponse.FromString(data)
return cluster.preFetch[0].response.wrapper.wrapper.cluster[0] return cluster.preFetch[0].response.wrapper.wrapper.cluster[0].doc[0]
def details(self, packageName): def details(self, packageName):
"""Get app details from a package name. """Get app details from a package name.
@ -416,40 +416,37 @@ 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."""
path = "purchase"
data = "ot=%d&doc=%s&vc=%d" % (offerType, packageName, versionCode)
message = self.executeRequestApi2(path, data)
response = message.payload.buyResponse.purchaseStatusResponse
if len(response.appDeliveryData.downloadAuthCookie) == 0:
raise DecodeError
url = response.appDeliveryData.downloadUrl
cookie = response.appDeliveryData.downloadAuthCookie[0]
path = "purchase"
headers = self.getDefaultHeaders()
params = {
'ot': str(offerType),
'doc': packageName,
'vc': str(versionCode)
}
url = "https://android.clients.google.com/fdfe/%s" % path
response = requests.post(url, headers=headers,
params=params, verify=ssl_verify)
resObj = googleplay_pb2.ResponseWrapper.FromString(response.content)
if "ErrorMessage" in str(resObj):
raise DecodeError
else:
dlToken = resObj.payload.buyResponse.downloadToken
path = "delivery"
params['dtok'] = dlToken
url = "https://android.clients.google.com/fdfe/%s" % path
response = requests.get(url, headers=headers,
params=params, verify=ssl_verify)
resObj = googleplay_pb2.ResponseWrapper.FromString(response.content)
downloadUrl = resObj.payload.deliveryResponse.appDeliveryData.downloadUrl
cookie = resObj.payload.deliveryResponse.appDeliveryData.downloadAuthCookie[0]
cookies = { cookies = {
str(cookie.name): str(cookie.value) str(cookie.name): str(cookie.value)
} }
return requests.get(downloadUrl, headers=headers,
cookies=cookies, verify=ssl_verify).content
headers = {
"User-Agent": "AndroidDownloadManager/4.4.3 (Linux; U; " +
"Android 4.4.3; Nexus S Build/JRO03E)",
"Accept-Encoding": "",
}
if not progress_bar:
response = requests.get(url, headers=headers,
cookies=cookies, verify=ssl_verify)
return response.content
# If progress_bar is asked
from clint.textui import progress
response_content = str()
response = requests.get(url,
headers=headers,
cookies=cookies,
verify=ssl_verify,
stream=True)
total_length = int(response.headers.get('content-length'))
for chunk in progress.bar(response.iter_content(chunk_size=1024),
expected_size=(total_length/1024) + 1):
if chunk:
response_content += chunk
return response_content

3
requiremets.txt Normal file
View File

@ -0,0 +1,3 @@
protobuf
requests
pycrypto

15
test.py
View File

@ -8,9 +8,18 @@ GSFID = 0
server = GooglePlayAPI(True) server = GooglePlayAPI(True)
if AC2DM == "": if AC2DM == "":
server.login(EMAIL, PASSWD, None, None) server.login(EMAIL, PASSWD, None, None)
print(server.search('firefox', 1, None)) print(server.search('firefox', 1, None).child[0])
print(server.bulkDetails(['com.mozilla.firefox']))
fl = server.download('com.cpuid.cpu_z', 23)
with open('com.cpuid.cpu_z.apk', 'wb') as f:
f.write(fl)
f.close()
else: else:
server.gsfId = GSFID server.gsfId = GSFID
server.login(EMAIL, PASSWD, AC2DM, GSFID) server.login(EMAIL, PASSWD, AC2DM, GSFID)
print(server.search('firefox', 1, None).doc[0].child[0]) print(server.search('firefox', 1, None).child[0])
print(server.download('org.telegram.messenger', 10853)) print(server.bulkDetails(['com.mozilla.firefox']))
fl = server.download('com.cpuid.cpu_z', 23)
with open('com.cpuid.cpu_z.apk', 'wb') as f:
f.write(fl)
f.close()