-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmojang.py
More file actions
25 lines (20 loc) · 825 Bytes
/
mojang.py
File metadata and controls
25 lines (20 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import base64
import json
import urllib.request
profile_api_url = 'https://sessionserver.mojang.com/session/minecraft/profile/'
# get player profile via Mojang's API
# the returned object is the first property ("textures") decoded
# may raise an error on failure
def get_player_profile(uuid):
compact_uuid = uuid.replace('-', '')
response_str = False
with urllib.request.urlopen(profile_api_url + compact_uuid) as response:
response_str = response.read().decode()
if response_str:
profile = json.loads(response_str)
# FIXME: this is some heavy hardcoding right here, but what the API returns
# does not seem to follow any reasonnable logic
return json.loads(
base64.b64decode(profile['properties'][0]['value']).decode())
else:
return False