Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 51 lines (39 sloc) 1.15 KB
#!/usr/bin/python
# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None
from config import *
from pprint import pprint
from googleplay import GooglePlayAPI
import sys
def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
if(len(sys.argv) < 2):
print "Usage: %s packagename [filename]"
print "Download an app."
print "If filename is not present, will write to packagename.apk."
sys.exit(0)
packagename = sys.argv[1]
if(len(sys.argv) == 3):
filename = sys.argv[2]
else:
filename = packagename + ".apk"
# Connect
api = GooglePlayAPI()
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
# Get the version code and the offer type from the app details
try:
m = api.details(packagename)
doc = m.docV2
vc = doc.details.appDetails.versionCode
ot = doc.offer[0].offerType
except:
print "Unable to get details from this package name. Are you sure it is correct?"
sys.exit(1)
# Download
print "Downloading %s..." % sizeof_fmt(doc.details.appDetails.installationSize),
data = api.download(packagename, vc, ot)
open(filename, "wb").write(data)
print "Done"