skin.go 682 B

123456789101112131415161718192021222324
  1. package mc
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "log"
  6. "os"
  7. )
  8. //DownloadSkin is exported function
  9. func (mc *Handler) DownloadSkin() {
  10. if _, err := os.Stat(mc.savePath + "/" + mc.UUID + ".png"); os.IsNotExist(err) {
  11. resp := httpReq("https://sessionserver.mojang.com/session/minecraft/profile/" + mc.UUID)
  12. var profileArray profile
  13. json.Unmarshal(resp, &profileArray)
  14. decoded, _ := base64.URLEncoding.DecodeString(profileArray.Properties[0].Value)
  15. var textureArray texture
  16. json.Unmarshal([]byte(decoded), &textureArray)
  17. downloadFile(mc.savePath+"/"+mc.UUID+".png", textureArray.Textures.SKIN.URL)
  18. } else {
  19. log.Println("Skin exists, not downloading")
  20. }
  21. }