Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # *************
- # transmission-remote-queue version 0.2
- # Contact sam.day (at) gmail.com with suggestions, corrections, etc.
- # Based on wereHampster's script from http://pastie.org/357236
- # Modified by super-poussin
- # *************
- # Variables
- #
- # Path to transmission-remote
- REMOTE="/usr/local/bin/transmission-remote"
- # Maximum number of active torrents (downloading + seeding)
- MAXACTIVE="3"
- # Maximum number of downloading torrents
- MAXDOWNLOADING="2"
- # Download ratio at which to stop seeding
- DESIREDRATIO="1.3"
- # Options to be passed to transmission-remote
- TRANSOPT=" localhost:8181 -n admin:password1"
- # Turn on/off adding extra slots if bandwidth to spare. Boolean.
- # Recommend disabling if using 'turtle mode'
- MODSLOTS=0
- # Extra download slot added if download speed is below this value and MODSLOT=1
- DOWNLOADLIMIT="700.0"
- # If MAXFIRST = 1 seed torrents with Highest ratio First
- MAXFIRST=1
- # *************
- # Add extra download slot if required
- if [ $MODSLOTS -eq 1 ]; then
- DOWNLOADSPEED="$($REMOTE -l | tail -n -1 | sed 's/^\s\+//g' | sed 's/\s\{2,\}/~/g' | cut -d '~' -f4)"
- if expr $DOWNLOADSPEED \<= $DOWNLOADLIMIT > /dev/null; then
- MAXDOWNLOADING=$(($MAXDOWNLOADING+1))
- fi
- if [ $MAXDOWNLOADING -gt $MAXACTIVE ]; then
- MAXACTIVE=$MAXDOWNLOADING
- fi
- # debugging output (3 lines)
- echo "Current download speed: $DOWNLOADSPEED KB/s"
- echo "Lower threshold before adding a slot: $DOWNLOADLIMIT KB/s"
- echo "Download slots: $MAXDOWNLOADING"
- fi
- # Stop torrents upper desired ratio
- #LIST="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep 100% |grep Seeding | awk '{ print $1; }')"
- #for ID in $LIST; do
- # RATIO="$($REMOTE $TRANSOPT -t $ID -i | grep Ratio | awk '{ print $2; }')"
- # if expr $RATIO \>= $DESIREDRATIO > /dev/null; then
- # NAME="$($REMOTE $TRANSOPT --torrent $ID --info | grep Name:)"
- # echo "Stop Torrent: $ID - ${NAME#*Name: } (Ratio $RATIO)"
- # $REMOTE $TRANSOPT --torrent $ID --stop > /dev/null
- # fi
- #done
- # Start downloading new torrents if download slots exist
- DOWNLOADING="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep -v Stopped | grep -v 100% | wc -l)"
- if [ $DOWNLOADING -lt $MAXDOWNLOADING ]; then
- LIST="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep -v 100% | grep Stopped | head -n $(expr $MAXDOWNLOADING - $DOWNLOADING) | awk '{ print $1; }')"
- for ID in $LIST; do
- NAME="$($REMOTE $TRANSOPT --torrent $ID --info | grep Name:)"
- echo "Downloading Torrent: $ID - ${NAME#*Name: }"
- $REMOTE $TRANSOPT --torrent $ID --start --verify > /dev/null
- done
- fi
- # Seed torrents below desired ratio if slots exist
- ACTIVE="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep -v Stopped | wc -l)"
- if [ $ACTIVE -lt $MAXACTIVE ]; then
- LIST="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep 100% | tail -n $(expr $MAXACTIVE - $ACTIVE) | awk '{ print $1; }'| awk -F "*" '{ print $1}')"
- RAT="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep 100% | tail -n $(expr $MAXACTIVE - $ACTIVE) | sed 's/^\s\+//g' | sed 's/\s\{2,\}/~/g' | cut -d '~' -f7)"
- if [ $MAXFIRST -eq 1 ]; then
- RAT2=$(echo $RAT | sed 's/ /\n/g' | sort -u -r)
- fi
- if [ $MAXFIRST -eq 0 ]; then
- RAT2=$(echo $RAT | sed 's/ /\n/g' | sort -u)
- fi
- for LOWEST in $RAT2; do
- for ID in $LIST; do
- RATIO="$($REMOTE $TRANSOPT -t $ID -i | grep Ratio: | awk '{ print $2; }')"
- if expr $RATIO \= $LOWEST > /dev/null; then
- NAME="$($REMOTE $TRANSOPT --torrent $ID --info | grep Name:)"
- echo "Seeding Torrent: $ID - ${NAME#*Name: } (Ratio $RATIO)"
- $REMOTE $TRANSOPT --torrent $ID --start --verify > /dev/null
- break
- fi
- done
- done
- fi
- # List Active Torrents
- LIST="$($REMOTE $TRANSOPT -l | tail -n +2 | head -n -1 | grep -v Stopped | awk '{ print $1; }'| awk -F "*" '{ print $1}')"
- for ID in $LIST; do
- NAME="$($REMOTE $TRANSOPT --torrent $ID --info | grep Name:)"
- echo "Active: $ID - ${NAME#*Name: }"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement