This repository has been archived on 2024-08-03. You can view files and clone it, but cannot push or open issues or pull requests.
nyaa/nyaa

85 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/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"
download=0
dir=${NYAA_DIR:-"."}
2022-03-14 22:11:43 +01:00
url="https://nyaa.si"
extra_flags="-i"
2022-01-03 02:45:31 +01:00
trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT
# 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
query=${ARGS[*]}
if test -z "$query";
then
2022-01-03 02:45:31 +01:00
query=$(pmenu -p "Search Torrent: ")
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
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
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
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
if test -z "$magnet"; then
2022-01-03 02:45:31 +01:00
echo Nothing selected
exit 0
fi
if test $download -eq 1;
then
mkdir -p $dir
aria2c "$magnet" -d $dir;
else
webtorrent "$extra_flags" --not-on-top --player-args="$NYAA_PLAYER_ARGS" --mpv "$magnet";
fi