forked from ddf8196/mc-w10-versiondb-auto-update
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
158 lines (137 loc) · 12.5 KB
/
update.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import urllib.request
import urllib.parse
import ssl
import html
import json
import zlib
import base64
import subprocess
import os
from xml.dom import minidom
# GetCookie.xml
GET_COOKIE_XML = zlib.decompress(base64.b64decode(b'eNrFVFtvmzAUft+viPIOtoGUBNFIbVptldppEmSd9jI5cJpYBYxs0yT79TsOhGTpups67QFh+9y/850TX1dPUMgaBpuyqHS00eJ8uDKmjghZr9fu2nelWhKPUkY+3d0m2QpK7ohKG15lMOyt8l9bdcovKPqEjoiWvHagy2g4fTMYxO+A56DsES8XmRGyGuR+zaKy0WZeocymguHZPhkr/f0gP01qROiY8DxXoLWolsPpkVYpMiW1fDBuJkuS4GHNFVwJbZRYNDZPkoB6AkVmhYDK3MPC3kUG5C2YmZSPAmLSVtSVd4dh+BJurv4sqUZVUdOIPFpMFoEfjkLH84LQCfJw4XAYPzg8ZAs+5p7nj89i0kfpoqbyPwOqUe0BfDeHQiBeW7esT9B9hmC2e3C5LjcxSWVXSQJZo4TZ/st6cplpV3IttIPSame41toaBwTp3orsjTIHBfbr0nLwABvjMJe6ODHDNmvbAVECJlnWrxgLGVjY/2kwDDdTwA3kU4+y0GGeQ72U0oidRWzkeox+jsle42BzvakFNq238SYpPYu8URT47iTw0WavsS+K9FX1T/eiyuVaz+scvaciewSjU/kIONEBNkxgk9pO3yUXfbOCo2a9JiAnWOvdjtInxCt1Y72zgDBKvkv/ojErqcRXbuf3GN22rnSLK/U9L+F8uCvmI9IQFZGFLh0OPshCZFsUXd58SZLbI3N0MNegBuTIIzm4PKD7IpbdLJD9MOy2KDms0fhS5ttOqV9EPxjav99vB2LLIm/9H/J+/lRwbWYrXi3BsmvkMOp4LGVhRFlEQ5cFoTdhlmFHintbLFFhbEu1F+gcouGx1t6yVtLITBZdY6bMDWhMTl87LHucWjBbBJHy3Y6YfgMAjFBH')).decode("utf-8")
# WUIDRequest.xml
WUID_REQUEST_XML = zlib.decompress(base64.b64decode(b'eNq1nGtzE8mShj8zv8LBd1t1v9iSIxgY9jgWBhabmRP7ZUJIbaNAUiu6JYx3Yv77vinJxqA3mThxdoMA7H66bllZWZl16WF/+svyczNvV81PT74s5sv+dDx6+nG9Xp0OBre3tye3/qTtbgbOmDgwZTCeTrum72fLm6f37/fK+36AJH07Xh03+xKenv/0ZNif/qMZT5sOPz8Zjk+fTdazdnnUny42/fr9EqBfj5fT0VP79PxRtovZpGv79np9MmkXg0v8cDvumhezft3NPmwki8Fl031uusHz+axZrn9vPsjvs0kzuLxbTt6vpuN10w8H9wXuS3+NtoxvmosX55tuebrZzKanNsfpdSqT4/Ch2uNgm+b4QzYfjq+dM2WSYvClkXy+Jt1lddXqjejRiuvGn0yb+Qx1vDtZrL5r0UGtJ9sHJ+N+8UVKu2q3xbSnl81k083Wd7QwvLLvlPahU6btpD9px/2sP0YXLLe9c9v30kNhYOxgh+Q3Y48B5O++jGP80HxZH9sTc/Kln0r3oQ5Xs0WDEhcr+W1X3P9JYejFufz/TWlPhs+7Bl03PXfG5mNTjk28Mu7U+FMTT4wv/z0c3L+xe/+XL6sZVPT798vX9+/f2LZm8NCc3e+3m9v+9PfZctre9jutuZpNPjXr/qr91CyPbvvN6Qyy3vXX68tnT79K4RTw/0USj4tA9R7K6Ccfm8W4/06VFv1GirFhYM3gm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D96jTGM5Gcv57Obj+t3aOTo94vLMylGvuSAeoycPbu869fN4vV4ubkeT9Yb5Dd6ff8NiqPnbbdqd9+HONsr871ERlvxnb25fH+x66H9g/1r2zSiDqOdRPe1QCV2ld9+naNBX3bL8fzs5axbiPG4/1DHP5CwO/7t6P0vLy+O3u0aePTZncR9dffdsM3k++a+ubz8tLmYjkLZl/m8XUJl1qNdwWcYpKPf34u4JPkf75cTZL9spkqz8bpIypoTcyLX88KJ3NJFKc86lLdutjIbPXv9IoV95S7/8/3o1xY12akoRAtxyejYGrmRO7voH4Txy3L8AfZhZPFwpwXvmvV4Nn/RLNqRObtC06Fm3d1OAzyKvRfR9xXapX45Xszmd6P9t0pOXjT9p3W7OhsODlTswX7CPnWPnl9AWB00Yfa52dbqsmk+of3mTKznd+/u87gfFPd2aaCMkuHg20+FDB9/zWj/1ZTdl1Lkp/svOZ3/Lx+Uv0s=')).decode("utf-8")
unverifiedContext = ssl.create_default_context()
unverifiedContext.check_hostname = False
unverifiedContext.verify_mode = ssl.CERT_NONE
cookie = os.getenv("COOKIE")
# getting the encrypted cookie for the fe3 delivery api
def getCookie():
global cookie
if cookie:
return cookie
cookie_content = GET_COOKIE_XML
request=urllib.request.Request(
"https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx",
data=cookie_content.encode("utf-8"),
headers={"Content-Type": "application/soap+xml; charset=utf-8"}
)
out = urllib.request.urlopen(request, context=unverifiedContext, timeout=20)
doc = minidom.parseString(out.read())
# extracting the cookie from the EncryptedData tag
cookie = doc.getElementsByTagName('EncryptedData')[0].firstChild.nodeValue
return cookie
# getting the update id,revision number and package name from the fe3 delivery api by providing the encrpyted cookie, cat_id, realse type
def getUpdates(cookie, categoryID):
# Map {"retail": "Retail", "release preview": "RP","insider slow": "WIS", "insider fast": "WIF"}
release_type = "Retail"
cat_id_content = WUID_REQUEST_XML.format(cookie, categoryID, release_type)
request=urllib.request.Request(
"https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx",
data=cat_id_content.encode("utf-8"),
headers={'Content-Type': 'application/soap+xml; charset=utf-8'}
)
out = urllib.request.urlopen(request, context=unverifiedContext, timeout=20)
text = html.unescape(out.read().decode("utf-8"))
return text
def getUpdateIdentityByCategoryId(categoryId, withOriginalUpdatesString = False):
result = []
cookie = getCookie()
updatesString = getUpdates(cookie, categoryId)
updatesDoc = minidom.parseString(updatesString)
nodes = updatesDoc.getElementsByTagName("SecuredFragment")
for node in nodes:
xml = node.parentNode.parentNode
updateID = xml.firstChild.attributes["UpdateID"].nodeValue
packageMoniker = xml.getElementsByTagName("AppxMetadata")[0].attributes["PackageMoniker"].nodeValue
id = xml.parentNode.firstChild.firstChild.nodeValue
result.append((updateID, packageMoniker, id))
if not withOriginalUpdatesString:
return result
return result, updatesString
#------------------------------------------------------------------------------------------------------------------------------------
def getPackageIdentityName(packageFamilyName):
return packageFamilyName[:packageFamilyName.rfind("_")]
def getPackageVersionAndArch(packageMoniker):
firstIdx = packageMoniker.find("_")
secondIdx = packageMoniker.find("_", firstIdx + 1)
thirdIdx = packageMoniker.find("_", secondIdx + 1)
if firstIdx != -1 and secondIdx != -1 and thirdIdx != -1:
return packageMoniker[firstIdx + 1:secondIdx], packageMoniker[secondIdx + 1:thirdIdx]
return None
# [(updateID, packageMoniker, id, version, arch)...]
def getCurrentVersionInfo(packageFamilyName, categoryId):
packageIdentityName = getPackageIdentityName(packageFamilyName)
versions = []
result, xmlStr = getUpdateIdentityByCategoryId(categoryId, withOriginalUpdatesString=True)
for i in result:
packageMoniker = i[1]
if packageIdentityName in packageMoniker:
versions.append(i + getPackageVersionAndArch(packageMoniker))
return versions, xmlStr
def appxVer2GameVer(appxVersion: str) -> tuple[int]:
arr = appxVersion.split(".")
if (n := 4 - len(arr[2])) > 0:
arr[2] = ("0" * n) + arr[2]
major = arr[0]
minor = arr[1]
patch = arr[2][:-2]
revision = arr[2][-2:]
fifth = arr[3]
return (int(major), int(minor), int(patch), int(revision), int(fifth))
def gameVer2Str(gameVer: tuple[int], withFifth = False) -> str:
if withFifth:
return f"{gameVer[0]}.{gameVer[1]}.{gameVer[2]}.{gameVer[3]}.{gameVer[4]}"
else:
return f"{gameVer[0]}.{gameVer[1]}.{gameVer[2]}.{gameVer[3]}"
def checkForUpdate(pfn, categoryId, releaseType):
updateInfo, xml = getCurrentVersionInfo(pfn, categoryId)
with open("versions.json.min", "r") as f:
versions = json.load(f)
newVersion = True
gameVer = None
idt = getPackageIdentityName(pfn)
updateTxt = ""
for i in updateInfo:
if idt in i[1]:
updateTxt += f"{i[0]} {i[1]} {i[2]}\n"
if i[4] == "x64":
gameVer = gameVer2Str(appxVer2GameVer(i[3]))
for ver in versions:
if ver[2] == releaseType and ver[0] == gameVer:
newVersion = False
break
if newVersion:
versions.append([gameVer, i[0], releaseType])
if newVersion and gameVer:
print("New version found:", idt, gameVer)
commitMsg = "Minecraft " + gameVer
if releaseType == 2:
commitMsg += " (Preview)"
with open("versions.json.min", "w") as f:
json.dump(versions, f)
with open("versions.txt", "r") as f:
verTxt = f.read()
target = "Releases" if releaseType == 0 else "Preview"
start = verTxt.find("\n\n", verTxt.find(target))
with open("versions.txt", "w") as wf:
wf.write(verTxt[:start] + "\n" + updateTxt + verTxt[start:])
subprocess.run(["git", "add", "versions.json.min", "versions.txt"])
subprocess.run(["git", "-c", "user.name='github-actions[bot]'", "-c", "user.email='github-actions[bot]@users.noreply.github.com'", "commit", "-m", commitMsg])
subprocess.run(["git", "push", "origin"])
else:
print(idt, "is up to date.")
if __name__ == "__main__":
checkForUpdate("Microsoft.MinecraftUWP_8wekyb3d8bbwe", "d25480ca-36aa-46e6-b76b-39608d49558c", 0)
checkForUpdate("Microsoft.MinecraftWindowsBeta_8wekyb3d8bbwe", "188f32fc-5eaa-45a8-9f78-7dde4322d131", 2)