Skip to content

Instantly share code, notes, and snippets.

@eddiezato
Last active December 12, 2024 03:51
Show Gist options
  • Save eddiezato/39675e86f2d9b1f3e0df00405c8b1a24 to your computer and use it in GitHub Desktop.
Save eddiezato/39675e86f2d9b1f3e0df00405c8b1a24 to your computer and use it in GitHub Desktop.
Python: script to download and extract chrome installer
#!/usr/bin/env python3
import glob
import json
import msvcrt
import os
import requests
import shutil
import subprocess
_reset, _invert, _green, _red = '\033[0m', '\033[7m', '\033[92m', '\033[91m'
_hidecur, _showcur, _up, _down = '\033[?25l', '\033[?25h', '\033[A', '\033[B'
r = '''{"request": { "protocol": "3.1", "dedup": "cr", "ismachine": 1,
"hw": { "physmemory": "16", "sse3": "1", "avx": "1" },
"os": { "platform": "win", "version": "10.0.22631", "arch": "x86_64" },
"app": [{ "appid": "{8A69D345-D564-463C-AFF1-A69D9E530F96}", "updatecheck": {}},
{ "appid": "{8237E44A-0054-442C-B6B6-EA0509993955}", "updatecheck": {}},
{ "appid": "{401C381F-E0DE-4B85-8BD8-3F3F14FBDA57}", "updatecheck": {}},
{ "appid": "{4EA16AC7-FD5A-47C3-875B-DBF4A2008C20}", "ap": "x64-canary", "updatecheck": {}}]}}'''
try:
r = requests.post('https://tools.google.com/service/update2/json', data = r)
except:
r = None
if r != None and r.status_code == 200:
app = json.loads(r.text[5:])['response']['app']
output = []
for r in app:
output.append(dict(channel = r['cohortname'], version = r['updatecheck']['manifest']['version']))
pl = tuple(max({len(item[key]) for item in output} | {len(key) + 2}) for key in tuple(output[0]))
print('\n' + _green, end = ' ')
for i, key in enumerate(tuple(output[0])):
print(' ' + key.ljust(pl[i]), end = ' ')
print()
for i in range(len(tuple(output[0]))):
print(' ' + '-' * pl[i], end = ' ')
print(_reset)
for channel in output:
print(' ', end = '')
for i, value in enumerate(channel.values()):
print(value.ljust(pl[i]), end = ' ')
print()
key = index = 0
print(_hidecur + _up * len(output), end = '\r')
print(' ' + _invert + output[index]['channel'].ljust(pl[0]) + _reset, end = '\r')
while key not in (3, 13, 27):
key = ord(msvcrt.getwch())
if key == 224:
key = ord(msvcrt.getwch())
index_ = index
mv = ''
match key:
case 72:
if index > 0:
index -= 1
mv = _up
case 80:
if index < (len(output) - 1):
index += 1
mv = _down
if index != index_:
print(' ' + output[index_]['channel'].ljust(pl[0]) + mv, end = '\r')
print(' ' + _invert + output[index]['channel'].ljust(pl[0]) + _reset, end = '\r')
print(_down * (len(output) - index) + _showcur, end = '\r')
if key == 13:
wd = 'D:\\Downloads\\'
prefix = next(x['codebase'] for x in app[index]['updatecheck']['urls']['url'] if 'dl.google.com' in x['codebase'])
file = app[index]['updatecheck']['manifest']['packages']['package'][0]['name']
ver = app[index]['updatecheck']['manifest']['version']
print()
_ = subprocess.call(f'curl -L -o {wd}{file} {prefix}{file}')
if _ == 0 and os.path.exists(wd + file):
_ = subprocess.call(f'7z x {wd}{file} -o{wd} -aoa -bso0 -bsp1 -y')
if _ == 0 and os.path.exists(wd + 'chrome.7z'):
os.remove(wd + file)
_ = subprocess.call(f'7z x {wd}chrome.7z -o{wd} -aoa -bso0 -bsp1 -y')
if _ == 0 and os.path.exists(wd + 'Chrome-bin'):
os.remove(wd + 'chrome.7z')
os.rename(wd + 'Chrome-bin', wd + 'app')
if os.path.exists(f'{wd}app\\{ver}'):
shutil.rmtree(f'{wd}app\\{ver}\\default_apps')
shutil.rmtree(f'{wd}app\\{ver}\\Extensions')
shutil.rmtree(f'{wd}app\\{ver}\\WidevineCdm')
for rmlang in glob.glob(f'{wd}app\\{ver}\\Locales\\*'):
if not rmlang.endswith('en-US.pak'):
os.remove(rmlang)
else:
print(_red + '\nsomething went wrong' + _reset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment