diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-07-11 21:48:56 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-07-11 21:48:56 +0200 |
commit | a857f247d9a71b88a4f0dbcfa95e3679e8456e70 (patch) | |
tree | 846ddcd8117be1505a970e3638fc65d0ec954a2e /share/tsh/nyaa.sh | |
parent | 75196520b3d6a0e60db1d03a64aaa0655cc4f202 (diff) | |
parent | 6251d6ba1054cd79387f0f88ce25d2f4bc8b78c4 (diff) |
Merge branch 'main' of debuc.com:dotfiles
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" +} |