Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- param (
- [String] $Name,
- [Int] $Number = -1
- )
- # If you want to change the website, pls look into the file start_rule34xxx.ps1 (https://pastebin.com/H4LAjX7b)
- # There are some pointers on how to start and do this.
- if ([String]::IsNullOrEmpty($Name))
- {
- $waifu = Read-Host -Prompt "Waifu name?"
- }
- else
- {
- $waifu = $Name
- }
- $auto_complete_url = "https://gelbooru.com/index.php?page=autocomplete2&term=$waifu"
- $response = Invoke-WebRequest $auto_complete_url -UseBasicParsing
- $array_of_completions = $response.Content | ConvertFrom-Json
- if($array_of_completions.Length -gt 1)
- {
- Write-Host "Found multiple choices for your waifu."
- $completions = $response.Content | ConvertFrom-Json | ForEach-Object { $_.Value }
- for($i = 1; $i -le $completions.Length; $i++)
- {
- Write-Host "${i}:" $completions[$i - 1]
- }
- $hasChosenNumber = $false
- while(-not $hasChosenNumber)
- {
- if ($Number -eq -1)
- {
- $number = Read-Host "Please select the number you intended."
- }
- $number = $number - '0'
- if($number -match "\d" -and $number -le $completions.Length -and $number -ge 1)
- {
- $waifu = $completions[$number - 1]
- $hasChosenNumber = $true
- }
- else
- {
- Write-Host "Please enter a valid number (e.g. 1)"
- }
- }
- Write-Host ""
- Write-Host "You have chosen '$waifu' as a waifu."
- Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
- Write-Host ""
- Write-Host "E.g. if Morgana from League of Legends is your waifu, you should write 'morgana_(league_of_legends)' and not only 'morgana'."
- Write-Host "You can select the name between the 's and press enter to copy the text. Then just paste it by pressing right click into the console window."
- Write-Host ""
- }
- else
- {
- Write-Host ""
- Write-Host "You have chosen '$waifu' as a waifu."
- Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
- Write-Host "You can select the name between the 's and press enter to copy the text. Then just paste it by pressing right click into the console window."
- Write-Host ""
- }
- $waifu_path = "$PSScriptRoot\waifus\$waifu"
- if (-not (Test-Path $waifu_path))
- {
- mkdir "waifus\$waifu" | Out-Null
- $allPictures = @()
- $url_pattern = '<a id="p.\d*" href="(.*?)"'
- $maxPicturesOnPage = 42
- $maxCardsInDeck = 60
- for($page = 0; $page -lt 3; ++$page)
- {
- $start_page_id = $maxPicturesOnPage * $page
- $main_url_base = "https://gelbooru.com/index.php?page=post&s=list&tags=$waifu+rating%3aexplicit+sort%3ascore%3adesc+-animated_gif+-animated+-webm+-solo&pid=$start_page_id"
- $response = Invoke-WebRequest $main_url_base -UseBasicParsing
- $allFoundPictures = ($response.Content | Select-String -Pattern $url_pattern -AllMatches).Matches.Value
- foreach ($foundPicture in $allFoundPictures)
- {
- $allPictures += $foundPicture
- if ($allPictures.Length -gt $maxCardsInDeck)
- {
- # No need to download more pictures than cards
- break
- }
- }
- if ($allFoundPictures.Length -ne $maxPicturesOnPage)
- {
- # This page was not full, so the next one should be empty
- break
- }
- }
- $jobCode =
- {
- [CmdletBinding()]
- param (
- [Parameter(Mandatory=$true)] [Int] $image_number,
- [Parameter(Mandatory=$true)] [String] $waifu_path,
- [Parameter(Mandatory=$true)] [String] $url_pattern,
- [Parameter(Mandatory=$true)] [String] $content
- )
- Write-Debug "Downloaded $image_number images so far. (Will stop at 10 for debugging so remove it)"
- $content -match $url_pattern | Out-Null
- $image_number = ($image_number + 1);
- $url = ($Matches[1] -replace "amp;","")
- $response = Invoke-WebRequest $url -UseBasicParsing
- $response.Content -match 'href="(https://img\d.gelbooru.com/images/.*?\.(.*?))"' | Out-Null
- $out_path = "$waifu_path\$image_number." + $Matches[2]
- $oldProgPref = $ProgressPreference
- $ProgressPreference = "SilentlyContinue"
- Invoke-WebRequest $Matches[1] -OutFile $out_path -UseBasicParsing | Out-Null
- $ProgressPreference = $oldProgPref
- if ($image_number % 10 -eq 0)
- {
- Write-Host "Downloaded $image_number images so far."
- }
- }
- Write-Debug "FULL LOOP"
- $allJobs = @()
- for ($i = 0; $i -lt $allPictures.Length; ++$i)
- {
- $allJobs += Start-job -ScriptBlock $jobCode -ArgumentList $i, $waifu_path, $url_pattern, $allPictures[$i]
- }
- foreach ($job in $allJobs)
- {
- Wait-Job $job | Out-Null
- }
- }
- .\waifu_solitaire.exe
Add Comment
Please, Sign In to add comment