mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 21:04:59 +00:00
Small fixes and cleanup
Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
parent
582b544070
commit
e987322629
@ -41,8 +41,14 @@ class GooglePlayAPI(object):
|
|||||||
Usual APIs methods are login(), search(), details(), bulkDetails(),
|
Usual APIs methods are login(), search(), details(), bulkDetails(),
|
||||||
download(), browse(), reviews() and list()."""
|
download(), browse(), reviews() and list()."""
|
||||||
|
|
||||||
URL_LOGIN = "https://android.clients.google.com/auth"
|
BASE = "https://android.clients.google.com/"
|
||||||
ACCOUNT_TYPE_HOSTED_OR_GOOGLE = "HOSTED_OR_GOOGLE"
|
FDFE = BASE + "fdfe/"
|
||||||
|
UPLOADURL = FDFE + "uploadDeviceConfig"
|
||||||
|
SEARCHURL = FDFE + "search"
|
||||||
|
CHECKINURL = BASE + "checkin"
|
||||||
|
AUTHURL = BASE + "auth"
|
||||||
|
|
||||||
|
ACCOUNT = "HOSTED_OR_GOOGLE"
|
||||||
authSubToken = None
|
authSubToken = None
|
||||||
ac2dmToken = None
|
ac2dmToken = None
|
||||||
gsfId = None
|
gsfId = None
|
||||||
@ -54,14 +60,17 @@ class GooglePlayAPI(object):
|
|||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
def encrypt_password(self, login, passwd):
|
def encrypt_password(self, login, passwd):
|
||||||
|
"""Encrypt the password using the google publickey, using
|
||||||
|
the RSA encryption algorithm"""
|
||||||
|
|
||||||
def readInt(byteArray, start):
|
def readInt(byteArray, start):
|
||||||
# [start:] remove elements before start
|
"""Read the byte array, starting from *start* position,
|
||||||
# [0:4] select the first four elements from start
|
as an 32-bit unsigned integer"""
|
||||||
return struct.unpack("!L", byteArray[start:][0:4])[0]
|
return struct.unpack("!L", byteArray[start:][0:4])[0]
|
||||||
|
|
||||||
|
|
||||||
def toBigInt(byteArray):
|
def toBigInt(byteArray):
|
||||||
|
"""Convert the byte array to a BigInteger"""
|
||||||
array = byteArray[::-1] # reverse array
|
array = byteArray[::-1] # reverse array
|
||||||
out = 0
|
out = 0
|
||||||
for key, value in enumerate(array):
|
for key, value in enumerate(array):
|
||||||
@ -140,7 +149,7 @@ class GooglePlayAPI(object):
|
|||||||
print("ac2dmToken: " + ac2dmToken)
|
print("ac2dmToken: " + ac2dmToken)
|
||||||
|
|
||||||
def getDefaultHeaders(self):
|
def getDefaultHeaders(self):
|
||||||
"""Return the default set of request parameters, which
|
"""Return the default set of request headers, which
|
||||||
can later be updated, based on the request type"""
|
can later be updated, based on the request type"""
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
@ -159,12 +168,11 @@ class GooglePlayAPI(object):
|
|||||||
def checkin(self, email):
|
def checkin(self, email):
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
headers["Content-Type"] = "application/x-protobuffer"
|
headers["Content-Type"] = "application/x-protobuffer"
|
||||||
url = "https://android.clients.google.com/checkin"
|
|
||||||
|
|
||||||
request = config.getAndroidCheckinRequest()
|
request = config.getAndroidCheckinRequest()
|
||||||
|
|
||||||
stringRequest = request.SerializeToString()
|
stringRequest = request.SerializeToString()
|
||||||
res = requests.post(url, data=stringRequest,
|
res = requests.post(self.CHECKINURL, data=stringRequest,
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
response = googleplay_pb2.AndroidCheckinResponse()
|
response = googleplay_pb2.AndroidCheckinResponse()
|
||||||
response.ParseFromString(res.content)
|
response.ParseFromString(res.content)
|
||||||
@ -179,12 +187,15 @@ class GooglePlayAPI(object):
|
|||||||
request2.accountCookie.append("[" + email + "]")
|
request2.accountCookie.append("[" + email + "]")
|
||||||
request2.accountCookie.append(self.ac2dmToken)
|
request2.accountCookie.append(self.ac2dmToken)
|
||||||
stringRequest = request2.SerializeToString()
|
stringRequest = request2.SerializeToString()
|
||||||
res2 = requests.post(url, data=stringRequest,
|
res2 = requests.post(self.CHECKINURL, data=stringRequest,
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
|
|
||||||
return response.androidId
|
return response.androidId
|
||||||
|
|
||||||
def uploadDeviceConfig(self):
|
def uploadDeviceConfig(self):
|
||||||
|
"""Upload the device configuration defined in the file
|
||||||
|
*device.properties* to the google account. Default device is a Google Nexus 6P"""
|
||||||
|
|
||||||
upload = googleplay_pb2.UploadDeviceConfigRequest()
|
upload = googleplay_pb2.UploadDeviceConfigRequest()
|
||||||
upload.deviceConfiguration.CopyFrom(config.getDeviceConfig())
|
upload.deviceConfiguration.CopyFrom(config.getDeviceConfig())
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
@ -193,9 +204,8 @@ class GooglePlayAPI(object):
|
|||||||
headers["X-DFE-Client-Id"] = "am-android-google"
|
headers["X-DFE-Client-Id"] = "am-android-google"
|
||||||
headers["X-DFE-SmallestScreenWidthDp"] = "320"
|
headers["X-DFE-SmallestScreenWidthDp"] = "320"
|
||||||
headers["X-DFE-Filter-Level"] = "3"
|
headers["X-DFE-Filter-Level"] = "3"
|
||||||
url = "https://android.clients.google.com/fdfe/uploadDeviceConfig"
|
|
||||||
stringRequest = upload.SerializeToString()
|
stringRequest = upload.SerializeToString()
|
||||||
res = requests.post(url, data=stringRequest,
|
res = requests.post(self.UPLOADURL, data=stringRequest,
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
response = googleplay_pb2.ResponseWrapper.FromString(res.content)
|
response = googleplay_pb2.ResponseWrapper.FromString(res.content)
|
||||||
|
|
||||||
@ -228,7 +238,7 @@ class GooglePlayAPI(object):
|
|||||||
"EncryptedPasswd": encryptedPass,
|
"EncryptedPasswd": encryptedPass,
|
||||||
"service": "ac2dm",
|
"service": "ac2dm",
|
||||||
"add_account": "1",
|
"add_account": "1",
|
||||||
"accountType": self.ACCOUNT_TYPE_HOSTED_OR_GOOGLE,
|
"accountType": self.ACCOUNT,
|
||||||
"has_permission": "1",
|
"has_permission": "1",
|
||||||
"app": "com.google.android.gsf",
|
"app": "com.google.android.gsf",
|
||||||
"source": "android",
|
"source": "android",
|
||||||
@ -237,7 +247,7 @@ class GooglePlayAPI(object):
|
|||||||
"sdk_version": "25",
|
"sdk_version": "25",
|
||||||
"client_sig": "38918a453d07199354f8b19af05ec6562ced5788"
|
"client_sig": "38918a453d07199354f8b19af05ec6562ced5788"
|
||||||
}
|
}
|
||||||
response = requests.post(self.URL_LOGIN, data=params, verify=ssl_verify)
|
response = requests.post(self.AUTHURL, data=params, verify=ssl_verify)
|
||||||
data = response.text.split()
|
data = response.text.split()
|
||||||
params = {}
|
params = {}
|
||||||
for d in data:
|
for d in data:
|
||||||
@ -264,7 +274,7 @@ class GooglePlayAPI(object):
|
|||||||
params = {
|
params = {
|
||||||
"Email": email,
|
"Email": email,
|
||||||
"EncryptedPasswd": passwd,
|
"EncryptedPasswd": passwd,
|
||||||
"accountType": self.ACCOUNT_TYPE_HOSTED_OR_GOOGLE,
|
"accountType": self.ACCOUNT,
|
||||||
"has_permission": "1",
|
"has_permission": "1",
|
||||||
"source": "android",
|
"source": "android",
|
||||||
"device_country": "en",
|
"device_country": "en",
|
||||||
@ -274,7 +284,7 @@ class GooglePlayAPI(object):
|
|||||||
"sdk_version": "25",
|
"sdk_version": "25",
|
||||||
"client_sig": "38918a453d07199354f8b19af05ec6562ced5788"
|
"client_sig": "38918a453d07199354f8b19af05ec6562ced5788"
|
||||||
}
|
}
|
||||||
response = requests.post(self.URL_LOGIN, data=params, verify=ssl_verify)
|
response = requests.post(self.AUTHURL, data=params, verify=ssl_verify)
|
||||||
data = response.text.split()
|
data = response.text.split()
|
||||||
params = {}
|
params = {}
|
||||||
for d in data:
|
for d in data:
|
||||||
@ -299,7 +309,7 @@ class GooglePlayAPI(object):
|
|||||||
if datapost is not None:
|
if datapost is not None:
|
||||||
headers["Content-Type"] = post_content_type
|
headers["Content-Type"] = post_content_type
|
||||||
|
|
||||||
url = "https://android.clients.google.com/fdfe/%s" % path
|
url = self.FDFE + path
|
||||||
if datapost is not None:
|
if datapost is not None:
|
||||||
response = requests.post(url, data=str(datapost),
|
response = requests.post(url, data=str(datapost),
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
@ -321,7 +331,7 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
|
|
||||||
url = "https://android.clients.google.com/fdfe/%s" % path
|
url = self.FDFE + path
|
||||||
response = requests.get(url, headers=headers,
|
response = requests.get(url, headers=headers,
|
||||||
verify=ssl_verify)
|
verify=ssl_verify)
|
||||||
data = response.content
|
data = response.content
|
||||||
@ -412,7 +422,7 @@ class GooglePlayAPI(object):
|
|||||||
'vc': str(versionCode)
|
'vc': str(versionCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
url = "https://android.clients.google.com/fdfe/%s" % 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)
|
||||||
|
|
||||||
|
2
test.py
2
test.py
@ -17,7 +17,7 @@ server.login(EMAIL, PASSWD, ac2dmToken, gsfId)
|
|||||||
app = server.search('telegram', 1, None).child[0]
|
app = server.search('telegram', 1, None).child[0]
|
||||||
docid = app.docid
|
docid = app.docid
|
||||||
version = app.details.appDetails.versionCode
|
version = app.details.appDetails.versionCode
|
||||||
print('\nFirefox docid is: %s\n' % docid)
|
print('\nTelegram docid is: %s\n' % docid)
|
||||||
print('\nAttempting to download %s\n' % docid)
|
print('\nAttempting to download %s\n' % docid)
|
||||||
fl = server.download(docid, version)
|
fl = server.download(docid, version)
|
||||||
with open(docid + '.apk', 'wb') as f:
|
with open(docid + '.apk', 'wb') as f:
|
||||||
|
Loading…
Reference in New Issue
Block a user