Created
January 25, 2023 05:31
-
-
Save hl2guide/7feeaef0960b19461e8ffa362facec38 to your computer and use it in GitHub Desktop.
Connects to an aria2c RPC instance and adds a download.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Connects to an aria2c RPC instance and adds a download | |
| # Ref: | |
| # Curl: curl.exe http://localhost:6800/jsonrpc -H "Content-Type: application/json" -H "Accept:application/json" -d "{\"jsonrpc\":\"2.0\",\"method\":\"aria2.tellActive\",\"params\":[\"token:TOKEN\"],\"id\":1}" | |
| # Lint JSON: https://jsonlint.com/ | |
| # Last Edited: 2023-01-25 15:30:00PM | |
| $aria2cRPCURI = "http://localhost:6800/jsonrpc" | |
| # Set to your token | |
| $token = "" | |
| # Sets a likely unique ID for download | |
| $id = New-Guid | |
| # Allows for multiple URIs for a single file (tab character (`t) between each URI), | |
| # if all URIs are fully resolved (end with a filename and are not redirects) | |
| $download = @" | |
| http://m.gettywallpapers.com/wp-content/uploads/2020/01/Wallpaper-Naruto-2.jpg | |
| "@ | |
| $download = $download -replace "`n|`r","" | |
| # Cleans the output filename | |
| $outFile = ([uri]$download).Segments[-1] | |
| $outFile = [Management.Automation.WildcardPattern]::Escape($outFile) | |
| # Add a download | |
| # TELLACTIVE CODE ==== $body = "{`"jsonrcp`":`"2.0`",`"id`":`"$id`",`"method`":`"aria2.tellActive`",`"params`":[`"token:$token`"]}" | |
| $body = "{`"jsonrcp`":`"2.0`",`"id`":`"$id`",`"method`":`"aria2.addUri`",`"params`":[`"token:$token`",[`"$download`"],{`"out`":`"$outFile`"}]}" | |
| Write-Host "`nDownload Request Preview:`n" -ForegroundColor Cyan | |
| Write-Host "$body`n" -ForegroundColor Yellow | |
| Write-Host "Run this web request?`n" | |
| pause | |
| Invoke-WebRequest -Method Post -Uri $aria2cRPCURI -Body $body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment