43 lines
1.3 KiB
Bash
43 lines
1.3 KiB
Bash
#!/bin/bash
|
|
RDR_AUTH=$(cat ./conf/auth.token);
|
|
err="";
|
|
|
|
if [ -z $1 ]; then
|
|
pid=$(cat pid);
|
|
else
|
|
pid="$1"; # Allows for an argument to be passed to this script, i.e. a custom post ID
|
|
fi
|
|
|
|
# Stores the result of the curl GET into a file (only use for this was to find out I've reached API limit)
|
|
# curl "https://rdrama.net/post/$pid" -X GET -H "$RDR_AUTH" --SILENT | jq > debug.json
|
|
|
|
get=$(curl "https://rdrama.net/post/$pid" \
|
|
-X GET \
|
|
-H "$RDR_AUTH" \
|
|
--SILENT | jq \
|
|
| grep '"url":\|"code":' \
|
|
);
|
|
|
|
get_code=$(echo "$get" | grep '"code":' | tr -d ', ' | cut -d ':' -f2);
|
|
get_url=$(echo "$get" | grep '"url":' | cut -d'"' -f4);
|
|
|
|
|
|
if [ -n "$get_code" ]; then
|
|
if [ "$get_code" = '403' ]; then err="noauth";
|
|
elif [ "$get_code" = '404' ]; then err="finish";
|
|
elif [ "$get_code" = '429' ]; then err="rlimit";
|
|
else err="erridk"; fi;
|
|
else get="$get_url"
|
|
if [ -z "$get" ]; then err="nolink"; else get=$(echo "$get" | grep 'reddit.com');
|
|
if [ -z "$get" ]; then err="notrdt"; else get=$(echo "$get" | grep -e 'https://reddit\.com.*/s/'); # Final check for URL regex
|
|
if [ -z "$get" ]; then err="notrds"; fi; fi; fi;
|
|
fi;
|
|
|
|
if [ -n "$err" ]; then echo "error $err";
|
|
else
|
|
get=$(./linkloc "${get}"); # If url pattern is matched, pass it to the script that gets the real link
|
|
echo "$get"
|
|
fi
|
|
|
|
sleep 90
|
|
# Pauses script for 90 seconds to stay within API rate limits |