156 lines
4.3 KiB
Bash
Executable File
156 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
i=1
|
|
rep=$1 # how many submissions to generate
|
|
maxsubs=52089873 #sets the default maximum bound of submission depth, should be left here if the max bound can't be updated for whatever reason.
|
|
# It's recommended to set the max subs yourself, as there isn't a good
|
|
# way to poll the website and check for that.
|
|
|
|
minsubs=0 #sets the default minimum bound of submission depth
|
|
minsubarg=$2
|
|
|
|
#Check for dependencies
|
|
if command -v curl >/dev/null 2>&1 ; then
|
|
:
|
|
else
|
|
echo "curl is not available. exiting."
|
|
exit
|
|
fi
|
|
|
|
if command -v xdg-open >/dev/null 2>&1 ; then
|
|
:
|
|
else
|
|
echo "xdg-open is not available. exiting."
|
|
exit
|
|
fi
|
|
|
|
if command -v shuf >/dev/null 2>&1 ; then
|
|
:
|
|
else
|
|
echo "shuf is not available. exiting."
|
|
exit
|
|
fi
|
|
|
|
if command -v grep >/dev/null 2>&1 ; then
|
|
:
|
|
else
|
|
echo "grep is not available. exiting."
|
|
exit
|
|
fi
|
|
|
|
echo "===FA.SH: The Random FA Sub Generator==="
|
|
if [ ! -f ./cookies.txt ]; then
|
|
echo "!! You haven't provided a cookies.txt file !!"
|
|
echo "Providing a cookies file will let this script scrape titles from all submissions!"
|
|
echo "Place a cookies file in the same folder as this script."
|
|
fi
|
|
|
|
validate=1
|
|
# Validate the rep count is only numbers.
|
|
while [ $validate -eq 1 ]
|
|
do
|
|
if [[ -z "$rep" ]]; then
|
|
validate=1
|
|
echo "///"
|
|
echo "How many submissions to pull? (Default: 1)"
|
|
echo "///"
|
|
read rep
|
|
fi
|
|
|
|
if [[ -n "$rep" ]]; then
|
|
echo "Debug: Checking Submission Input."
|
|
if [[ $rep != [0-9]* ]]; then
|
|
echo "Submission Argument Not an Integer."
|
|
unset rep
|
|
else
|
|
((validate--));
|
|
fi
|
|
fi
|
|
|
|
done
|
|
|
|
# Note: curl Doesn't seem to care if the cookies file is missing, probably don't need to add case statements. yay?
|
|
# Pull the main page of FA to get the latest Submission ID.
|
|
|
|
echo "debug: Pulling furaffinity.net index page for latest Sub ID."
|
|
mainpagefetch=$(curl -b "./cookies.txt" -s --stderr - https://www.furaffinity.net/)
|
|
# find the first figure id field and cut it down before changing maxsubs.
|
|
maxsubidparse=$(grep -m1 -Po 'figure id="\K[^"]*' <<< "$mainpagefetch" | cut -c 5-)
|
|
echo "debug: $maxsubidparse"
|
|
if [[ -n "$maxsubidparse" ]]; then
|
|
echo "debug: Latest Known Sub ID Was $maxsubidparse"
|
|
maxsubs=$maxsubidparse
|
|
else
|
|
echo "debug: couldn't get latest known Sub ID, falling back to hardcoded Sub ID."
|
|
fi
|
|
|
|
echo "debug: amount of submissions requested: $rep"
|
|
if [[ -z "$minsubarg" ]]; then
|
|
echo "debug: no minimum sub id given"
|
|
else
|
|
echo "debug: minimum sub id: $minsubarg"
|
|
fi
|
|
|
|
echo "debug: max sub id: $maxsubs"
|
|
|
|
if [[ $minsubarg -gt $minsubs ]]; then
|
|
minsubs=$minsubarg
|
|
else
|
|
minsubs=$minsubs
|
|
fi
|
|
|
|
echo "debug: min sub id: $minsubs"
|
|
|
|
if [ ! -f ./already-checked.txt ]; then
|
|
echo "debug: missing already-checked.txt, touching it now."
|
|
touch already-checked.txt
|
|
fi
|
|
|
|
repeat=1
|
|
|
|
while [ $repeat -eq 1 ]
|
|
do
|
|
|
|
while [ $i -le $rep ]
|
|
do
|
|
ranid=$(shuf -i $minsubs-$maxsubs -n1)
|
|
if grep -w $ranid already-checked.txt; then #check if it's been seen before, re-roll without iterating the loop and check again.
|
|
echo "😿 Already presented $ranid , re-rolling."
|
|
else
|
|
# curl the url if it's not in the list already
|
|
# see if it errors out for not existing in the database.
|
|
result=$(curl -b "./cookies.txt" -s --stderr - https://www.furaffinity.net/view/$ranid)
|
|
title=$(grep -m 1 "title" <<< "$result" | cut -c 12- | rev | cut -c 35- | rev)
|
|
if grep -q "not in our database" <<< "$result"; then
|
|
echo "($i of $rep) $ranid does not exist, logged and re-rolling."
|
|
echo "$ranid" >> already-checked.txt
|
|
sleep 0.5
|
|
elif grep -q "pending deletion" <<< "$result"; then
|
|
echo "($i of $rep) $ranid is pending deletion, logged and re-rolling."
|
|
echo "$ranid" >> already-checked.txt
|
|
sleep 0.5
|
|
# if it passes the second test, run the main script.
|
|
#todo: add an additional step with a SFW/NSFW flag state
|
|
# checking the rating of the submission, kicking back if an argument flag is set (ex: --safe?)
|
|
else
|
|
# Only upticks the counter on a hit.
|
|
xdg-open https://furaffinity.net/view/$ranid 2> /dev/null
|
|
echo "$ranid" >> already-checked.txt
|
|
echo "($i of $rep) 🔫 New Sub! $ranid -- $title"
|
|
counts=$(wc already-checked.txt | awk '{print $1}')
|
|
|
|
sleep 0.5 #to avoid site throttling.
|
|
((i++))
|
|
fi
|
|
fi
|
|
|
|
done
|
|
echo "viewed $counts pages so far."
|
|
read -r -p "😼 Do you want to go another $rep? (Y/n): " answer
|
|
case $answer in
|
|
[Yy]* ) echo "Going for another round!"; i=1;;
|
|
[Nn]* ) ((repeat--)); echo "Ok, bye!";;
|
|
* ) echo "Going for another round!"; i=1;;
|
|
esac
|
|
done
|
|
exit
|