Last active
March 30, 2023 14:26
-
-
Save fabricionaweb/89c184932443acb71fe34b7c88e85228 to your computer and use it in GitHub Desktop.
Pause/Resume qbittorrent bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# qbit settings | |
QBIT_API="http://qbittorrent.lan:8080/api/v2" | |
# tag to filter by, it will be removed on resume command | |
TAG="cache" | |
# days to filter in epoch time | |
# DAYS_OLD=$(date -d "-1 days" +%s) | |
# read value from ca.mover.tunning | |
CA_SETTINGS=$(cat /boot/config/plugins/ca.mover.tuning/ca.mover.tuning.cfg | awk -F '"' '/daysold/{print $2}') | |
DAYS_OLD=$(date -d "-$CA_SETTINGS days" +%s) | |
# $1 is the script argument | |
ACTION="$1" | |
if [[ "$ACTION" != "pause" && "$ACTION" != "resume" ]]; then | |
echo "Invalid argument, expected 'resume' or 'pause'" | |
exit 1 | |
fi | |
# decide which filter to use for perform search | |
# to PAUSE we filter for seeding | |
# to RESUME we filter for paused | |
if [[ "$ACTION" == "pause" ]]; then | |
FILTER="completed"; | |
else | |
FILTER="paused"; | |
fi | |
# get torrents id with status 'completed' and the tag | |
# somehow I can not filter by tags in api, so lets filter in jq | |
TORRENTS_HASH=$(curl -sS "$QBIT_API/torrents/info?filter=$FILTER" \ | |
| jq \ | |
--arg TAG "$TAG" \ | |
--argjson DAYS_OLD "$DAYS_OLD" \ | |
--raw-output \ | |
'.[] | select(.tags | contains($TAG)) | select(.completion_on < $DAYS_OLD) | .hash' \ | |
| tr '[:space:]' '|' | |
) | |
# pause or resume | |
curl -sSX POST "$QBIT_API/torrents/$ACTION" --data "hashes=$TORRENTS_HASH" | |
# if the action is resume we will assume the move have been done and can remove the tag | |
if [[ "$ACTION" == "resume" ]]; then | |
curl -sSX POST "$QBIT_API/torrents/removeTags" --data "hashes=$TORRENTS_HASH&tags=$TAG" | |
fi | |
# wait a little | |
sleep 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./pause-resume-qbit.sh pause
and./pause-resume-qbit.sh resume