#!/usr/bin/env python3 from urllib.request import Request, urlopen from base64 import b64decode from os import makedirs import json def jsonurlread(url, data=None): return json.loads(urlopen(Request(url, data=json.dumps(data).encode() if data is not None else None, headers={"Content-Type": "application/json"})).read().decode()) def dlskin(user): data = jsonurlread("https://api.mojang.com/profiles/minecraft", [user]) uuid = data[0]["id"] data = jsonurlread("https://sessionserver.mojang.com/session/minecraft/profile/%s" % uuid) textures = None for x in data["properties"]: if x["name"] == "textures": textures = json.loads(b64decode(x["value"].encode()))["textures"] if "SKIN" in textures: skin = urlopen(textures["SKIN"]["url"]).read() makedirs("skin", exist_ok=True) open("skin/%s.png" % user, "wb").write(skin) if "CAPE" in textures: skin = urlopen(textures["CAPE"]["url"]).read() makedirs("cape", exist_ok=True) open("cape/%s.png" % user, "wb").write(cape) if __name__ == "__main__": from sys import argv dlskin(argv[1])