summaryrefslogtreecommitdiff
path: root/share/tsh/nyaa.sh
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-07-11 20:42:56 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-07-11 20:42:56 +0200
commit2144e991b0334aac9def384e0430be20889f1b73 (patch)
treee24494dad6098a40c01532dfc59f865d7afe059b /share/tsh/nyaa.sh
parent18d5762e0d89af0aff03945c691cbd16fd231ee1 (diff)
checkpoint
Diffstat (limited to 'share/tsh/nyaa.sh')
-rwxr-xr-xshare/tsh/nyaa.sh32
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"
+}