1
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
Write-Host 'Examples:'
Write-Host ' fav:username (a user''s favorites)'
Write-Host ' plapenjoyer (all posts with a tag)'
Write-Host ' plapenjoyer -female score:>25 (exclude a tag, minimum score)'
Write-Host ' -type:webm -type:mp4 -type:gif (exclude videos/gifs)'
Write-Host ' type:png rating:s (only PNGs, only safe)'
$Tag = (Read-Host 'Enter tags').Trim()
$clean = ($Tag -split '\s+' | Where-Object { $_ -notmatch '^-?ord(er|fav):' }) -join ' '
if ($clean -ne $Tag) { Write-Warning 'Removed order:/ordfav: term(s); results are always fetched newest-first.'; $Tag = $clean }
$saveTags = (Read-Host 'Save a .txt file with tags for each image? (Y/n)') -notmatch '^\s*n'
$DelayMs = 600
$base = 'https://e6ai.net'
$headers = @{ 'User-Agent' = 'e6ai-tag-downloader/1.0 (PowerShell)' }
$OutDir = Join-Path (Get-Location).Path (($Tag -replace '[\\/:*?"<>|]', '_') -replace '\s+', ' ')
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
$encodedTag = [uri]::EscapeDataString($Tag)
$beforeId = $null
$total = 0; $skipped = 0; $failed = 0
while ($true) {
$page = if ($beforeId) { "b$beforeId" } else { '1' }
$url = "$base/posts.json?tags=$encodedTag&limit=320&page=$page"
try { $resp = Invoke-RestMethod -Uri $url -Headers $headers }
catch { Write-Warning "Failed to fetch $url : $_"; break }
$posts = @($resp.posts)
if ($posts.Count -eq 0) { break }
foreach ($post in $posts) {
$beforeId = $post.id
$fileUrl = $post.file.url
if (-not $fileUrl) { Write-Warning "Post $($post.id) has no file URL (deleted/hidden); skipping."; $failed++; continue }
$name = "$($post.id)_$($post.file.md5)"
$imgPath = Join-Path $OutDir "$name.$($post.file.ext)"
$txtPath = Join-Path $OutDir "$name.txt"
if (-not (Test-Path -LiteralPath $imgPath)) {
try {
Invoke-WebRequest -Uri $fileUrl -Headers $headers -OutFile $imgPath
Write-Host "Downloaded $name.$($post.file.ext)"
$total++
} catch {
Write-Warning "Failed to download post $($post.id): $_"
if (Test-Path -LiteralPath $imgPath) { Remove-Item -LiteralPath $imgPath -Force }
$failed++
continue
}
Start-Sleep -Milliseconds $DelayMs
} else { $skipped++ }
if ($saveTags) {
$tags = foreach ($cat in $post.tags.PSObject.Properties) { $cat.Value }
Set-Content -LiteralPath $txtPath -Value (@($tags) -join "`n") -Encoding UTF8
}
}
Start-Sleep -Milliseconds $DelayMs
}
Write-Host "Done. Downloaded: $total, already present: $skipped, failed: $failed. Output: $OutDir"For immediate assistance, please email our customer support: [email protected]