So, I'm trying to download the latest release from GitHub using a Windows batch script. I can get a long list of URLs by running curl -s https://api.github.com/repos/ActualMandM/cemu_graphic_packs/releases/latest
, but I can't figure out how to pass the "browser_download_url": "https://github.com/ActualMandM/cemu_graphic_packs/releases/download/Github828/graphicPacks828.zip"
it outputs to curl. I've looked online, but everything I found was for PowerShell and most of them used wget.

- 3
- 2
-
1Why not use PowerShell then? – Compo Sep 19 '21 at 14:20
-
1CMD is notoriously incapable as far as its built-in functionality. You'll probably want to use either a POSIX shell with a tool like `jq` or a language like Perl or Ruby to parse the JSON, or possibly PowerShell. – bk2204 Sep 19 '21 at 14:20
2 Answers
If you really want to use batch for this, you'll have to search the output JSON for the value you're looking for and then process that string. If the JSON had appeared all on one line, you'd need to take a different approach, but you got lucky.
for /f "tokens=1,* delims=:" %%A in ('curl -ks https://api.github.com/repos/ActualMandM/cemu_graphic_packs/releases/latest ^| find "browser_download_url"') do (
curl -kOL %%B
)
I've added the -k
flag because my computer requires it for some reason (so other peoples' might as well).
-O
will set the name of the output file to the remote output file name
-L
follows a redirect, which is required for downloading from Github.

- 13,229
- 5
- 50
- 55
The Github API url you're accessing returns JSON, so you're going to need a JSON parser.
I can highly recommend xidel. xidel
can open and download urls, so you won't need curl
or a batch-script.
To query the "browser_download_url"-attribute:
xidel.exe -s "https://api.github.com/repos/ActualMandM/cemu_graphic_packs/releases/latest" -e "$json//browser_download_url"
https://github.com/ActualMandM/cemu_graphic_packs/releases/download/Github874/graphicPacks874.zip
(or -e "$json/(assets)()/browser_download_url"
in full)
To download 'graphicPacks874.zip' in the current dir:
xidel.exe ^
-s "https://api.github.com/repos/ActualMandM/cemu_graphic_packs/releases/latest" ^
-f "$json//browser_download_url" ^
--download "{substring-after($headers[starts-with(.,'Content-Disposition')],'filename=')}"
With r8389 or newer (because of this commit) you can just use --download .
.

- 3,203
- 1
- 13
- 21