Seed Until

Feature requests not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
exiztone

Seed Until

Post by exiztone »

-
Last edited by exiztone on Wed Jul 24, 2013 5:55 pm, edited 1 time in total.
Rolcol
Posts: 337
Joined: Sun Aug 10, 2008 8:00 am

Re: Seed Until

Post by Rolcol »

There's already a ticket for this:
http://trac.transmissionbt.com/ticket/671
exiztone

Re: Seed Until

Post by exiztone »

-
Last edited by exiztone on Wed Jul 24, 2013 5:55 pm, edited 1 time in total.
ronv
Posts: 13
Joined: Sun Mar 16, 2008 3:10 am

Re: Seed Until

Post by ronv »

I wrote my own cron scrip to use the transmission-remote and check on the hour for a preset ratio....I suggest that it can be posted in the wiki but here is the script and the awk code. Make sure the 'workdir' variable points to the directory where your awk code is located.

Script:

Code: Select all

#!/bin/bash
#
# Written by: RonV
#
# Stops transmission torrengs when their share ratio is over set %
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin
NAME="torrent_stop.sh"
DESC="Stop Transmission Torrents"
EXE=/usr/local/bin/transmission-remote
TMPDIR=/tmp
TMPFILE=torrents.txt
WORKDIR=/util
RATIO=8.0


cd ${WORKDIR}

# AWK torrent file
${EXE} --list | awk -f ./torrent_stop.awk | xargs -n 1 -I '{}' ${EXE} -t'{}' -S
Awk:

Code: Select all

# torrent_stop.awk
#
# used to filter transmission remove list torrent command
# and only provide torrents that are over criteria
#
# $1 - Torrent Number
# $2 - Done %
# $3 - ETA (Literal "Done" means that a full copy is on server)
# $6 - Ratio of download vs. share check for 8.0 for 8 times

BEGIN {
        ratio=8.0
        count=0

}

# All matches

#{print $1, $2, $3, $4, $5, $6}

(($3=="Done")&&($6 > ratio)&& ($6 != "Inf")) {
        count++;
        torrentarray[count]=$1;
}

END {
        for (x in torrentarray) {
                print torrentarray[x];
        }
}
avberk
Posts: 29
Joined: Fri Jun 01, 2007 7:48 am

Re: Seed Until

Post by avberk »

Hi Ronv,

I am trying to implement your scripts on my asus wl500gp.
No errors, so i assume the script will do its job :)

Two questions about setting the seed ratio:

1) Can you explain this line from thw awk code?

# $6 - Ratio of download vs. share check for 8.0 for 8 times

2) If i want to set the ratio to 2, do i set it in both files? (i guess i change both instances of 8.0 to 2.0)?
rb07
Posts: 1400
Joined: Sun Aug 24, 2008 3:14 am

Re: Seed Until

Post by rb07 »

You can also look at my script http://forum.transmissionbt.com/viewtop ... f=7&t=4244 (the second one, which is an improvement which uses up to 2 decimals), it is easier to configure.
avberk
Posts: 29
Joined: Fri Jun 01, 2007 7:48 am

Re: Seed Until

Post by avberk »

I am using your first script, because:

-Transmission-remote -l shows a ratio of 2 decimals with me. (i guess because i am using one of the latest nightlies of transmission ;-))
-I don't see use for exceptions
-I don't need to install bash
-The script looks simpler ;-)

Thanks a lot for this solution!!
rb07
Posts: 1400
Joined: Sun Aug 24, 2008 3:14 am

Re: Seed Until

Post by rb07 »

avberk wrote:I am using your first script, because:

-Transmission-remote -l shows a ratio of 2 decimals with me. (i guess because i am using one of the latest nightlies of transmission ;-))
You're right! using 1.50b1 does show 2 decimals while listing; I'll simplify my script.

Thanks for the "heads up".
buggsy2
Posts: 7
Joined: Tue Jan 13, 2009 2:54 pm

Re: Seed Until

Post by buggsy2 »

T 1.42 on an NSLU2 Unslung.

Problem with keying on T's Ratio is that T uses Ratio=Uploaded/Downloaded, which doesn't work well for torrents that were added to T already 100% downloaded. Ratio is reported as Inf and the script stops the torrent.

So below is the previous bash script and awk program modified to recalculate Ratio=Uploaded/Have. Later I'll simplify a few things.

Code: Select all

#!/bin/bash

TR_R=/opt/bin/transmission-remote
PORT=9091
USER=user-name
PASS=password
RATIO=1.7
declare -a EXCEPTIONS=( )

