comparison getskin.py @ 44:190ac0f669c6

Upload getskin.py committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Tue, 13 Jul 2021 00:47:42 -0400
parents
children eac6dae753ca
comparison
equal deleted inserted replaced
43:3487aa65ca56 44:190ac0f669c6
1 # minecraft skin fetcher
2 # by Paper, 2021-07-13
3 # this only really exists as reference to a possible java implementation
4 # (for those beta versions of minecraft that don't support UUIDs)
5 # however, i do not have any java experience, like, at all
6 # so that'll be fun!
7
8 import argparse
9 import base64
10 import cv2
11 import json
12 import numpy
13 import urllib.request
14
15 def get_status_code(mcign):
16 return urllib.request.urlopen(f"https://api.mojang.com/users/profiles/minecraft/{mcign}").getcode()
17
18 # parse arguments
19 parser = argparse.ArgumentParser()
20 parser.add_argument('-c', '--crop', help='crops your skin to 64x32, for beta versions', action="store_true")
21 parser.add_argument('-u', '--username', help='minecraft in-game name')
22 args = parser.parse_args()
23
24 # parse username, probably unnecessarily long but idc
25 if args.username:
26 myname = args.username
27 try:
28 statuscode = get_status_code(myname)
29 except:
30 myname = input("What is your Minecraft username?: ")
31 statuscode = get_status_code(myname)
32 finally:
33 while statuscode == 204:
34 myname = input("What is your Minecraft username?: ")
35 statuscode = get_status_code(myname)
36
37 skinlink = json.loads(base64.b64decode(json.loads(urllib.request.urlopen(f'https://sessionserver.mojang.com/session/minecraft/profile/{json.loads(urllib.request.urlopen("https://api.mojang.com/users/profiles/minecraft/{0}".format(myname)).read().decode("utf-8"))["id"]}').read().decode("utf-8"))["properties"][0]["value"]).decode("utf-8"))["textures"]["SKIN"]["url"] # get your free long lines here!
38 skin = numpy.asarray(bytearray(urllib.request.urlopen(skinlink).read()), dtype="uint8")
39 skin = cv2.imdecode(skin, cv2.IMREAD_UNCHANGED)
40
41 # this is worthless if your skin is already 64x32
42 if args.crop:
43 skin = skin[0:32, 0:64]
44
45 # write the final skin
46 cv2.imwrite("skin.png", skin)