Advertisement
Guest User

Waifu Solitair Fix 3

a guest
Dec 21st, 2020
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $waifu = Read-Host -Prompt "Waifu name?"
  2.  
  3. $auto_complete_url = "https://gelbooru.com/index.php?page=autocomplete2&term=$waifu"
  4.  
  5. $response = Invoke-WebRequest $auto_complete_url
  6. $completions = $response.Content | ConvertFrom-Json | % { $_.name }
  7.  
  8. if($completions.Length -gt 1)
  9. {
  10.     Write-Host "Found multiple choices for your waifu."
  11.  
  12.     for($i = 1; $i -le $completions.Length; $i++)
  13.     {
  14.         Write-Host "${i}:" $completions[$i - 1]
  15.     }
  16.  
  17.     $hasChosenNumber = $false
  18.  
  19.     while(-not $hasChosenNumber)
  20.     {
  21.         $number = Read-Host -Promt "Please select the number you intended."
  22.  
  23.         $number = $number - '0'
  24.  
  25.         if($number -match "\d" -and $number -le $completions.Length -and $number -ge 1)
  26.         {
  27.             $waifu = $completions[$number - 1]
  28.             $hasChosenNumber = $true
  29.         }
  30.         else
  31.         {
  32.             Write-Host "Please enter a valid number (e.g. 1)"
  33.         }
  34.     }
  35.  
  36.     Write-Host ""
  37.     Write-Host ""
  38.     Write-Host "You have chosen $waifu."
  39.     Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
  40.     Write-Host ""
  41.     Write-Host "E.g. if Morgana from League of Legends is your waifu, you should write 'morgana_(league_of_legends)' and not only 'morgana'."
  42.     Write-Host ""
  43. }
  44. else
  45. {
  46.     Write-Host ""
  47.     Write-Host "You have chosen $waifu as a waifu."
  48.     Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
  49.     Write-Host ""
  50. }
  51.  
  52. $waifu_path = "waifus\$waifu"
  53.  
  54. if (-not (Test-Path $waifu_path))
  55. {
  56.     mkdir "waifus\$waifu" | Out-Null
  57.  
  58.     $full_page = $true
  59.     $match_count = 0
  60.     $page = 0
  61.  
  62.     while($full_page -and $page -lt 3)
  63.     {
  64.  
  65.         $start_page_id = 42 * $page
  66.  
  67.         $main_url_base = "https://gelbooru.com/index.php?page=post&s=list&tags=$waifu+rating%3aexplicit+sort%3ascore%3adesc+-animated_gif+-animated+-webm+solo+-absurdres&pid=$start_page_id"
  68.  
  69.         $response = Invoke-WebRequest $main_url_base
  70.  
  71.         ($response.Content | Select-String -Pattern 'js-pop" id="p.\d*" href="(.*?)"' -AllMatches).Matches.Value |
  72.         % {
  73.             $_ -match 'js-pop" id="p.\d*" href="(.*?)"' | Out-Null
  74.  
  75.             $match_count = ($match_count + 1);
  76.             $url = "https:" + ($Matches[1] -replace "amp;","")
  77.             $response = Invoke-WebRequest $url
  78.  
  79.             $response.Content -match 'href="(https://img2.gelbooru.com/images/.*?\.(.*?))"' | Out-Null
  80.  
  81.             $out_path = "$waifu_path\$match_count." + $Matches[2]
  82.        
  83.             $img = Invoke-WebRequest $Matches[1] -OutFile $out_path
  84.         }
  85.         $page++
  86.  
  87.         $full_page = $match_count -eq 42
  88.     }
  89. }
  90.  
  91. .\waifu_solitaire.exe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement