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

55 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-03-14 22:11:43 +01:00
#!/usr/bin/env bash
2022-01-03 02:45:31 +01:00
mkdir -p "${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
temp="${XDG_CACHE_HOME:-'$HOME/.cache'}/nyaa"
dir=${NYAA_DIR:-"$HOME/Downloads"}
2022-03-14 22:11:43 +01:00
url="https://nyaa.si"
2022-01-03 02:45:31 +01:00
trap "rm -rf $temp" SIGINT SIGTERM ERR EXIT
while getopts axd:q: flag; do
2022-01-03 02:45:31 +01:00
case "${flag}" in
x) url="https://sukebei.nyaa.si";;
d) dir=${OPTARG};;
q) query=${OPTARG};;
2022-01-03 02:45:31 +01:00
esac
done
if [ -z "$query" ]; then
query=$(pmenu -p "Search Torrent: ")
if [ -z "$query" ]; then
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
grep -o '<a href="/view/.*</a>' $temp/html | sed 's/<[^>]*>//g' > $temp/titles
results=$(wc -l $temp/titles | cut -d " " -f 1)
if [ $results -lt 1 ]; then
echo No results
exit 0
fi
grep -Po 'magnet:\?xt=urn:btih:[^"]*' $temp/html > $temp/magnets
magnet=$(paste $temp/titles $temp/magnets | pmenu | cut -f 2)
if [ -z "$magnet" ]; then
echo Nothing selected
exit 0
fi
mkdir -p $dir
if command -v webtorrent 2> /dev/null
then
webtorrent "$magnet" -o $dir
else
2022-03-14 22:11:43 +01:00
aria2c "$magnet" -d $dir
fi
2022-01-03 02:45:31 +01:00
echo Enjoy watching!