#!/bin/sh #this script uses the piratesbay api to search for torrents cal_size() { printf "%.03f\n" "$(($1 / 1000))e-6" } display() { for i in $(seq "$(printf "%s\nlol" "$2" | wc -l)"); do printf "[%s GB;S:%s\n" "$(cal_size "$(printf "%s" "$1" | sed -n "${i}p")")" "$(printf "%s" "$2" | sed -n "${i}p")" & done wait } os="linux" uname -o | grep -q "ndroid" && os="droid" # shellcheck disable=SC1091,SC1090 . "$(dirname "$0")"/.functions [ -z "$*" ] && search_$os "Search Torrent: " || query=$* [ -z "$query" ] && exit 0 [ "$os" = "linux" ] && tmp=$(notify-send -e "Searching query" -p) query=$(printf "%s" "$query" | tr " " "+") data=$(curl -s "https://apibay.org/q.php?q=$query" | sed 's/},/}\n/g' | tr -d "[]") [ "$os" = "linux" ] && notify-send -e "tidying up data" -r "$tmp" size=$(printf "%s" "$data" | sed -nE 's/.*name.*size":"(.*)",.*user.*/\1/p') name_seed=$(printf "%s" "$data" | sed -nE 's/.*name":"(.*)","info_hash.*seeders":"(.*)",.*num.*/\2] \1/p') sel=$(display "$size" "$name_seed" | menu_$os "Select Torrent: " | cut -d" " -f3-) [ -z "$sel" ] && exit 0 magnet="magnet:?xt=urn:btih:$(printf "%s" "$data" | sed -nE 's/.*name":"(.*)","info_hash":"(.*)",.*leech.*/\2\t\1/p' | sed -n "s/\t$sel//p")" torrent_$os "$magnet"