def on_start_download(package_name): if package_name_regex.match(package_name): try: api = Playstore(credentials_location) try: app = api.app_details(package_name).docV2 except AttributeError: emit('download_bad_package', 'Unable to retrieve application with package name "{0}"'.format(package_name)) return details = { 'package_name': app.docid, 'title': app.title, 'creator': app.creator } downloaded_apk_file_path = os.path.join( downloaded_apk_location, re.sub(r'[^\w\-_.\s]', '_', '{0} by {1} - {2}.apk'.format(details['title'], details['creator'], details['package_name']))) for progress in api.silent_download_with_progress(details['package_name'], downloaded_apk_file_path): emit('download_progress', progress) logger.info('The application was downloaded and saved to "{0}"'.format(downloaded_apk_file_path)) emit('download_success', 'The application was successfully downloaded') except Exception as e: emit('download_error', str(e)) else: emit('download_error', 'Please specify a valid package name')
def on_start_download(package_name): if package_name_regex.match(package_name): try: api = Playstore(credentials_location) try: app = api.app_details(package_name).docV2 except AttributeError: emit( "download_bad_package", 'Unable to retrieve application with package name "{0}"'. format(package_name), ) return details = { "package_name": app.docid, "title": app.title, "creator": app.creator, } downloaded_apk_file_path = os.path.join( downloaded_apk_location, re.sub( r"[^\w\-_.\s]", "_", "{0} by {1} - {2}.apk".format(details["title"], details["creator"], details["package_name"]), ), ) for progress in api.silent_download_with_progress( details["package_name"], downloaded_apk_file_path): emit("download_progress", progress) logger.info( 'The application was downloaded and saved to "{0}"'.format( downloaded_apk_file_path)) emit("download_success", "The application was successfully downloaded") except Exception as e: emit("download_error", str(e)) else: emit("download_error", "Please specify a valid package name")