Page 1 of 2
How to see time it took to download a torrent?
Posted: Tue Jun 28, 2011 8:43 pm
by colbert
I see Active Time and Seeding Time, and the math is simple enough of course, but I have an automated script to send me an email when torrent is complete, and I'm wondering how I can add in the email a little blurb with the time it took to complete the torrent download?
This is the email script I am using:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
Re: How to see time it took to download a torrent?
Posted: Tue Jun 28, 2011 10:46 pm
by CSB
Code: Select all
#!/usr/bin/python
import sys
from datetime import datetime, date, time
from deluge.ui.client import client
from twisted.internet import reactor
d = client.connect()
def on_connect_success(result):
def on_get_torrent_value(torrent):
print str(datetime.fromtimestamp(torrent["active_time"]) - datetime.fromtimestamp(0))
client.disconnect()
reactor.stop()
client.core.get_torrent_status(sys.argv[1], ["active_time"]).addCallback(on_get_torrent_value)
d.addCallback(on_connect_success)
def on_connect_fail(result):
pass
d.addErrback(on_connect_fail)
reactor.run()
The python script above will return the active time of a torrentid. Call it from your bash script. Since you're calling that bash script as soon as you finish, the seeding time is zero, and the active time is all downloading, no math is needed involving the seeding time.
Re: How to see time it took to download a torrent?
Posted: Wed Jun 29, 2011 2:49 am
by colbert
Thanks! How should I call it from my script?
Re: How to see time it took to download a torrent?
Posted: Wed Jun 29, 2011 6:58 am
by CSB
colbert wrote:Thanks! How should I call it from my script?
Just pass it $1 and it will return a string.
Re: How to see time it took to download a torrent?
Posted: Wed Jun 29, 2011 8:21 pm
by colbert
CSB wrote:colbert wrote:Thanks! How should I call it from my script?
Just pass it $1 and it will return a string.
Sorry mate I'm pretty bad with bash lol, my script is:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
So I reckon I add:
in there? But how do I reference this separate script? If I'm explaining badly what I mean is I want, in the email from this script, to include the time of downloading as per your script. I'm just confused how exactly I combine both. Thanks a lot for your help

Re: How to see time it took to download a torrent?
Posted: Wed Jun 29, 2011 9:39 pm
by CSB
No.
Save that text as a torrentTimeDelta.py file, chmod +x it, and put it in your PATH.
In your script add
Code: Select all
torrenttimedelta=`python torrentTimeDelta.py $1`
Then, you can use $torrenttimedelta where you want the time.
Re: How to see time it took to download a torrent?
Posted: Thu Jun 30, 2011 12:05 am
by colbert
Okay this is what I have put:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
torrenttimedelta=`python /home/bobby/scripts/deluge/torrentTimeDelta.py $1`
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath and took $torrenttimedelta to complete :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
echo ---------------------------------------- >> ~/logs/scripts.log
However, where the time should be I'm getting an empty space so it just says "and took to complete

".
Re: How to see time it took to download a torrent?
Posted: Thu Jun 30, 2011 12:50 am
by CSB
Get a torrentid, and try calling the script manually.
The following will print all torrent ids.
Code: Select all
#!/usr/bin/python
from deluge.ui.client import client
from twisted.internet import reactor
d = client.connect()
def on_connect_success(result):
print "Connection was successful!"
def on_get_torrent_value(value):
for torrent in value:
print "%s: %s" % (torrent, value[torrent]["name"])
client.disconnect()
reactor.stop()
client.core.get_torrents_status({}, ["name"]).addCallback(on_get_torrent_value)
d.addCallback(on_connect_success)
def on_connect_fail(result):
print "Connection failed!"
print "result:", result
d.addErrback(on_connect_fail)
reactor.run()
Re: How to see time it took to download a torrent?
Posted: Thu Jun 30, 2011 1:30 am
by colbert
Ok I used that as torrentID.py and did:
Code: Select all
python2 torrentTimeDelta.py 363e9064f2af41f63e16779dc9dccf4b9cf0542d
2:48:16
So it works, but only manually?
Re: How to see time it took to download a torrent?
Posted: Thu Jun 30, 2011 1:45 am
by CSB
Try calling the python script from the bash script using the same binary you did there.