Last active
July 29, 2023 17:26
-
-
Save kantjer01/fe17201f4dca3ad79e14753fb10cef9f to your computer and use it in GitHub Desktop.
upgraderr-max_torrents.sh
This file contains 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 | |
# This script removes the oldest movies and series torrents from qbit to keep the number of torrents per instance below a set number. | |
# Only a set maximum number a torrents will be deleted in each run. | |
# load variables | |
set -o allexport | |
source /volume1/scripts/upgraderr/upgraderr.env | |
set +o allexport | |
# set variables | |
log="$log_dir/max_torrents.$(date +"%Y-%m-%d_%H.%M").log" | |
m_max="5500" # maximun movies torrents in qbit instance | |
m_del="75" # maximum movies torrents to delete in a run | |
s_max="5500" # maximun series torrents in qbit instance | |
s_del="100" # maximum series torrents to delete in a run | |
# Get total number of movies torrents tagged 'keep'and 'BeyondHD' | |
echo "Get total number of movies torrents tagged 'keep'and 'BeyondHD'..." | tee $log | |
movies_keep=$log_dir/movies_keep.txt | |
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA > $movies_keep | |
{"host":"${host_movies_local}", | |
"user":"${user_local}", | |
"password":"${password_local}", | |
"action":"test", | |
"query":"DisableCrossseed() && (Tags contains 'BeyondHD' || Tags contains 'keep')"} | |
CURL_DATA | |
sed -i 's/[^0-9]*//g' $movies_keep | |
sleep 0.5s | |
m_keep=$(<$movies_keep) | |
echo "Total movies torrents tagged 'keep'and 'BeyondHD' = $m_keep" | tee -a $log | |
echo | tee -a $log | |
movies_max=$(($m_max - $m_keep)) | |
echo "Total torrents max movies torrent calculation = $movies_max" | tee -a $log | |
# Delete movies torrents above set maxaimum. | |
echo "If total movie torrents is more then $m_max: delete max $m_del movies torrents" | tee -a $log | |
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA | tee -a $log | |
{"host":"${host_movies_local}", | |
"user":"${user_local}", | |
"password":"${password_local}", | |
"action":"delete", | |
"query":"DisableCrossseed() && ResultSkip($movies_max) && ResultLimit($m_del) && Tags not contains 'keep' && Tags not contains 'BeyondHD' && Category contains 'movies-lts'", | |
"sort":"-CompletionOn"} | |
CURL_DATA | |
# Get total number of series torrents tagged 'keep'and 'BeyondHD' | |
echo "Get total number of series torrents tagged 'keep'and 'BeyondHD'..." | tee -a $log | |
series_keep=$log_dir/series_keep.txt | |
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA > $series_keep | |
{"host":"${host_series_local}", | |
"user":"${user_local}", | |
"password":"${password_local}", | |
"action":"test", | |
"query":"DisableCrossseed() && (Tags contains 'BeyondHD' || Tags contains 'keep')"} | |
CURL_DATA | |
sed -i 's/[^0-9]*//g' $series_keep | |
sleep 0.5s | |
s_keep=$(<$series_keep) | |
echo "Total series torrents tagged 'keep'and 'BeyondHD' = $s_keep" | tee -a $log | |
echo | tee -a $log | |
series_max=$(( $s_max - $s_keep)) | |
echo "Total torrents for max series torrent calculation = $series_max" | tee -a $log | |
# Delete series torrents above set maxaimum. | |
echo "If total series torrents is more then $s_max: delete max $s_del series torrents" | tee -a $log | |
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA | tee -a $log | |
{"host":"${host_series_local}", | |
"user":"${user_local}", | |
"password":"${password_local}", | |
"action":"delete", | |
"query":"DisableCrossseed() && ResultSkip($series_max) && ResultLimit($s_del) && Tags not contains 'keep' && Tags not contains 'BeyondHD' && Category contains 'tv-lts'", | |
"sort":"-CompletionOn"} | |
CURL_DATA | |
# cleanup log files | |
if ls -t $log_dir/max_torrents.*.log &>/dev/null; then | |
ls -t $log_dir/max_torrents.*.log | tail -n +4 | xargs rm -f -- | |
fi | |
# Delete temp files | |
if [ -f $log_dir/movies_keep.txt ]; then | |
rm $log_dir/movies_keep.txt | |
fi | |
if [ -f $log_dir/series_keep.txt ]; then | |
rm $log_dir/series_keep.txt | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment