Browse Source

Add skin fetching

master
mid-kid 4 weeks ago
parent
commit
e172571d47
  1. 33
      auth/getskin.py

33
auth/getskin.py

@ -0,0 +1,33 @@
#!/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")
open("skin/%s.png" % user, "wb").write(skin)
if "CAPE" in textures:
skin = urlopen(textures["CAPE"]["url"]).read()
makedirs("cape")
open("cape/%s.png" % user, "wb").write(cape)
if __name__ == "__main__":
from sys import argv
dlskin(argv[1])
Loading…
Cancel
Save