for i in `$TR_R $PORT -l -n $USER:$PASS | \
  awk '$3 ~ "Done" && $6 >= R && $7 !~ "Stopped" { print $1 }' R=$RATIO`
do
  skip=0
  for j in ${EXCEPTIONS[@]}
  do
    if [ $j -eq $i ]; then
      skip=1
    fi
  done
  if [ $skip -eq 0 ]; then
    $TR_R $PORT -n $USER:$PASS -t $i -i | gawk -f tr_check_ratio.awk R=$RATIO &&
    $TR_R $PORT -n $USER:$PASS -t $i -S
  fi
done
tr_check_ratio.awk:

Code: Select all

# input is a detailed list from transmission,
# calculate correct upload/download ratio for each torrent

sub(/None/,"0")
/Name:/ { split($0, a, ":")}
/Have:/ {
    have=$2; scale=substr($3,1,1); have_scl=scalefn(have,scale)
}
/Uploaded:/ {
    upl=$2; scale=substr($3,1,1); upl_scl=scalefn(upl,scale)
    ratio=have_scl>0 ? upl_scl/have_scl : 0.0 # should be Inf, but Have==0 implies need to dl/ul a while
    if (ratio >= R) { print "Stopping: ", a[2]; exit 0; }    else exit 1;
}

function scalefn(value,scale)
{
# given a numeric VALUE, and a metric SCALE code (K, M, G, etc),
# return value * scale
    if (value !~ /^[0-9.-]+$/) {return -1}
    if (scale=="K")
	return value*1e3
    if (scale=="M")
	return value*1e6
    if (scale=="G")
	return value*1e9
    return -2
}
exiztone

Re: Seed Until

Post by exiztone »

-
Last edited by exiztone on Wed Jul 24, 2013 5:55 pm, edited 1 time in total.
buggsy2
Posts: 7
Joined: Tue Jan 13, 2009 2:54 pm

Re: Seed Until

Post by buggsy2 »

A simplified version that is entirely within awk. So your crontab line should be something like

0,30 * * * * /bin/awk -f /scripts/tr_check_ratio.awk

Also this doesn't have the exceptions feature, which would be easy to add.

Yeah, would be nice if this were part of transmission itself.

Code: Select all

#!/bin/gawk
# calculate correct upload/download ratio for each torrent
BEGIN {
    TR_R="/bin/transmission-remote"
    PORT=9091
    MAXRATIO=1.7
    tmpfile="/tmp/junk_TR_R"
# generate detailed list, process through awk
    system(TR_R" "PORT" -tall -i > "tmpfile)
    while ((getline < tmpfile ) > 0) {
	sub(/None/,"0")
	if ($0 ~ /Id:/) {torid=$2}
	if ($0 ~ /State:/) {state=$2}
	if ($0 ~ /Name:/) {split($0, a, ":");name=a[2]}
	if ($0 ~ /Have:/) {have=$2; scale=substr($3,1,1); have_scl=scalefn(have,scale)}
	if ($0 ~ /Uploaded:/) {
	    if (state=="Stopped") # skip stopped torrents
		continue
	    upl=$2; scale=substr($3,1,1); upl_scl=scalefn(upl,scale)
	    ratio=have_scl>0 ? upl_scl/have_scl : 0.0 # should be Inf, but Have==0 implies need to dl/ul a while
#print torid, name, state, ratio
	    if (ratio >= MAXRATIO) {
		print "Stopping: ", name
		system(TR_R" "PORT" -t"torid" -S") # torrent's true ratio exceeds, stop it
	    }
	}
    }
}
function scalefn(value,scale)
{
# given a numeric VALUE, and a metric SCALE code (K, M, G, etc),
# return value * scale
    if (value !~ /^[0-9.-]+$/) {return -1}
    if (scale=="K")
	return value*1e3
    if (scale=="M")
	return value*1e6
    if (scale=="G")
	return value*1e9
    return -2
}
nightstand
Posts: 2
Joined: Wed Nov 25, 2009 4:28 pm

Re: Seed Until

Post by nightstand »

I would like to see a date of last seed, so I can see if a torrent hasn't been used by anybody for, say a month or so, so I can take it down.
livings124
Transmission Developer
Posts: 3142
Joined: Fri Jan 13, 2006 8:08 pm

Re: Seed Until

Post by livings124 »

There is a last activity date field.
nightstand
Posts: 2
Joined: Wed Nov 25, 2009 4:28 pm

Re: Seed Until

Post by nightstand »

thanks, livings124, didn't know it was there.
Post Reply