#!/bin/sh [ -n "$DEBUG" ] && set -x set -eu qb_host=https://poseidon.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,(if .root_path != "" then .root_path else .content_path end)]|@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() { rm -f "$qb_cookiejar" && do_login case "$1" in getnew) do_getnew ;; markx) do_markx "$2" ;; esac } main "$@"