Skip to content

Commit

Permalink
enhance description
Browse files Browse the repository at this point in the history
  • Loading branch information
phstudy committed Oct 21, 2021
1 parent 0561ee7 commit 2d16ce0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,59 @@ DSA Downloader is a Disney Sorcerer's Arena resources downloader,
which allow developers to download localization files and assets.

## How to use
Installing the library using pip:

Show supported commands

```
$ dsa-downloader --help
Usage: dsa-downloader [OPTIONS] COMMAND [ARGS]...
Options:
--debug / --no-debug
--help Show this message and exit.
Commands:
download-assets Download assets.
download-langs Download localization files.
extract-config Extract bootstrap config from APK file.
```

Install the library using pip

```
$ pip install dsa-downloader
$ pip install dsa-downloader -U
```

Extracting bootstrap config from apk
Extract bootstrap config from *APK* file

```
$ dsa-downloader extract-config com.glu.disneygame.apk
bootstrap_config file is written to out/bootstrap_config.json.
```

Downloading localization files
Download localization files

```
$ dsa-downloader download-langs --langs ChineseTraditional --langs English
ChineseTraditional localization file is written to out/langs/Loc_ChineseTraditional.txt.
ChineseTraditional localization file is written to out/langs/Loc_ChineseTraditional.json.
English localization file is written to out/langs/Loc_English.txt.
English localization file is written to out/langs/Loc_English.json.
```

Downloading assets
Download assets

```
$ dsa-downloader download-assets
2%|██▋ | 81/3896 [00:03<03:00, 21.08it/s]
```

## Docker

Extracting bootstrap config from apk
Use docker container to extract bootstrap config from *APK* file

```
docker run -it --rm -v "$PWD":/dsa study/dsa-downloader dsa-downloader extract-config com.glu.disneygame.apk
$ docker run --rm -v "$PWD":/dsa study/dsa-downloader dsa-downloader \
extract-config com.glu.disneygame.apk
bootstrap_config file is written to out/bootstrap_config.json.
```
1 change: 1 addition & 0 deletions dsa_downloader/asset_processor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import click
import UnityPy
import requests
import os
Expand Down
14 changes: 8 additions & 6 deletions dsa_downloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def cli(ctx, debug):
ctx.obj['DEBUG'] = debug


@cli.command()
@cli.command(help='Extract bootstrap config from APK file.')
@click.pass_context
@click.argument('path_to_apk', type=click.Path(exists=True))
@click.argument('output_path', type=click.Path(dir_okay=False), default='out/bootstrap_config.json')
Expand All @@ -24,28 +24,30 @@ def extract_config(ctx, path_to_apk, output_path):
extractor.bootstrap_extract_config(path_to_apk, output_path)


@cli.command()
@cli.command(help='Download localization files.')
@click.pass_context
@click.argument('path_to_boostrap_config', type=click.Path(exists=True), default='out/bootstrap_config.json')
@click.argument('output_path', type=click.Path(), default='out/langs')
@click.option('--langs', type=click.Choice(
["ChineseTraditional", "ChineseSimplified", "English", "French", "German", "Italian", "Japanese", "Korean",
"PortugueseBrazilian", "Russian", "Spanish"], case_sensitive=False), default=["English"],
multiple=True)
multiple=True, help="Languages to be extracted.")
def download_langs(ctx, path_to_boostrap_config, output_path, langs):
lang_downloader = language_downloader.LanguageDownloader(ctx.obj['DEBUG'], path_to_boostrap_config, output_path)

for lang in langs:
lang_downloader.download_lang(lang)


@cli.command()
@cli.command(help='Download assets.')
@click.pass_context
@click.argument('path_to_boostrap_config', type=click.Path(exists=True), default='out/bootstrap_config.json')
@click.argument('output_path', type=click.Path(), default='out/assets')
@click.argument('extracted_path', type=click.Path(), default='out/assets_extracted')
@click.option('--extract_asset', type=click.BOOL, default=True)
@click.option('--threads', type=click.INT, default=10)
@click.option('--extract-asset', type=click.BOOL, default=True,
help="Flag to turn on/off asset extraction.")
@click.option('--threads', type=click.INT, default=10,
help="Threads count to download/extract assets.", metavar='<int>')
def download_assets(ctx, path_to_boostrap_config, output_path, extract_asset, extracted_path, threads):
handler = asset_processor.AssetHandler(ctx.obj['DEBUG'], path_to_boostrap_config, output_path, extracted_path,
threads)
Expand Down
4 changes: 2 additions & 2 deletions dsa_downloader/config_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def bootstrap_extract_config(self, apk_path, output_path):
data = obj.read()
if data.name == "bootstrap_config":
if self.debug:
click.echo("bootstrap_config was found")
click.echo("bootstrap_config is found")
click.echo("try to extract bootstrap_config")
output_file = open(output_path, 'w')
output_file.write(data.text)
output_file.flush()
output_file.close()
click.echo(f"bootstrap_config was extracted to {output_path}")
click.echo(f"bootstrap_config file is written to {output_path}.")
exit(0)
4 changes: 3 additions & 1 deletion dsa_downloader/language_downloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import click
import requests
import json
import os
Expand All @@ -12,14 +13,14 @@ def __init__(self, debug, bootstrap_file, output_path):
os.makedirs(output_path, exist_ok=True)

def download_lang(self, lang):
print(f'Downloading Loc_{lang}...')
loc_res = requests.get(f'{self.meta.loc_cdn_base_url}/localization/{self.meta.loc_version}/Loc_{lang}.txt')
loc_res.encoding = 'utf-8'

with open(f'{self.output_path}/Loc_{lang}.txt', 'w', encoding='utf8') as fout:
fout.write(loc_res.text)
fout.flush()
fout.close()
click.echo(f"{lang} localization file is written to {self.output_path}/Loc_{lang}.txt.")

with open(f'{self.output_path}/Loc_{lang}.json', 'w', encoding='utf8') as fout:
rst = dict()
Expand All @@ -31,3 +32,4 @@ def download_lang(self, lang):
rst[words[0]] = ''
json_dumps_str = json.dumps(rst, sort_keys=True, ensure_ascii=False, indent=2)
print(json_dumps_str, file=fout)
click.echo(f"{lang} localization file is written to {self.output_path}/Loc_{lang}.json.")
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[metadata]
name = dsa-downloader
url = https://github.com/phstudy/dsa-downloader
description_file = README.md
description = Disney Sorcerer's Arena resources downloader
long_description = file: README.md
long_description_content_type = text/markdown
author = Study Hsueh
author_email = [email protected]
maintainer = Study Hsueh
Expand Down

0 comments on commit 2d16ce0

Please sign in to comment.