Add wait time for the api to be usable again, cause of rate limiting.

This commit is contained in:
CronyAkatsuki 2023-03-23 21:04:21 +01:00
parent 1c0a265455
commit e8f3cca8a9

View File

@ -20,14 +20,19 @@ list() {
done | column -t -s '|' | dmenu -i -l 15 | awk '{print $1}'
}
query=$(printf '%s' | dmenu -i -p "Enter search term: " | sed 's/ /%20/g')
base_url="https://torrentapi.org/pubapi_v2.php?"
token=$(curl -sLH "User-agent: 'your bot 0.1'" "${base_url}get_token=get_token&app_id=pirokit" | jq -r '.token')
token=$(curl -sLH "User-agent: 'your bot 0.1'" "${base_url}get_token=get_token&app_id=dmenu-rarbg" | jq -r '.token')
default_args="&token=${token}&limit=100&app_id=pirokit&format=json_extended"
while [ "$token" = "" ]; do
token=$(curl -sLH "User-agent: 'your bot 0.1'" "${base_url}get_token=get_token&app_id=dmenu-rarbg" | jq -r '.token')
notify-send "RARGB" "Waiting 5 second for api limit to reset"
sleep 5
done
default_args="&token=${token}&limit=100&app_id=dmenu-rarbg&format=json_extended"
query=$(printf '%s' | dmenu -i -p "Enter search term: " | sed 's/ /%20/g')
if [ "$query" = "" ]; then
url="${base_url}mode=list${default_args}"
@ -36,19 +41,24 @@ else
fi
case "$(printf "All\\nMovies\\nTV Shows\\nGames\\nMusic" | dmenu -i -p "Choose category: ")" in
All) response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}");;
Movies) response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}&category=17;44;45;47;50;51;52;42;46;54");;
"TV Shows") response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}&category=2;18;41;49");;
Games) response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}&category=2;27;28;29;30;31;53");;
Music) response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}&category=2;23;24;25;26");;
All) url="$url";;
Movies) url="${url}&category=17;44;45;47;50;51;52;42;46;54";;
"TV Shows") url="${url}&category=2;18;41;49";;
Games) url="${url}&category=2;27;28;29;30;31;53";;
Music) url="${url}&category=2;23;24;25;26";;
esac
response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}" )
while [ "$response" = "" ]; do
response=$(curl -sLH "User-agent: 'your bot 0.1'" "${url}" )
notify-send "RARGB" "Waiting 5 second for api limit to reset"
sleep 5
done
[ "$response" = "" ] && notify-send "RARBG" "Wait for 3 seconds for api to work." && exit 1
[ "$response" = '{"error":"No results found","error_code":20}' ] && notify-send "RARBG" "No results found" && exit 1
# echo "$response" | jq '.'
# exit 1
titles=$(printf '%s\n' "$response" | jq -r '.[] | .[].title')
seeders=$(printf '%s\n' "$response" | jq -r '.[] | .[].seeders')