- Create
extensions.txt
file in script location and write list of extensions to get inside it. For example:
ms-toolsai.jupyter
ms-python.vscode-pylance
ms-vscode.cpptools
# and so on
This is the script:
import requests
from time import sleep
from os.path import exists
extensions = []
with open("extensions.txt", 'r') as f:
for line in f:
if not line.startswith('#'):
extensions.append(line.strip())
with requests.session() as session:
session.headers.update({
"user-agent": "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0",
"host": "marketplace.visualstudio.com",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"accept-language": "en-US,en;q=0.5",
"accept-encoding": "gzip, deflate, br",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"Sec-Fetch-Site" : "none",
"Sec-Fetch-User": "?1",
"Sec-GPC": "1"
})
session.get("https://marketplace.visualstudio.com/")
for extension in extensions:
pub, name = extension.split('.')
if exists(f"{pub}.{name}.vsix"):
print(f"'{name}'' already exists, skipping")
continue
print(f"Getting '{name}'")
data = b''
try:
with session.get(f"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/{pub}/vsextensions/{name}/latest/vspackage", stream=True) as stream:
file_size = int(stream.headers["Content-Length"])
for content in stream.iter_content(1024, decode_unicode=False):
if content:
data += content
print(f"got {min(len(data)/file_size*100, 100):.2f}%", end='\r')
print()
except KeyboardInterrupt:
print("\nExiting")
quit()
except Exception:
print(f"Error for '{name}'")
continue
with open(f"{pub}.{name}.vsix", 'wb') as f:
f.write(data)
print("Done, waiting a bit before next request")
sleep(5)