Exemple #1
0
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')
Exemple #2
0
def main():

    args = get_cmd_args()

    # Make sure to use a valid json file with the credentials.
    api = Playstore(args.credentials.strip(' \'"'))

    try:
        # Get the application details.
        app = api.app_details(args.package.strip(' \'"')).docV2
    except AttributeError:
        print('Error when downloading "{0}". Unable to get app\'s details.'.
              format(args.package.strip(' \'"')))
        sys.exit(1)

    details = {
        'package_name': app.docid,
        'title': app.title,
        'creator': app.creator
    }

    if args.out.strip(' \'"') == downloaded_apk_default_location:
        # The downloaded apk will be saved in the Downloads folder (created in the same folder as this script).
        downloaded_apk_file_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            downloaded_apk_default_location,
            re.sub(
                '[^\w\-_.\s]', '_',
                '{0} by {1} - {2}.apk'.format(details['title'],
                                              details['creator'],
                                              details['package_name'])))
    else:
        # The downloaded apk will be saved in the location chosen by the user.
        downloaded_apk_file_path = os.path.abspath(args.out.strip(' \'"'))

    # If it doesn't exist, create the directory where to save the downloaded apk.
    if not os.path.exists(os.path.dirname(downloaded_apk_file_path)):
        os.makedirs(os.path.dirname(downloaded_apk_file_path))

    if args.tag and args.tag.strip(' \'"'):
        # If provided, prepend the specified tag to the file name.
        downloaded_apk_file_path = os.path.join(
            os.path.dirname(downloaded_apk_file_path),
            '[{0}] {1}'.format(args.tag.strip(' \'"'),
                               os.path.basename(downloaded_apk_file_path)))

    # The download of the additional .obb files is optional.
    if args.blobs:
        success = api.download(details['package_name'],
                               downloaded_apk_file_path,
                               download_obb=True)
    else:
        success = api.download(details['package_name'],
                               downloaded_apk_file_path,
                               download_obb=False)

    if not success:
        print('Error when downloading "{0}".'.format(details['package_name']))
        sys.exit(1)
Exemple #3
0
def main(arg):

    args = arg
    apk_map = get_apk_version_map()

    # Make sure to use a valid json file with the credentials.
    api = Playstore(args.credentials.strip(' \'"'))

    try:
        # Get the application details.
        app = api.app_details(args.package.strip(' \'"')).docV2
        if arg.package in apk_map:
            if int(apk_map[arg.package]) >= app.details.appDetails.versionCode:
                print(
                    "------------The same version of the apk already exists------------"
                )
                return
    except AttributeError:
        print('Error when downloading "{0}". Unable to get app\'s details.'.
              format(args.package.strip(' \'"')))
        return
    details = {
        'package_name': app.docid,
        'title': app.title,
        'creator': app.creator
    }

    if args.out.strip(' \'"') == downloaded_apk_default_location:
        # The downloaded apk will be saved in the Downloads folder (created in the same folder as this script).
        downloaded_apk_file_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            downloaded_apk_default_location,
            re.sub(
                '[^\w\-_.\s]', '_',
                '{0}-{1}.apk'.format(details['package_name'],
                                     app.details.appDetails.versionCode)))
    else:
        # The downloaded apk will be saved in the location chosen by the user.
        downloaded_apk_file_path = os.path.abspath(args.out.strip(' \'"'))
        downloaded_apk_file_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            downloaded_apk_file_path,
            re.sub(
                '[^\w\-_.\s]', '_',
                '{0}-{1}.apk'.format(details['package_name'],
                                     app.details.appDetails.versionCode)))

    print("The APK save path is ", downloaded_apk_file_path)
    # If it doesn't exist, create the directory where to save the downloaded apk.
    if not os.path.exists(os.path.dirname(downloaded_apk_file_path)):
        os.makedirs(os.path.dirname(downloaded_apk_file_path))

    success = api.download(details['package_name'], downloaded_apk_file_path)

    if not success:
        print('Error when downloading "{0}".'.format(details['package_name']))
        time.sleep(10)
        return
