Last active
June 19, 2018 10:03
-
-
Save jaames/162399accb808f8f82237aab4de88a22 to your computer and use it in GitHub Desktop.
crappy miitomo asset scraper (v2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# crappy miitomo asset downloader | |
# usage: python3 miitomo-asset.py < url for manifest.json > | |
from pathlib import Path | |
from io import BytesIO | |
from sys import argv | |
import zipfile | |
import urllib.request | |
import json | |
MANIFEST_URL = argv[1] | |
# fetch manifest | |
with urllib.request.urlopen(MANIFEST_URL) as manifest: | |
# load manifest as json | |
manifestData = json.loads(manifest.read().decode()) | |
packageUrl = manifestData["packageUrl"] | |
assetList = manifestData["assets"] | |
for index, key in enumerate(assetList): | |
asset = assetList[key] | |
assetFilepath = asset["path"] | |
assetDirectory = Path(assetFilepath).parents[0] | |
# download asset | |
print("({0:04d}/{1:04d}) Downloading".format(index + 1, len(assetList)), assetFilepath) | |
if "compressed" in asset and asset["compressed"]: | |
# download asset and extract as zip | |
resp = urllib.request.urlopen(packageUrl + "/" + assetFilepath) | |
z = zipfile.ZipFile(BytesIO(resp.read())) | |
z.extractall(str(assetDirectory)) | |
z.close() | |
else: | |
# download asset directly | |
assetDirectory.mkdir(parents=True, exist_ok=True) | |
urllib.request.urlretrieve(packageUrl + "/" + assetFilepath, assetFilepath) | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment