从 Shadertoy 下载 GLSL shader 源码及全部关联资源的命令行工具。
A Python CLI that downloads Shadertoy GLSL shader source and all linked assets (textures, audio, video, cubemaps).
ShadertoyTool is a single-file Python script (fetch_shadertoy.py) that fetches complete shader source code from Shadertoy via URL or 6-character Shader ID, exports it as .glsl, and downloads all referenced input assets with a manifest.json inventory.
To deal with Cloudflare challenges, it has a multi-tier fetch strategy: official API key, legacy POST endpoint with extracted browser cookies, and a Playwright + Microsoft Edge browser fallback.
单文件 Python 脚本,通过 Shadertoy URL 或 6 位 Shader ID 抓取完整着色器源码,导出为 .glsl 文件,同时下载着色器引用的所有输入资源并生成 manifest.json 清单。
为了绕过 Cloudflare 验证,工具内置三级获取策略:官方 API Key、模拟网页端的 legacy POST(附带从本机浏览器提取的 Cookie)、以及基于 Playwright + Microsoft Edge 的浏览器回退。
- Download complete GLSL source via URL or Shader ID
- Extracts all Render Passes (Image / Buffer / Sound / Common etc.) into a single annotated
.glslfile - Downloads referenced textures, audio, video, cubemaps
- Generates
manifest.jsonwith URL, filename, download status, and reference location for each asset - Supports Shadertoy API Key (
/api/v1) for direct, stable access - Auto-extracts cookies from local browsers (Chrome / Edge / Brave / Firefox)
- Playwright + Edge browser fallback for Cloudflare bypass
- Auto-retry on retriable HTTP codes (408/429/500/502/503/504)
- Assets blocked by 403 / Cloudflare are automatically retried via browser context
- 通过 URL 或 Shader ID 下载完整 GLSL 源码
- 自动提取所有 Render Pass(Image / Buffer / Sound / Common 等),按注释分隔写入单个
.glsl文件 - 下载 Shader 引用的纹理、音频、视频、Cubemap 等输入资源
- 生成资源清单
manifest.json,记录每个资源的 URL、保存文件名、下载状态与引用位置 - 支持 Shadertoy API Key(
/api/v1)直接访问,最稳定 - 从本机浏览器(Chrome / Edge / Brave / Firefox)自动提取 Cookie
- 内置 Playwright + Edge 浏览器回退,通过 Cloudflare 验证
- 对可重试的 HTTP 状态码(408/429/500/502/503/504)自动重试
- 资源下载被 403 / Cloudflare 拦截时自动通过浏览器上下文重试
- Language / 语言: Python 3.8+
- Dependencies / 依赖 (
requirements.txt):requests>=2.28— HTTP requestsbrowser-cookie3>=0.19— extract cookies from local browsersplaywright>=1.40— browser fallback (uses local Edge by default)
ShadertoyTool/
├── fetch_shadertoy.py # Main script (CLI entry, fetch & asset download logic)
├── fetch_shadertoy.cmd # Windows batch wrapper, auto-installs missing deps
├── requirements.txt # Python dependencies
├── SECURITY.md
├── LICENSE # MIT
└── .gitignore
- Python 3.8+
- pip
pip install -r requirements.txtPlaywright browser driver (only needed for the browser fallback; defaults to local Microsoft Edge):
python -m playwright install chromiumRun fetch_shadertoy.cmd — it checks for requests, browser_cookie3, playwright, auto-installs anything missing via pip, then runs fetch_shadertoy.py.
# Download by URL
python fetch_shadertoy.py https://www.shadertoy.com/view/4djyRD
# Download by Shader ID
python fetch_shadertoy.py 4djyRD
# Windows batch
fetch_shadertoy.cmd XltGDrRunning without arguments downloads https://www.shadertoy.com/view/4djyRD by default.
不带参数运行时默认下载 https://www.shadertoy.com/view/4djyRD。
| Param | Description / 说明 | Default |
|---|---|---|
shader |
Shadertoy URL or 6-char Shader ID (positional, optional) | https://www.shadertoy.com/view/4djyRD |
-o, --out-dir |
GLSL output directory / GLSL 输出目录 | downloads |
--api-key |
Shadertoy API Key (uses /api/v1 route) |
— |
--no-browser |
Disable browser fallback / 禁用浏览器回退 | off |
--headless |
Headless mode for browser fallback / 浏览器回退无头模式 | off |
--verify-attempts |
Manual verification retries in browser mode / 手动验证重试次数 | 5 |
--skip-assets |
Skip asset download / 跳过资源下载 | off |
--assets-dir |
Asset save directory / 资源保存目录 | <out-dir>/<shader_id>_assets |
# Use API Key (recommended, most stable)
python fetch_shadertoy.py XltGDr --api-key YOUR_API_KEY
# Source only, no assets
python fetch_shadertoy.py 4d33Dj --skip-assets
# Custom output directory
python fetch_shadertoy.py XtlSD7 -o ./my_shaders
# Headless browser fallback
python fetch_shadertoy.py 4djyRD --headlessdownloads/
├── XltGDr.glsl # GLSL source (all passes)
└── XltGDr_assets/
├── manifest.json # Asset download manifest
├── texture_01.png
└── audio_track.mp3
Each .glsl file contains all Render Passes with annotated headers:
每个 .glsl 文件包含该 Shader 的所有 Render Pass,以注释头标注:
// ShaderToy ID: XltGDr
// Name: Contra
// Retrieved: 2025-01-01 12:00:00 UTC
// ===== Pass 0: Image (image) =====
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// ...
}
// ===== Pass 1: Buffer_A (buffer) =====
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// ...
}Fetch priority:
- API v1 (requires
--api-key) — official REST API (/api/v1/shaders/<id>?key=<key>), most reliable - Legacy POST — sends an internal request to
https://www.shadertoy.com/shadertoywith cookies extracted from local browsers - Playwright browser fallback — launches local Microsoft Edge, passes Cloudflare, then calls the same legacy endpoint via in-page
fetch
Asset download also supports fallback: requests first, 403 / Cloudflare-blocked assets are retried via browser context.
Browser fallback uses locally installed Microsoft Edge (searches common install paths for msedge.exe). In visible-window mode you complete the manual verification in the opened browser.
获取优先级:
- API v1(需要
--api-key)— 官方 REST API,最可靠 - Legacy POST — 向
https://www.shadertoy.com/shadertoy发送模拟网页端请求,附带从本机浏览器提取的 Cookie - Playwright 浏览器回退 — 启动本机 Microsoft Edge,通过 Cloudflare 验证后在页面内
fetch相同接口
资源下载同样支持回退:先用 requests 直接下载,被 403 / Cloudflare 拦截的自动通过浏览器上下文重试。
浏览器回退依赖本机安装的 Microsoft Edge(在常见安装路径中查找 msedge.exe)。可见窗口模式下需要在打开的浏览器中完成人工验证。
Using an API Key bypasses Cloudflare entirely — it's the most stable method.
使用 API Key 可以直接走官方 API,无需处理 Cloudflare 验证,是最稳定的方式。
Personal utility tool. Single-file script, functional. Fetch success rate may fluctuate as Shadertoy's internal endpoints and Cloudflare settings change.
个人实用工具,单文件脚本,功能可用。因依赖 Shadertoy 内部接口与 Cloudflare 验证,抓取成功率可能随站点变化而波动。