download to dir, add webtorrent as default

This commit is contained in:
Nikola Kubiczek 2022-01-05 01:22:25 +01:00
parent 124e1f7328
commit 0b25e074e3
Signed by: yaemiku
GPG Key ID: ADC039636B3E4AAB

22
nyaa
View File

@ -3,14 +3,17 @@
mkdir -p "${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa" mkdir -p "${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
temp="${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa" temp="${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
url="https://nyaa.si" url="https://nyaa.si"
dir=${NYAA_DIR:-"$HOME/Downloads"}
filter=1
trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT
filter=2
while getopts q:ad flag; do while getopts axd:q: flag; do
case "${flag}" in case "${flag}" in
q) query=${OPTARG};;
a) filter=0;; a) filter=0;;
x) url="https://sukebei.nyaa.si";;
d) dir=${OPTARG};;
q) query=${OPTARG};;
esac esac
done done
@ -22,7 +25,7 @@ if [ -z "$query" ]; then
fi fi
query="$(echo $query | sed 's/ /+/g')" query="$(echo $query | sed 's/ /+/g')"
curl -s "$url/?f=$filter&q=$query" > $temp/html curl -s "$url/?s=seeders&f=$filter&q=$query" > $temp/html
grep -o '<a href="/view/.*</a>' $temp/html | sed 's/<[^>]*>//g' > $temp/titles grep -o '<a href="/view/.*</a>' $temp/html | sed 's/<[^>]*>//g' > $temp/titles
@ -40,7 +43,14 @@ if [ -z "$magnet" ]; then
exit 0 exit 0
fi fi
mkdir -p $HOME/Downloads mkdir -p $dir
aria2c "$magnet" --seed-time 0 -d $HOME/Downloads
if command -v webtorrent 2> /dev/null
then
webtorrent "$magnet" -o $dir
else
aria2c "$magnet" --seed-time 0 -d $dir
fi
echo Enjoy watching! echo Enjoy watching!