skins.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var http = require('http');
  2. var https = require('https');
  3. var fs = require('fs');
  4. var imagemagick = require('imagemagick');
  5. module.exports = {
  6. get_profile: function(uuid, callback) {
  7. https.get("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid, function(res) {
  8. res.on('data', function(d) {
  9. var profile = JSON.parse(d);
  10. if (profile.error) throw profile.error;
  11. callback(profile);
  12. });
  13. });
  14. },
  15. skin_url: function(profile) {
  16. var url = null;
  17. if (profile && profile.properties) {
  18. profile.properties.forEach(function(prop) {
  19. if (prop.name == 'textures') {
  20. var json = Buffer(prop.value, 'base64').toString();
  21. var props = JSON.parse(json);
  22. url = props.textures.SKIN.url;
  23. }
  24. });
  25. }
  26. return url;
  27. },
  28. skin_file: function(url, filename, callback) {
  29. var file = fs.createWriteStream(filename);
  30. http.get(url, function(res) {
  31. res.on('data', function(data) {
  32. file.write(data);
  33. }).on('end', function() {
  34. file.end();
  35. callback();
  36. });
  37. });
  38. },
  39. extract_face: function(infile, outfile, callback) {
  40. imagemagick.convert([infile, '-crop', '8x8+8+8', outfile], function(err, stdout) {
  41. if (err) throw err;
  42. callback();
  43. });
  44. }
  45. };