def download_reference_apk(self): api = GooglePlayAPI(self.android_id) api.login(self.google_login, self.google_password) package = api.details(self.results['package']) doc = package.docV2 version = doc.details.appDetails.versionCode offer_type = doc.offer[0].offerType ref_path = path.join(self.tmpdir, "ref.apk") data = api.download(self.results['package'], version, offer_type) with open(ref_path, "wb") as out: out.write(data) return ref_path
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(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType # Download print "Downloading %s..." % sizeof_fmt( doc.details.appDetails.installationSize), data = api.download(packagename, vc, ot) open(filename, "wb").write(data) print "Done"
sys.exit(0) packagename = sys.argv[1] filename = None if (len(sys.argv) == 3): filename = sys.argv[2] # read config from config.py config = GooglePlayAPI.read_config() # connect to GooglePlayStore api = GooglePlayAPI(config['ANDROID_ID']) api.login(config['GOOGLE_LOGIN'], config['GOOGLE_PASSWORD'], config['AUTH_TOKEN']) # Get the version code and the offer type from the app details m = api.details(packagename) doc = m.docV2 vc = doc.details.appDetails.versionCode ot = doc.offer[0].offerType if filename == None: filename = "%s_%s.apk" % (packagename, vc) # Download print("Downloading to file %s with size %s..." % (filename, helpers.sizeof_fmt(doc.details.appDetails.installationSize))) data = api.download(packagename, vc, ot) io.open(filename, "wb").write(data) print("Done")
class PlayStoreCrawler: def __init__(self): try: creds = loadPlayStoreConfig() self.googleLogin = creds['GOOGLE_LOGIN'] self.googlePassword = creds['GOOGLE_PASSWORD'] self.androidID = creds['ANDROID_ID'] self.authToken = creds['AUTH_TOKEN'] self.api = GooglePlayAPI(self.androidID) # Login to the Play Store except Exception as e: prettyPrintError(e) def login(self): """ Logs into the Google account using the received Google credentials """ try: self.api.login(self.googleLogin, self.googlePassword, self.authToken) except Exception as e: prettyPrintError(e) return False return True def getCategories(self): """ Returns a list of app categories available on Google Play Store """ try: cats = self.api.browse() categories = [c.dataUrl[c.dataUrl.rfind('=')+1:] for c in cats.category] except Exception as e: prettyPrintError(e) return [] return categories def getSubCategories(self, category): """ Returns a list of app sub-categories available on Google Play Store """ try: sub = self.api.list(category) subcategories = [s.docid for s in sub.doc] except Exception as e: prettyPrintError(e) return [] return subcategories def getApps(self, category, subcategory): """ Returns a list of "App" objects found under the given (sub)category """ try: apps = self.api.list(category, subcategory) if len(apps.doc) < 1: prettyPrint("Unable to find any apps under \"%s\" > \"%s\"" % (category, subcategory), "warning") return [] applications = [App(a.title, a.docid, a.details.appDetails.versionCode, a.offer[0].offerType, a.aggregateRating.starRating, a.offer[0].formattedAmount, a.details.appDetails.installationSize) for a in apps.doc[0].child] except Exception as e: prettyPrintError(e) return [] return applications def downloadApp(self, application): """ Downloads an app from the Google play store and moves it to the "downloads" directory """ try: if application.appPrice != "Free": prettyPrint("Warning, downloading a non free application", "warning") # Download the app data = self.api.download(application.appID, application.appVersionCode, application.appOfferType) io.open("%s.apk" % application.appID, "wb").write(data) downloadedApps = glob.glob("./*.apk") dstDir = loadDirs()["DOWNLOADS_DIR"] for da in downloadedApps: shutil.move(da, dstDir) except Exception as e: prettyPrintError(e) return False return True