def process(package_name):
    if package_name_regex.match(package_name):
        try:
            api = Playstore("", True)
            try:
                app = api.app_details(package_name).docV2
            except AttributeError:
                logger.error(
                    f"Unable to retrieve application with "
                    f"package name '{package_name}'", )
                return jsonify({
                    "package": package_name,
                    "status": "not valid"
                }), 400

            details = {
                "package_name": app.docid,
                "title": app.title,
                "creator": app.creator,
                "version_code": app.details.appDetails.versionCode,
                "version": app.details.appDetails.versionString,
            }
            filename = "%s_%s(%s).apk" % (details['package_name'],
                                          details['version'],
                                          details['version_code'])
            downloaded_apk_file_path = os.path.join(
                downloaded_apk_location,
                filename,
            )

            success = api.download(details["package_name"],
                                   downloaded_apk_file_path, False, False,
                                   False)

            if not success:
                logger.critical(
                    f"Error when downloading '{details['package_name']}'")
                return jsonify({
                    "package": package_name,
                    "status": "Error when downloading"
                }), 400

            return {
                "package": details['package_name'],
                "filename": filename,
                "version": details['version'],
                "version_code": details['version_code']
            }

        except Exception as e:
            logger.critical(f"Error during the download: {e}")
            abort(500)
    else:
        logger.critical("Please specify a valid package name")
        abort(400, description='Not valid package')
Exemple #5
0
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"]),
                ),
            )

            # noinspection PyProtectedMember
            for progress in api._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")
Exemple #6
0
def main():
    args = get_cmd_args()
    credential = {
        "USERNAME": os.environ["APP_USERNAME"],
        "PASSWORD": os.environ["APP_PASSWORD"],
        "ANDROID_ID": os.environ["APP_ANDROID_ID"],
        "LANG_CODE": os.environ["APP_LANG_CODE"],
        "LANG": os.environ["APP_LANG_CODE"]
    }
    try:
        api = Playstore(credential)
        stripped_package_name = os.environ["APP_PACKAGE"]
        try:
            app = api.app_details(stripped_package_name).docV2
        except AttributeError:
            logger.critical(
                f"Error when downloading '{stripped_package_name}': unable to "
                f"get app's details")
            sys.exit(1)

        details = {
            "package_name": app.docid,
            "title": app.title,
            "creator": app.creator,
        }

        if args.out.strip(" '\"") == downloaded_apk_default_location:
            downloaded_apk_file_path = os.path.join(
                downloaded_apk_default_location,
                re.sub(
                    r"[^\w\-_.\s]",
                    "_",
                    f"{details['title']} by {details['creator']} - "
                    f"{details['package_name']}.apk",
                ),
            )
        else:
            downloaded_apk_file_path = os.path.abspath(args.out.strip(" '\""))
        if not os.path.isdir(os.path.dirname(downloaded_apk_file_path)):
            os.makedirs(os.path.dirname(downloaded_apk_file_path),
                        exist_ok=True)

        if args.tag and args.tag.strip(" '\""):
            stripped_tag = args.tag.strip(" '\"")
            downloaded_apk_file_path = os.path.join(
                os.path.dirname(downloaded_apk_file_path),
                f"[{stripped_tag}] {os.path.basename(downloaded_apk_file_path)}",
            )
        success = api.download(
            details["package_name"],
            downloaded_apk_file_path,
            download_obb=True if args.blobs else False,
            download_split_apks=True if args.split_apks else False,
        )

        if not success:
            logger.critical(
                f"Error when downloading '{details['package_name']}'")
            sys.exit(1)

    except Exception as ex:
        logger.critical(f"Error during the download: {ex}")
        sys.exit(1)
def main():

    args = get_cmd_args()

    try:

        # Make sure to use a valid json file with the credentials.
        api = Playstore(args.credentials.strip(" '\""))

        try:
            # Get the application details.
            app = api.app_details(args.package.strip(" '\"")).docV2
        except AttributeError:
            logger.critical(
                "Error when downloading '{0}': unable to get app's details".
                format(args.package.strip(" '\"")))
            sys.exit(1)

        details = {
            "package_name": app.docid,
            "title": app.title,
            "creator": app.creator,
        }

        if args.out.strip(" '\"") == downloaded_apk_default_location:
            # The downloaded apk will be saved in the Downloads folder (created in the
            # same folder as this script).
            downloaded_apk_file_path = os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                downloaded_apk_default_location,
                re.sub(
                    r"[^\w\-_.\s]",
                    "_",
                    "{0} by {1} - {2}.apk".format(details["title"],
                                                  details["creator"],
                                                  details["package_name"]),
                ),
            )
        else:
            # The downloaded apk will be saved in the location chosen by the user.
            downloaded_apk_file_path = os.path.abspath(args.out.strip(" '\""))

        # If it doesn't already exist, create the directory where to save the
        # downloaded apk.
        if not os.path.isdir(os.path.dirname(downloaded_apk_file_path)):
            os.makedirs(os.path.dirname(downloaded_apk_file_path),
                        exist_ok=True)

        if args.tag and args.tag.strip(" '\""):
            # If provided, prepend the specified tag to the file name.
            downloaded_apk_file_path = os.path.join(
                os.path.dirname(downloaded_apk_file_path),
                "[{0}] {1}".format(args.tag.strip(" '\""),
                                   os.path.basename(downloaded_apk_file_path)),
            )

        # The download of the additional .obb files is optional.
        success = api.download(
            details["package_name"],
            downloaded_apk_file_path,
            download_obb=True if args.blobs else False,
        )

        if not success:
            logger.critical("Error when downloading '{0}'".format(
                details["package_name"]))
            sys.exit(1)

    except Exception as ex:
        logger.critical("Error during the download: {0}".format(ex))
        sys.exit(1)
