about summary refs log tree commit diff
path: root/bundles/bitfroest/files/qbapi
blob: 89d328e8c3f00bbfaae4a21dc21f1ab514150e46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 "$@"