Last active
June 22, 2018 20:43
-
-
Save WildDogOne/c154c839b2f3647697bc to your computer and use it in GitHub Desktop.
Furaffinity Downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cls | |
#Login Page for POST | |
$loginPage = "https://www.furaffinity.net/login/" | |
#Get Username | |
$username=read-host "Enter username: " | |
if($username -eq $null) | |
{ | |
Write-host "no User entered" | |
exit | |
} | |
#Get Password | |
$password=read-host "Enter password: " -AsSecureString | |
if($password -eq $null) | |
{ | |
Write-host "no password entered" | |
exit | |
} | |
#Make Password into a string, it's useless otherwise, we never talked security :P | |
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) | |
#Get Username of Gallery to grab, defaults to a cute gallery | |
$user=read-host "Enter FA Gallery name: " | |
if($user -eq $null) | |
{ | |
Write-host "no User entered, using default" | |
$user = "belayalapa" | |
} | |
#Get Destination, defaults to my liking, cause it's my script :D | |
$destination=read-host "Enter Destination: " | |
if($destination -eq $null) | |
{ | |
Write-host "no destination entered, using default" | |
$destination = "F:\Images\Grabber" | |
} | |
#Login via POST | |
$result = Invoke-WebRequest -UseBasicParsing -Uri $loginPage -SessionVariable session | |
$result = Invoke-WebRequest -UseBasicParsing -Uri $loginPage -WebSession $session -Method POST -Body @{'action'='login';'retard_protection'='1';'name'=$username;'pass'=$password;'login'='Login+to%C2%A0FurAffinity'} | |
if ($result.RawContent -match "You have typed in an erroneous username or password, please try again") | |
{ | |
Write-Host "Bad Login" | |
exit | |
} | |
#Build Destination with name of Artist | |
$destination = $destination+"\"+$user | |
$safe = $destination+"\rating~s" | |
$questionable = $destination+"\rating~q" | |
$explicit = $destination+"\rating~e" | |
#Site Variables | |
$gallery = "gallery/" | |
$site = "http://www.furaffinity.net/" | |
#Make Destination Folder if it ain't there | |
if(!(Test-Path $destination)){ | |
New-Item -ItemType directory -Path $destination | |
} | |
#Make Destination Folder if it ain't there | |
if(!(Test-Path $safe)){ | |
New-Item -ItemType directory -Path $safe | |
} | |
#Make Destination Folder if it ain't there | |
if(!(Test-Path $questionable)){ | |
New-Item -ItemType directory -Path $questionable | |
} | |
#Make Destination Folder if it ain't there | |
if(!(Test-Path $explicit)){ | |
New-Item -ItemType directory -Path $explicit | |
} | |
#Some variables | |
$siteCounter = 1 | |
$count = 0 | |
$max = 0 | |
$maxPath = 250 | |
$links = @() | |
#get all the gallery items, will take a while | |
do { | |
#Get Gallery | |
$website = Invoke-WebRequest -WebSession $session -UseBasicParsing –Uri $site$gallery$user/$siteCounter | |
#if no Submissions exist, exit loop | |
if($website.RawContent -match "There are no submissions to list") | |
{ | |
$max = 1 | |
}else | |
{ | |
#add links to link list | |
$links += $website.Links | |
#increase site counter by 1 | |
$siteCounter++ | |
} | |
} while ($max -eq 0) | |
#foreach link in the link list | |
foreach ($link in $links) | |
{ | |
$rating = "q" | |
#check if the string view is present | |
if ($link.href -match "view"){ | |
$tags = "" | |
$link = $link.href | |
#Start building the picture name, used to store the data | |
$bildName = $link -replace "/view","" | |
$bildName = $bildName -replace "/","" | |
$bildName = "furaffinity.net "+$bildName | |
#request the website and push into a variable | |
$html = Invoke-WebRequest -WebSession $session -UseBasicParsing –Uri $site$link | |
#Download Image list to see if Adult or not | |
$images = $html.Images | |
foreach($image in $images) | |
{ | |
if($image.outerHTML -match "adult") | |
{ | |
$rating = "e" | |
}elseif($image.outerHTML -match "mature") | |
{ | |
$rating = "q" | |
}elseif($image.outerHTML -match "general") | |
{ | |
$rating = "s" | |
} | |
} | |
#Download the links of the subsite, so we can find the download link for the picture | |
$websites = $html.links | |
foreach($website in $websites) | |
{ | |
#if search is found, we assume the link is a tag, tags are interpreted and added to the filename | |
if($website.href -match "search/@keywords" -and !($website.href -match $user)) | |
{ | |
$tag = $website.href -replace "/search/@keywords\s","" | |
$tags += " "+$tag | |
} | |
#if art/+username is found, that signals we found the picture to download | |
if($website.href -match ("art/"+$user) -and $website -match ("Download")) | |
{ | |
$bild = $website.href -replace "//","" | |
$filetype = $bild -replace ".*\.","" | |
} | |
} | |
if($rating -eq "e") | |
{ | |
$destination = $explicit | |
}elseif($rating -eq "s"){ | |
$destination = $safe | |
}else{ | |
$destination = $questionable | |
} | |
#Concat the picture name | |
$bildName = $bildName+" artist~"+$user+" "+$tags+"." | |
$bildName = $bildName -replace "\s\s"," " | |
#this loop is made, so that the filename doesn't become bigger than the filesystem can handle. Damn windows! | |
$t =1 | |
while ($t -eq 1){ | |
if (($destination.length+$bildName.Length+1+$filetype.length) -ge ($maxPath)) | |
{ | |
$bildName = $bildName -replace "\s[^\s]*$","" | |
} | |
else | |
{ | |
$bildName = $bildName + "." + $filetype | |
$t = 0 | |
} | |
} | |
$bildName = $bildName -replace "\.\.","." | |
$bild | |
$bildName | |
#Finally download the found picture to the correct destination | |
Invoke-WebRequest $bild -OutFile $destination"\"$bildName -UseBasicParsing -WebSession $session | |
$count++ | |
} | |
} | |
Write-Host "Pics grabbed: "$count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment