diff options
Diffstat (limited to 'share/tsh/nyaa.sh')
-rwxr-xr-x | share/tsh/nyaa.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/share/tsh/nyaa.sh b/share/tsh/nyaa.sh new file mode 100755 index 0000000..259dabd --- /dev/null +++ b/share/tsh/nyaa.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# shellcheck disable=SC2154 +# (we expect the variables to be set) + +# $1`: line number used to get link +get_magnet() { sed -n "${1}p" "$links"; } + +get_torrents() { + base_url="https://nyaa.si" + page="/?q=$query&p=1" + i=0 + while true; do + i=$((i + 1)) + page="$(curl -s "$base_url$page" | tee -a "$html" | pup -p 'li.next a attr{href}')" + if [ -z "$page" ]; then + printf '%s.\n' "$i" + break + else + >&2 printf '%s ' "$i" + fi + done + # No results + [ "$i" -eq 0 ] && return 1 + + pup -f "$html" -p 'table.torrent-list tr td:nth-child(2) a:last-child attr{title}' >"$names" + pup -f "$html" -p 'table.torrent-list tr td:nth-child(3) a:last-child attr{href}' >"$links" + pup -f "$html" -p 'table.torrent-list tr td:nth-child(4) text{}' | tr -d ' ' >"$sizes" + pup -f "$html" -p 'table.torrent-list tr td:nth-child(6) text{}' >"$seeds" + + paste "$sizes" "$seeds" "$names" >"$results" +} |