summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2022-02-16 23:02:23 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2022-02-16 23:02:23 (GMT)
commit832196f7a39c62c9426db07a8ddd90c64cefc187 (patch)
tree68d15ff81f0e784f472c4ef09d5ab66babf41498
parent611aa243b42aa854a8a5302a634cef14a7dced90 (diff)
Create a Proof of Concept for the PlayStore API.
-rw-r--r--python/googleplay.py86
1 files changed, 86 insertions, 0 deletions
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()