Last active
April 2, 2018 15:45
-
-
Save Bentroen/d495352a6b1888e96814db73354b2470 to your computer and use it in GitHub Desktop.
This file contains 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
import json | |
import os | |
import shutil | |
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
# Change this to the version you want to extract the assets from | |
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
version = "1.12-af" | |
minecraft_path = os.getenv('APPDATA') + r"\.minecraft\assets" | |
objects_path = minecraft_path + r"\objects" | |
indexes_path = minecraft_path + r"\indexes" | |
version_file = version + ".json" | |
version_list = os.listdir(indexes_path) | |
max_modified = 0 | |
for ver in version_list: | |
full_path = os.path.join(indexes_path, ver) | |
modified = os.path.getmtime(full_path) | |
if modified > max_modified: | |
max_modified = modified | |
latest_modified = ver | |
if version_file not in version_list: | |
raise Exception("The selected version was not found.") | |
else: | |
if version_file is latest_modified: | |
pass | |
#raise Exception("The selected version was not the latest version played.") | |
else: | |
indexes = os.path.join(indexes_path, version_file) | |
with open(indexes) as f: | |
lines = f.readlines() | |
file = "".join(lines) | |
json = json.loads(file) | |
json = json["objects"] | |
if not os.path.exists(version): | |
os.makedirs(version) | |
objects = {} | |
for i,object in enumerate(json): | |
hash = list(json.values())[i]["hash"] | |
objects[object] = hash | |
count = 0 | |
for object, hash in objects.items(): | |
count += 1 | |
print("Processing file {}/{}: {}".format(count, len(objects), object)) | |
source_file = os.path.join(objects_path, hash[:2], hash) | |
destination_file = os.path.join(version, object) | |
destination_folder = os.path.dirname(destination_file) | |
if not os.path.exists(destination_folder): | |
os.makedirs(destination_folder) | |
shutil.copy(source_file, destination_folder) | |
old_filename = os.path.join(destination_folder, hash) | |
os.rename(old_filename, destination_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment