Skip to content

Instantly share code, notes, and snippets.

@hare1039 hare1039/iwara-friend.ps1
Last active Aug 17, 2019

Embed
What would you like to do?
This powershell script helps creaters on iwara accept or delete friend requests
# Created by hare1039
$ErrorActionPreference = "Stop"
$user = Read-Host -Prompt 'Enter User name'
$pass = Read-Host -Prompt 'Enter User password' -AsSecureString
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
)
Write-Host '[1] Accept all friend requests'
Write-Host '[2] Delete all friend requests'
$mode = Read-Host -Prompt 'Please enter 1 or 2'
if ($mode -eq "1") {
$IWARA_HTTP_METHOD="PUT"
} elseif ($mode -eq "2") {
$IWARA_HTTP_METHOD="DELETE"
$mode = Read-Host -Prompt 'Do you really want to delete all friend request?[Y/n]'
if ($mode -like '*n*') {
Write-Host 'Abort'
exit
}
} else {
exit
}
# setup data
$data = @{name="$user";pass="$pass";form_build_id='form-jacky';form_id='user_login';op='%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3'}
Write-Host "Logging into iwara"
$res = Invoke-WebRequest -Uri https://ecchi.iwara.tv/user/login -Method POST -MaximumRedirection 0 -Body $data -ErrorAction Ignore
if (!$res.Headers["Set-Cookie"])
{
Write-Host "Cannot login"
exit
}
# get cookie from response
$raw_cookie = $res.Headers["Set-Cookie"].Split(";")[0]
# setup cookie
$cookie = New-Object System.Net.Cookie
$cookie.Name = $raw_cookie.Split("=")[0]
$cookie.Value = $raw_cookie.Split("=")[1]
$cookie.Domain= "ecchi.iwara.tv"
# inject cookie
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.Cookies.Add($cookie)
Write-Host "fetching friend list page"
$res = Invoke-WebRequest -Uri 'https://ecchi.iwara.tv/user/friends' -WebSession $session
# get last page number
$last = ($res.AllElements | Where {$_.TagName -eq 'li'} | Where {$_.Class -like '*pager-last*'})
if ($last)
{
$last = $last.innerHTML.Split('"')[1]
$last = $last.Split('=')[1]
}
else
{
$last = "0"
}
$last = [int]$last
Write-Host "looping through all friend page 0 -> $last"
$count = 0
For ($i=$last; $i -ge 0; $i--)
{
#get request list
$res = Invoke-WebRequest -Uri "https://ecchi.iwara.tv/user/friends?page=$i" -WebSession $session
$res.AllElements |
Where {$_.TagName -eq 'button'} |
Where {$_.class -like '*accept-friend*'} |
ForEach-Object {$_."data-frid"} |
ForEach-Object {
$count++
$data = @{frid=$_};
$v=Invoke-WebRequest -Uri 'https://ecchi.iwara.tv/api/user/friends' -WebSession $session -Method $IWARA_HTTP_METHOD -Body $data
}
}
Write-Host "$count requests processed"
Pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.