def main():

    args = get_cmd_args()

    try:

        # Make sure to use a valid json file with the credentials.
        api = Playstore(args.credentials.strip(" '\""))

        stripped_package_name = args.package.strip(" '\"")

        try:
            # Get the application details.
            app = api.app_details(stripped_package_name).docV2
        except AttributeError:
            logger.critical(
                f"Error when downloading '{stripped_package_name}': unable to "
                f"get app's details")
            sys.exit(1)

        details = {
            "package_name": app.docid,
            "title": app.title,
            "creator": app.creator,
        }

        if args.out.strip(" '\"") == downloaded_apk_default_location:
            # The downloaded apk will be saved in the Downloads folder (created in the
            # same folder as this script).
            downloaded_apk_file_path = os.path.join(
                downloaded_apk_default_location,
                re.sub(
                    r"[^\w\-_.\s]",
                    "_",
                    f"{details['title']} by {details['creator']} - "
                    f"{details['package_name']}.apk",
                ),
            )
        else:
            # The downloaded apk will be saved in the location chosen by the user.
            downloaded_apk_file_path = os.path.abspath(args.out.strip(" '\""))

        # If it doesn't already exist, create the directory where to save the
        # downloaded apk.
        if not os.path.isdir(os.path.dirname(downloaded_apk_file_path)):
            os.makedirs(os.path.dirname(downloaded_apk_file_path),
                        exist_ok=True)

        if args.tag and args.tag.strip(" '\""):
            # If provided, prepend the specified tag to the file name.
            stripped_tag = args.tag.strip(" '\"")
            downloaded_apk_file_path = os.path.join(
                os.path.dirname(downloaded_apk_file_path),
                f"[{stripped_tag}] {os.path.basename(downloaded_apk_file_path)}",
            )

        # The download of the additional files is optional.
        success = api.download(
            details["package_name"],
            downloaded_apk_file_path,
            download_obb=True if args.blobs else False,
            download_split_apks=True if args.split_apks else False,
        )

        if not success:
            logger.critical(
                f"Error when downloading '{details['package_name']}'")
            sys.exit(1)

    except Exception as ex:
        logger.critical(f"Error during the download: {ex}")
        sys.exit(1)
Exemple #9
0
class PlaystoreClient:
    def __init__(self, playstore_client_configuration):
        credentials_file_path = (
            playstore_client_configuration.get_credendials_file_path())
        self.api = Playstore(credentials_file_path.strip(" '\""))

    def download(
        self,
        package_name,
        file_path="Downloads",
        tag=None,
        blobs=False,
        split_apks=False,
    ):
        details = self.get_app_details(package_name)
        downloaded_apk_file_path = self._prepare_file_path_if_does_not_exist(
            file_path, details, tag)

        success = self.api.download(
            details["package_name"],
            downloaded_apk_file_path,
            download_obb=True if blobs else False,
            download_split_apks=True if split_apks else False,
        )
        if not success:
            raise RuntimeError(
                f"Error when downloading '{details['package_name']}'")

    def get_app_details(self, package_name):
        stripped_package_name = package_name.strip(" '\"")

        try:
            # Get the application details.
            app = self.api.app_details(stripped_package_name).docV2
        except AttributeError:
            raise RuntimeError(
                f"Error when downloading '{stripped_package_name}': unable to get app's details"
            )

        details = {
            "package_name": app.docid,
            "title": app.title,
            "creator": app.creator,
        }
        return details

    def _prepare_file_path_if_does_not_exist(self, file_path, details, tag):
        # The downloaded apk will be saved in the location chosen by the user.
        downloaded_apk_file_path = os.path.abspath(file_path.strip(" '\""))

        # If it doesn't already exist, create the directory where to save the
        # downloaded apk.
        if not os.path.isdir(os.path.dirname(downloaded_apk_file_path)):
            os.makedirs(os.path.dirname(downloaded_apk_file_path),
                        exist_ok=True)

        if tag and tag.strip(" '\""):
            # If provided, prepend the specified tag to the file name.
            stripped_tag = tag.strip(" '\"")
            downloaded_apk_file_path = os.path.join(
                os.path.dirname(downloaded_apk_file_path),
                f"[{stripped_tag}] {os.path.basename(downloaded_apk_file_path)}",
            )
        return downloaded_apk_file_path