forked from ultimate-pms/ultimate-media-server-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb_remove-completed-downloads.sh
executable file
·75 lines (51 loc) · 3.11 KB
/
qb_remove-completed-downloads.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# qBitTorrent script to automatically remove any completed downloads from matching category (tv|movies) after X hours.
# (The idea behind this is to allow Radarr/Sonar to copy & rename files, then this script will come and remove them after X hours so they still have time to seed.)
#
# Author: DN
# https://github.com/ultimate-pms/ultimate-plex-setup
#
#########################################################################################################
QBITTORRENT_HOSTNAME="localhost:8080"
QBITTORRENT_USERNAME=""
QBITTORRENT_PASSWORD=""
MOVIE_CATAGORY="movies"
TV_CATAGORY="tv"
REMOVE_AFTER_X_HOURS=720 # Suggest at least 24 hours, so that you maintain a reasonable seed ratio... Defaults to 1 month.
#########################################################################################################
#
## MOVIE TORRENTS
# ------------------------------------------------------------------------------------------------------------
COMPLETED_MOVIES=`curl -s "http://$QBITTORRENT_USERNAME:$QBITTORRENT_PASSWORD@$QBITTORRENT_HOSTNAME/query/torrents?filter=completed&category=$MOVIE_CATAGORY"`
# Radarr client copies the movies, but does not remove the torrent file or the movie file, instead it creates a hardlink so the file can continue to seed...
# Find any torrents older than X hours (after they have been copied over to the NAS volumes), go ahead and remove the torrents and files (in this case symlinks, your copied files will not be removed)...
echo $COMPLETED_MOVIES | jq -r '.[] | [.save_path + .name, .hash, .completion_on|tostring] | @tsv' |
while IFS=$'\t' read -r item hash completion_on; do
COMPLETED_DATE=`date -d @$completion_on "+%Y-%m-%d %H:%M:%S"`
CURRENT_DATE=`date "+%Y-%m-%d %H:%M:%S"`
HOURS_OLD=`echo $(( ( $(date -ud "$CURRENT_DATE" +'%s') - $(date -ud "$COMPLETED_DATE" +'%s') )/60/60 ))`
if (( $HOURS_OLD > $REMOVE_AFTER_X_HOURS )); then
echo "Removing: [$item]"
# Remove from torrent client...
curl -s -d "hashes=$hash" -X POST "http://$QBITTORRENT_USERNAME:$QBITTORRENT_PASSWORD@$QBITTORRENT_HOSTNAME/command/delete"
# Remove seed files...
rm -rf $item
fi
done
## TV TORRENTS
# ------------------------------------------------------------------------------------------------------------
COMPLETED_TV_SERIES=`curl -s "http://$QBITTORRENT_USERNAME:$QBITTORRENT_PASSWORD@$QBITTORRENT_HOSTNAME/query/torrents?filter=completed&category=$TV_CATAGORY"`
echo $COMPLETED_TV_SERIES | jq -r '.[] | [.save_path + .name, .hash, .completion_on|tostring] | @tsv' |
while IFS=$'\t' read -r item hash completion_on; do
COMPLETED_DATE=`date -d @$completion_on "+%Y-%m-%d %H:%M:%S"`
CURRENT_DATE=`date "+%Y-%m-%d %H:%M:%S"`
HOURS_OLD=`echo $(( ( $(date -ud "$CURRENT_DATE" +'%s') - $(date -ud "$COMPLETED_DATE" +'%s') )/60/60 ))`
if (( $HOURS_OLD > $REMOVE_AFTER_X_HOURS )); then
echo "Removing: [$item]"
# Remove from torrent client...
curl -s -d "hashes=$hash" -X POST "http://$QBITTORRENT_USERNAME:$QBITTORRENT_PASSWORD@$QBITTORRENT_HOSTNAME/command/delete"
# Remove seed files...
rm -rf $item
fi
done