about summary refs log tree commit diff
path: root/bundles/bitfroest/files/qbapi
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/bitfroest/files/qbapi')
-rwxr-xr-xbundles/bitfroest/files/qbapi45
1 files changed, 45 insertions, 0 deletions
diff --git a/bundles/bitfroest/files/qbapi b/bundles/bitfroest/files/qbapi
new file mode 100755
index 0000000..89d328e
--- /dev/null
+++ b/bundles/bitfroest/files/qbapi
@@ -0,0 +1,45 @@
+#!/bin/sh
+set -eu
+
+qb_host=https://porphyrion.feralhosting.com/kum4/qbittorrent
+qb_user=kum4
+qb_pass=${repo.vault.cmd("rbw get 6e66abae-094c-4c98-83ad-9b7bae3eb1b2")}
+qb_cookiejar=/dev/shm/qb.cookies
+
+do_login() {
+	curl -sS -o /dev/null \
+		-H "Referer: $qb_host" \
+		-d "username=$qb_user&password=$qb_pass" \
+		-c "$qb_cookiejar" \
+		"$qb_host/api/v2/auth/login"
+}
+
+do_getnew() {
+	curl -sS -b "$qb_cookiejar" \
+		"$qb_host/api/v2/torrents/info?filter=completed&sort=added_on&tag=" |
+		jq -rc '.[]|[.name,.content_path]|@tsv'
+}
+
+do_markx() {
+	local name=$1
+	local hash
+
+	hash=$(curl -sS -b "$qb_cookiejar" \
+		"$qb_host/api/v2/torrents/info?filter=completed&sort=added_on&tag=" |
+		jq -rc --arg filter "$name" '.[]|select(.name==$filter)|.hash')
+
+	curl -sS -b "$qb_cookiejar" \
+		-d "hashes=$hash&tags=x" \
+		"$qb_host/api/v2/torrents/addTags"
+}
+
+main() {
+	test -f "$qb_cookiejar" || do_login
+
+	case "$1" in
+	getnew) do_getnew ;;
+	markx) do_markx "$2" ;;
+	esac
+}
+
+main "$@"