idlechampadvunnamedimages.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import json
  2. from pprint import pprint
  3. import re
  4. from collections import OrderedDict
  5. import math
  6. from decimal import Decimal
  7. import html
  8. import glob
  9. from idlechampaccount import ICAccount
  10. import subprocess
  11. import filecmp
  12. import os
  13. import hashlib
  14. import requests
  15. import zlib
  16. import tempfile
  17. COMPARE = True
  18. POST = False
  19. PROCESS = True
  20. REDOWNLOAD = False
  21. _summary = None
  22. if POST:
  23. instance = ICAccount()
  24. instance.login()
  25. # filename = '/home/txtsd/.local/share/Steam/steamapps/common/IdleChampions/IdleDragons_Data/StreamingAssets/downloaded_files/cached_definitions.json'
  26. filename = '/tmp/cached_definitions.json'
  27. if REDOWNLOAD or not os.path.isfile(filename):
  28. result = requests.get('http://master.idlechampions.com/~idledragons/post.php?call=getdefinitions')
  29. with open(filename, 'w') as f:
  30. if result.status_code == 200:
  31. f.write(result.text)
  32. adv_filename = 'json/adventure_defines.json'
  33. area_filename = 'json/adventure_area_defines.json'
  34. camp_filename = 'json/campaign_defines.json'
  35. monster_filename = 'json/monster_defines.json'
  36. with open(filename) as f:
  37. file = f.read()
  38. with open(adv_filename) as f:
  39. adv_file = f.read()
  40. with open(area_filename) as f:
  41. area_file = f.read()
  42. with open(camp_filename) as f:
  43. camp_file = f.read()
  44. with open(monster_filename) as f:
  45. monster_file = f.read()
  46. js = json.loads(file)
  47. js_adv = json.loads(adv_file)
  48. js_area = json.loads(area_file)
  49. js_camp = json.loads(camp_file)
  50. js_mon = json.loads(monster_file)
  51. js_graphic = js['graphic_defines']
  52. js_attack = js['attack_defines']
  53. js_hero = js['hero_defines']
  54. js_hero_skin = js['hero_skin_defines']
  55. js_upgrade = js['upgrade_defines']
  56. js_premium_item = js['premium_item_defines']
  57. js_sound = js['sound_defines']
  58. js_buff = js['buff_defines']
  59. js_loot = js['loot_defines']
  60. js_achievement = js['achievement_defines']
  61. js_ability = js['ability_defines']
  62. js_effect = js['effect_defines']
  63. js_changelog = js['changelog_defines']
  64. js_text = js['text_defines']
  65. js_chest_type = js['chest_type_defines']
  66. js_effect_key = js['effect_key_defines']
  67. js_tutorial_state = js['tutorial_state_defines']
  68. js_game_rule = js['game_rule_defines']
  69. js_news = js['news_defines']
  70. js_language = js['language_defines']
  71. js_familiar = js['familiar_defines']
  72. for graphic in js_graphic:
  73. if '/Events/' in graphic['graphic']:
  74. if '_Icon_Adventure' in graphic['graphic']:
  75. print(graphic['graphic'])
  76. imgname = graphic['graphic']
  77. imgname = imgname.replace('/', '__')
  78. fname_orig = '{imgname}.png'.format(imgname=imgname)
  79. fname_crop = '{imgname}_cropped.png'.format(imgname=imgname)
  80. fname_orig_path = 'images/' + fname_orig
  81. fname_crop_path = 'images/' + fname_crop
  82. if PROCESS:
  83. if REDOWNLOAD or (not os.path.isfile(fname_orig_path)):
  84. pathname = fname_orig.replace('__', '//').replace('.png', '')
  85. file = requests.get('http://ps5.idlechampions.com/~idledragons/mobile_assets/{pathname}'.format(pathname=pathname))
  86. with open('/tmp/IC_temp', 'wb') as t:
  87. t.write(file.content)
  88. with open('/tmp/IC_temp', 'rb') as t:
  89. current_file = t.read()
  90. # current_file = t.read()
  91. res = re.search(b'(\\x89\\x50\\x4e\\x47\\x0d\\x0a\\x1a\\x0a.*)', current_file, re.MULTILINE|re.DOTALL)
  92. if res is not None:
  93. with open(fname_orig_path, 'wb') as g:
  94. g.write(res.group())
  95. else:
  96. data = zlib.decompress(current_file)
  97. res = re.search(b'(\\x89\\x50\\x4e\\x47\\x0d\\x0a\\x1a\\x0a.*)', data, re.MULTILINE|re.DOTALL)
  98. with open(fname_orig_path, 'wb') as g:
  99. g.write(res.group())
  100. result1 = subprocess.run(['convert', fname_orig_path, '-trim', fname_crop_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  101. if result1.stderr:
  102. print(result1.stderr)
  103. result2 = subprocess.run(['pngcrush', '-brute', '-rem', 'alla', '-rem', 'allb', '-rem', 'text', '-reduce', '-check', '-q', '-s', '-ow', fname_crop_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  104. # if result2.stderr:
  105. # print(result2.stderr)