-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathfetch.py
More file actions
254 lines (211 loc) · 8.35 KB
/
fetch.py
File metadata and controls
254 lines (211 loc) · 8.35 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import base64
import os
import json
import xml.etree.ElementTree as tree
from datetime import datetime, timezone, timedelta
import requests
# https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/util/additional_parameters.cc;drc=406947a0f1e0e6b596d387b6b14156f369e8c55d;l=206
info = {
"win_stable_x86": {
"os": '''arch="x86"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="x86-stable"''',
},
"win_stable_x64": {
"os": '''arch="x64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="x64-stable"''',
},
"win_stable_arm64": {
"os": '''arch="arm64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="arm64-stable"''',
},
"win_beta_x86": {
"os": '''arch="x86"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="1.1-beta-arch_x86"''',
},
"win_beta_x64": {
"os": '''arch="x64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="1.1-beta-arch_x64"''',
},
"win_beta_arm64": {
"os": '''arch="arm64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="1.1-beta-arch_arm64"''',
},
"win_dev_x86": {
"os": '''arch="x86"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="2.0-dev-arch_x86"''',
},
"win_dev_x64": {
"os": '''arch="x64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="2.0-dev-arch_x64"''',
},
"win_dev_arm64": {
"os": '''arch="arm64"''',
"app": '''appid="{8A69D345-D564-463C-AFF1-A69D9E530F96}" ap="2.0-dev-arch_arm64"''',
},
"win_canary_x86": {
"os": '''arch="x86"''',
"app": '''appid="{4EA16AC7-FD5A-47C3-875B-DBF4A2008C20}" ap="x86-canary"''',
},
"win_canary_x64": {
"os": '''arch="x64"''',
"app": '''appid="{4EA16AC7-FD5A-47C3-875B-DBF4A2008C20}" ap="x64-canary"''',
},
"win_canary_arm64": {
"os": '''arch="arm64"''',
"app": '''appid="{4EA16AC7-FD5A-47C3-875B-DBF4A2008C20}" ap="arm64-canary"''',
},
}
update_url = "https://tools.google.com/service/update2"
session = requests.Session()
def post(os: str, app: str) -> str:
xml = f"""<?xml version="1.0" encoding="UTF-8"?>
<request protocol="3.0" updater="Omaha" updaterversion="1.3.36.372" shell_version="1.3.36.352" ismachine="0" sessionid="{11111111-1111-1111-1111-111111111111}" installsource="taggedmi" requestid="{11111111-1111-1111-1111-111111111111}" dedup="cr" domainjoined="0">
<hw physmemory="16" sse="1" sse2="1" sse3="1" ssse3="1" sse41="1" sse42="1" avx="1"/>
<os platform="win" version="10.0.26100.1742" {os}/>
<app version="" {app}>
<updatecheck/>
<data name="install" index="empty"/>
</app>
</request>"""
r = session.post(update_url, data=xml)
r.raise_for_status()
return r.text
def decode(text):
root = tree.fromstring(text)
manifest_node = root.find(".//manifest")
if manifest_node is None:
print("Error: manifest_node is None")
return
manifest_version = manifest_node.get("version")
package_node = root.find(".//package")
if package_node is None:
print("Error: package_node is None")
return
package_name = package_node.get("name")
package_size = int(package_node.get("size"))
package_sha1 = base64.b64decode(package_node.get("hash")).hex()
package_sha256 = package_node.get("hash_sha256")
url_nodes = root.findall(".//url")
url_prefixes = [node.get("codebase") + package_name for node in url_nodes]
return {
"version": manifest_version,
"size": package_size,
"sha1": package_sha1,
"sha256": package_sha256,
"urls": url_prefixes,
}
def version_tuple(v):
return tuple(map(int, v.split(".")))
def load_json(file_path="data.json"):
if not os.path.exists(file_path):
return {}
try:
with open(file_path, "r") as f:
return json.load(f) or {}
except (json.JSONDecodeError, ValueError):
return {}
def fetch(info, results):
for k, v in info.items():
res = post(**v)
data = decode(res)
if data is None:
print(f"Error: No data returned for {k}")
continue
if version_tuple(data["version"]) < version_tuple(
results.get(k, {}).get("version", "0.0.0.0")
):
print("ignore", k, data["version"])
continue
results[k] = data
suffixes = ["B", "KB", "MB", "GB", "TB", "PB"]
def humansize(nbytes):
i = 0
while nbytes >= 1024 and i < len(suffixes) - 1:
nbytes /= 1024.0
i += 1
f = ("%.2f" % nbytes).rstrip("0").rstrip(".")
return f"{f} {suffixes[i]}"
def save_md(results, file_path="readme.md"):
def format_channel_arch(name):
parts = name.split("_")
return parts[0], parts[1], parts[2] # platform, channel, arch
channels = {}
for name, info in results.items():
platform, channel, arch = format_channel_arch(name)
if channel not in channels:
channels[channel] = {}
channels[channel][arch] = {
"name": name,
"version": info["version"],
"size": humansize(info["size"]),
"sha256": info["sha256"],
"url": next(
(
url
for url in info["urls"]
if url.startswith("https://") and "google.com" in url
),
info["urls"][0] if info["urls"] else "N/A",
),
}
with open(file_path, "w", encoding="utf-8") as f:
f.write("# Google Chrome Offline Installers (extract with 7-Zip)\n")
f.write(
"Stable release archive: "
"https://github.com/Bush2021/chrome_installer/releases\n\n"
)
channel_order = ["stable", "beta", "dev", "canary"]
channel_names = {
"stable": "Stable",
"beta": "Beta",
"dev": "Dev",
"canary": "Canary",
}
f.write("## Contents\n\n")
for channel in channel_order:
if channel in channels:
channel_name = channel_names.get(channel, channel.title())
f.write(f"- [{channel_name}](#{channel})\n")
f.write("\n")
for channel in channel_order:
if channel not in channels:
continue
channel_name = channel_names.get(channel, channel.title())
f.write(f"## {channel_name}\n\n")
f.write("| Architecture | Version | Size | SHA-256 | Download |\n")
f.write("|--------------|---------|------|---------|----------|\n")
arch_order = ["x86", "x64", "arm64"]
arch_names = {"x86": "x86", "x64": "x64", "arm64": "ARM64"}
for arch in arch_order:
if arch in channels[channel]:
info = channels[channel][arch]
sha256_short = (
info["sha256"][:16] + "..."
if len(info["sha256"]) > 16
else info["sha256"]
)
arch_display = arch_names.get(arch, arch.upper())
f.write(
f"| **{arch_display}** | `{info['version']}` | {info['size']} | `{sha256_short}` | [Download]({info['url']}) |\n"
)
f.write("\n")
f.write("<details>\n")
f.write("<summary>Full SHA-256 (sha256sum -c)</summary>\n\n")
f.write("```\n")
for arch in arch_order:
if arch in channels[channel]:
info = channels[channel][arch]
asset = f"{arch}_{info['url'].split('/')[-1]}"
f.write(f"{info['sha256']} {asset}\n")
f.write("```\n\n")
f.write("</details>\n\n")
def save_json(results, file_path="data.json"):
with open(file_path, "w") as f:
json.dump(results, f, indent=4)
def main():
results = load_json()
fetch(info, results)
save_md(results)
save_json(results)
if __name__ == "__main__":
main()