Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Last active January 2, 2022 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vftdan/a59ee14298070fcf3b2a8363ce7879a6 to your computer and use it in GitHub Desktop.
Save Vftdan/a59ee14298070fcf3b2a8363ce7879a6 to your computer and use it in GitHub Desktop.
Scripts for fetching minecraft skins
#! /bin/bash
curl `mcskinurl $1` --create-dirs -o ~/mcskins/$1.png
#! /usr/bin/nodejs
var https = require('https');
function atob(a) {
return new Buffer(a, 'base64').toString('binary');
}
function get(url, cb) {
var h = url.match(/^https/i) ? https : http;
h.get(url, (r) => {
var d = '';
r.on('data', (c) => {d += c});
r.on('end', function() {
cb(d);
});
}).on("error", (e) => {
console.error(e);
});
}
var nick = process.argv[2];
get("https://api.mojang.com/users/profiles/minecraft/" + encodeURIComponent(nick), (p) => {
p = JSON.parse(p);
if("error" in p) {
console.error(p.error + ": " + p.errorMessage);
} else {
var id = p.id;
get("https://sessionserver.mojang.com/session/minecraft/profile/" + id, (s) => {
s = JSON.parse(s);
var prop = s.properties, url, i, cp;
for(i in prop) {
if(prop[i].name != "textures") continue;
cp = JSON.parse(atob(prop[i].value));
url = cp.textures.SKIN.url;
}
console.log(url);
});
}
});
$ mcskinurl <nickname>
Prints url of skin
Requires NodeJS
$ mcskin <nickname>
Saves skin to ~/mcskins/<nickname>.png
Requires curl, mcskinurl in path; bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment