Guest User

Waifu Solitair Fix 5.0 with link to Tutorial

a guest
May 1st, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. [CmdletBinding()]
  2. param (
  3. [String] $Name,
  4. [Int] $Number = -1
  5. )
  6.  
  7. # If you want to change the website, pls look into the file start_rule34xxx.ps1 (https://pastebin.com/H4LAjX7b)
  8. # There are some pointers on how to start and do this.
  9.  
  10. if ([String]::IsNullOrEmpty($Name))
  11. {
  12. $waifu = Read-Host -Prompt "Waifu name?"
  13. }
  14. else
  15. {
  16. $waifu = $Name
  17. }
  18.  
  19. $auto_complete_url = "https://gelbooru.com/index.php?page=autocomplete2&term=$waifu"
  20.  
  21. $response = Invoke-WebRequest $auto_complete_url -UseBasicParsing
  22. $array_of_completions = $response.Content | ConvertFrom-Json
  23.  
  24. if($array_of_completions.Length -gt 1)
  25. {
  26. Write-Host "Found multiple choices for your waifu."
  27.  
  28. $completions = $response.Content | ConvertFrom-Json | ForEach-Object { $_.Value }
  29.  
  30. for($i = 1; $i -le $completions.Length; $i++)
  31. {
  32. Write-Host "${i}:" $completions[$i - 1]
  33. }
  34.  
  35. $hasChosenNumber = $false
  36.  
  37. while(-not $hasChosenNumber)
  38. {
  39. if ($Number -eq -1)
  40. {
  41. $number = Read-Host "Please select the number you intended."
  42. }
  43.  
  44. $number = $number - '0'
  45.  
  46. if($number -match "\d" -and $number -le $completions.Length -and $number -ge 1)
  47. {
  48. $waifu = $completions[$number - 1]
  49. $hasChosenNumber = $true
  50. }
  51. else
  52. {
  53. Write-Host "Please enter a valid number (e.g. 1)"
  54. }
  55. }
  56.  
  57. Write-Host ""
  58. Write-Host "You have chosen '$waifu' as a waifu."
  59. Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
  60. Write-Host ""
  61. Write-Host "E.g. if Morgana from League of Legends is your waifu, you should write 'morgana_(league_of_legends)' and not only 'morgana'."
  62. 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."
  63. Write-Host ""
  64. }
  65. else
  66. {
  67. Write-Host ""
  68. Write-Host "You have chosen '$waifu' as a waifu."
  69. Write-Host "Images will now be downloaded. After the download please write the same name on the solitair start-up."
  70. 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."
  71. Write-Host ""
  72. }
  73.  
  74. $waifu_path = "$PSScriptRoot\waifus\$waifu"
  75.  
  76. if (-not (Test-Path $waifu_path))
  77. {
  78. mkdir "waifus\$waifu" | Out-Null
  79.  
  80. $allPictures = @()
  81. $url_pattern = '<a id="p.\d*" href="(.*?)"'
  82. $maxPicturesOnPage = 42
  83. $maxCardsInDeck = 60
  84. for($page = 0; $page -lt 3; ++$page)
  85. {
  86. $start_page_id = $maxPicturesOnPage * $page
  87.  
  88. $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"
  89.  
  90. $response = Invoke-WebRequest $main_url_base -UseBasicParsing
  91.  
  92. $allFoundPictures = ($response.Content | Select-String -Pattern $url_pattern -AllMatches).Matches.Value
  93.  
  94. foreach ($foundPicture in $allFoundPictures)
  95. {
  96. $allPictures += $foundPicture
  97.  
  98. if ($allPictures.Length -gt $maxCardsInDeck)
  99. {
  100. # No need to download more pictures than cards
  101. break
  102. }
  103. }
  104.  
  105. if ($allFoundPictures.Length -ne $maxPicturesOnPage)
  106. {
  107. # This page was not full, so the next one should be empty
  108. break
  109. }
  110. }
  111.  
  112.  
  113. $jobCode =
  114. {
  115. [CmdletBinding()]
  116. param (
  117. [Parameter(Mandatory=$true)] [Int] $image_number,
  118. [Parameter(Mandatory=$true)] [String] $waifu_path,
  119. [Parameter(Mandatory=$true)] [String] $url_pattern,
  120. [Parameter(Mandatory=$true)] [String] $content
  121.  
  122. )
  123.  
  124. Write-Debug "Downloaded $image_number images so far. (Will stop at 10 for debugging so remove it)"
  125.  
  126. $content -match $url_pattern | Out-Null
  127.  
  128. $image_number = ($image_number + 1);
  129. $url = ($Matches[1] -replace "amp;","")
  130. $response = Invoke-WebRequest $url -UseBasicParsing
  131.  
  132. $response.Content -match 'href="(https://img\d.gelbooru.com/images/.*?\.(.*?))"' | Out-Null
  133.  
  134. $out_path = "$waifu_path\$image_number." + $Matches[2]
  135.  
  136. $oldProgPref = $ProgressPreference
  137. $ProgressPreference = "SilentlyContinue"
  138.  
  139. Invoke-WebRequest $Matches[1] -OutFile $out_path -UseBasicParsing | Out-Null
  140.  
  141. $ProgressPreference = $oldProgPref
  142.  
  143. if ($image_number % 10 -eq 0)
  144. {
  145. Write-Host "Downloaded $image_number images so far."
  146. }
  147. }
  148.  
  149. Write-Debug "FULL LOOP"
  150. $allJobs = @()
  151. for ($i = 0; $i -lt $allPictures.Length; ++$i)
  152. {
  153. $allJobs += Start-job -ScriptBlock $jobCode -ArgumentList $i, $waifu_path, $url_pattern, $allPictures[$i]
  154. }
  155.  
  156. foreach ($job in $allJobs)
  157. {
  158. Wait-Job $job | Out-Null
  159. }
  160. }
  161.  
  162. .\waifu_solitaire.exe
Add Comment
Please, Sign In to add comment