2022-07-12 02:40:59 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
save_dir=$NYAA_DIR
|
|
|
|
if test -f $XDG_CONFIG_HOME/nyaa/config || test -f $HOME/.config/nyaa/config;
|
|
|
|
then
|
|
|
|
source "${XDG_CONFIG_HOME:-'$HOME/.config'}/nyaa/config" 2> /dev/null; # source config
|
|
|
|
fi
|
|
|
|
NYAA_DIR=$save_dir
|
2022-01-03 02:45:31 +01:00
|
|
|
|
|
|
|
mkdir -p "${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
|
|
|
|
temp="${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
|
2022-07-12 02:40:59 +02:00
|
|
|
download=0
|
|
|
|
dir=${NYAA_DIR:-"."}
|
2022-03-14 22:11:43 +01:00
|
|
|
url="https://nyaa.si"
|
2022-07-12 02:40:59 +02:00
|
|
|
extra_flags="-i"
|
2022-01-03 02:45:31 +01:00
|
|
|
|
|
|
|
trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT
|
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
# https://gist.github.com/caruccio/836c2dda2bdfa5666c5f9b0230978f26
|
|
|
|
ARGS=()
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
while getopts xdp flag; do
|
|
|
|
case "${flag}" in
|
|
|
|
x) url="https://sukebei.nyaa.si";;
|
|
|
|
d) download=1;;
|
|
|
|
p) extra_flags="--playlist";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
[ $? -eq 0 ] || exit 1
|
|
|
|
[ $OPTIND -gt $# ] && break
|
|
|
|
|
|
|
|
shift $[$OPTIND - 1]
|
|
|
|
OPTIND=1
|
|
|
|
ARGS[${#ARGS[*]}]=$1
|
|
|
|
shift
|
2022-01-03 02:45:31 +01:00
|
|
|
done
|
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
query=${ARGS[*]}
|
|
|
|
|
|
|
|
if test -z "$query";
|
|
|
|
then
|
2022-01-03 02:45:31 +01:00
|
|
|
query=$(pmenu -p "Search Torrent: ")
|
2022-07-12 02:40:59 +02:00
|
|
|
if test -z "$query"; then
|
2022-01-03 02:45:31 +01:00
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
query="$(echo $query | sed 's/ /+/g')"
|
2022-03-14 22:11:43 +01:00
|
|
|
curl -s "$url/?s=seeders&q=$query" > $temp/html
|
2022-01-03 02:45:31 +01:00
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
cat $temp/html | tr -d '\n\t' \
|
|
|
|
| sed -E 's/<thead>.*?<\/thead>//g' \
|
|
|
|
| grep -oP "<tr.*?>(.*?)</tr>" \
|
|
|
|
| sed -E 's/<td[^>]*>/\t/g; s/<\/?i[^>]*>|<\/td>//g' \
|
|
|
|
| sed -E 's/<a href="[^"]*" class="comments"[^>]*>[^<]*<\/a>//g' \
|
|
|
|
| sed -E 's/<a href="[^"]*" title="([^"]*)">[^<]*<\/a>/\1/g' \
|
|
|
|
| sed -E 's/<a href="(magnet\:[^"]*)"><\/a>/\1/g' \
|
|
|
|
| sed -E 's/<\/?a[^>]*>|<\/tr>//g' \
|
|
|
|
| sed -E 's/<tr class="([a-z]*)">/\1/g' \
|
|
|
|
> $temp/data
|
|
|
|
|
2022-01-03 02:45:31 +01:00
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
results=$(wc -l $temp/data | cut -d " " -f 1)
|
|
|
|
if test $results -lt 1; then
|
2022-01-03 02:45:31 +01:00
|
|
|
echo No results
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
selected=$(cat $temp/data | awk -F '\t' '{printf "[S:%4s | L:%3s] %9s %s { %s } %s \n", $7, $8, $5, $3, $2, $4 }' | pmenu )
|
|
|
|
magnet=$(echo $selected | grep -o 'magnet:.\+')
|
2022-01-03 02:45:31 +01:00
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
if test -z "$magnet"; then
|
2022-01-03 02:45:31 +01:00
|
|
|
echo Nothing selected
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-07-12 02:40:59 +02:00
|
|
|
if test $download -eq 1;
|
2022-01-05 01:22:25 +01:00
|
|
|
then
|
2022-07-12 02:40:59 +02:00
|
|
|
mkdir -p $dir
|
|
|
|
aria2c "$magnet" -d $dir;
|
2022-01-05 01:22:25 +01:00
|
|
|
else
|
2022-07-12 02:40:59 +02:00
|
|
|
webtorrent "$extra_flags" --not-on-top --player-args="$NYAA_PLAYER_ARGS" --mpv "$magnet";
|
2022-01-05 01:22:25 +01:00
|
|
|
fi
|
|
|
|
|