Created
February 27, 2015 03:27
-
-
Save dalehamel/4b61ac93109b8bb14b99 to your computer and use it in GitHub Desktop.
Deluge curator script
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 | |
# A POSIX variable | |
OPTIND=1 # Reset in case getopts has been used previously in the shell. | |
# Initialize our own variables: | |
unreg=0 | |
error=0 | |
max_ratio=0 | |
target_tracker="" | |
days_ago=0 | |
while getopts "h?eur:t:d:" opt; do | |
case "$opt" in | |
h|\?) | |
show_help | |
exit 0 | |
;; | |
e) | |
echo "Will delete error torrents." | |
error=1 | |
;; | |
u) | |
echo "Will delete unregistered torrents." | |
unreg=1 | |
;; | |
r) | |
max_ratio=$OPTARG | |
echo "Will delete torrents with ratio greater than $max_ratio" | |
;; | |
t) | |
target_tracker=$OPTARG | |
echo "Will only delete torrents from $target_tracker" | |
;; | |
d) | |
days_ago=$OPTARG | |
echo "Will only delete torrents older than $days_ago days" | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "$1" = "--" ] && shift | |
echo "Fetching deluge torrent data..." | |
all_data=`deluge-console info` | |
echo "$all_data" >data | |
echo "Torrents by tracker": | |
echo "$all_data" | grep Tracker | awk '{print $3}' | sort | uniq -c | sed 's/://g' | |
ids=`echo "$all_data" | grep "ID:" | awk '{print $2}'` | |
for id in $ids; do | |
data=`deluge-console info $id` | |
name=`echo "$data" | grep "Name:" | awk '{print $2}'` | |
tracker=`echo "$data" | grep "Tracker" | awk '{print $3}' | sed 's/://g'` | |
seedtime=`echo "$data" | grep "Seed time:" | awk '{print $3":"$5}'` | |
echo "Checking $name" | |
if [ -n "$target_tracker" ];then | |
if [ "$target_tracker" != "$tracker" ];then | |
echo "$tracker is not $target_tracker, skipping" | |
continue; | |
fi | |
fi | |
if [ "$unreg" -eq 1 ];then | |
check=`echo "$data" | grep "Unregistered torrent"` | |
if [ -n $check ];then | |
echo "$name is unregistered" | |
fi | |
fi | |
if [ "$error" -eq 1 ];then | |
check=`echo "$data" | grep "Error"` | |
if [ -n $check ];then | |
echo "$name is an error torrent" | |
fi | |
fi | |
if [ "$days_ago" -gt 0 ];then | |
days=`echo $seedtime | cut -d : -f 1` | |
hours=`echo $seedtime | cut -d : -f 2` | |
minutes=`echo $seedtime | cut -d : -f 3` | |
seconds=`echo $seedtime | cut -d : -f 4` | |
min_date=`date --date="$days_ago days" +%s` | |
seed_stamp=`date --date="$days days $hours hours $minutes minutes $seconds seconds ago" +%s` | |
if [ $seed_stamp -ge $min_date ];then | |
echo "$name is $days old, older than $days_ago" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment