From 832196f7a39c62c9426db07a8ddd90c64cefc187 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 17 Feb 2022 00:02:23 +0100 Subject: Create a Proof of Concept for the PlayStore API. --- python/googleplay.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 python/googleplay.py diff --git a/python/googleplay.py b/python/googleplay.py new file mode 100644 index 0000000..d580ce2 --- /dev/null +++ b/python/googleplay.py @@ -0,0 +1,86 @@ + +import json +import os +import threading + +from pychrysalide import core +from pychrysalide.analysis.contents import MemoryContent +from pychrysalide.plugins.gplay import PlayStore, AndroidDevice + + +if __name__ == "__main__": + + core.set_verbosity(0) + + + assert('bacon' in AndroidDevice.list_available_models()) + + dev = AndroidDevice('bacon') + + + MyPlayStore = PlayStore + + if not(os.path.isfile('playstore.cfg')): + + user = os.getenv('USER') + password = os.getenv('PASSWORD') + + store = PlayStore(dev, user, password) + + cfg = { + 'dev_id': store.device_id, + 'auth_token': store.auth_token, + 'dev_token': store.device_token, + } + + with open('playstore.cfg', 'w') as fd: + json.dump(cfg, fd, indent=' ') + + else: + + with open('playstore.cfg', 'r') as fd: + cfg = json.load(fd) + + store = PlayStore(dev, dev_id=cfg['dev_id'], auth_token=cfg['auth_token'], dev_token=cfg['dev_token']) + + + _take_ownership = None + + + ret = store.login() + + if ret: + + pkg_name = 'org.mozilla.firefox' + + details = store.get_package_details(pkg_name) + + pkg_version = details.version_code + + + def _on_downloaded(_store, _content, _event): + + if not(_content is None): + + # As the content is allocated from another thread, + # transfer ownership to the main thread in order + # to avoid deadlock when Python tries to free this content + global _take_ownership + _take_ownership = _content + + with open('%s-%u.apk' % (pkg_name, pkg_version), 'wb') as fd: + fd.write(_content.data) + + else: + core.log_message(core.LogMessageType.EXT_ERROR, 'Error while downloading the APK file') + + _event.set() + + + event = threading.Event() + + store.connect('downloaded', _on_downloaded, event) + + store.download_package(pkg_name, pkg_version) + + event.wait() -- cgit v0.11.2-87-g4458