#!/bin/sh convert_sizes () { printf '%s\n' "$@" | \ while read size; do numfmt --to iec --format "%.2f" $size done } list() { num=1 printf '%s\n' "$1" | \ while read line in; do category=$(printf '%s' "$2" | sed -n "${num}p") seeder=$(printf '%s' "$3" | sed -n "${num}p") leecher=$(printf '%s' "$4" | sed -n "${num}p") size=$(printf '%s' "$5" | sed -n "${num}p") printf '%s\n' "$num - $line | $category | $seeder | $leecher | $size" num=$(($num + 1)) done | column -t -s '|' | dmenu -i -l 15 | awk '{print $1}' } 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=dmenu-rarbg" | jq -r '.token') 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}" else url="${base_url}mode=search&search_string=${query}$&sort=seeders${default_args}" fi case "$(printf "All\\nMovies\\nTV Shows\\nGames\\nMusic" | dmenu -i -p "Choose category: ")" in 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 titles=$(printf '%s\n' "$response" | jq -r '.[] | .[].title') seeders=$(printf '%s\n' "$response" | jq -r '.[] | .[].seeders') leechers=$(printf '%s\n' "$response" | jq -r '.[] | .[].leechers') sizes=$(convert_sizes "$(printf '%s\n' "$response" | jq -r '.[] | .[].size')") magnets=$(printf '%s\n' "$response" | jq -r '.[] | .[].download') categorys=$(printf '%s\n' "$response" | jq -r '.[] | .[].category') number=$(list "$titles" "$categorys" "$seeders" "$leechers" "$sizes") [ "$number" = "" ] && exit link=$(printf '%s\n' "$magnets" | sed -n "${number}p") transmission-remote -a "$link" && notify-send "RARBG" "Downloading selected torrent."