transmission-vise.py for Netgear ReadyNas 10400. run's by crontab every 2 hours
how it works:
stop torrent if ratio has been reached or seeders>MAXSEEDERS
start torrent if only my seeding
what's all this:
Netgear ReadyNas 10400 is slow, but most importantly - hot and noisy at his place, but most of all - if seeding more torrents, it can't share plex because low cpu one core speed.
note:
crontab must run script w/o dots
do like this in /etc/crontab:
/2 * * * * root /root/scripts/transmission-vice_py
#!/usr/bin/python
from os import popen
from sys import exit
import re
import logging
logging.basicConfig(filename='/root/scripts/transmission-vice.log', format='%(asctime)s - %(message)s', level=logging.INFO)
maxratio = 5
maxseeders = 3
unknowndata = 0
tarray = []
rawtorrents=popen('transmission-remote 8181 -l | egrep -v "ID|Sum"').read()
for torrent in rawtorrents.split("\n"):
if len(torrent)==0:
break
spltorrent=torrent.split()
torrentdict={'ID':spltorrent[0],'Done':spltorrent[1],'ETA':spltorrent[4],
'Ratio':spltorrent[7],'Status':spltorrent[8],'Name':' '.join(tuple(spltorrent)[9:])}
torrentstats=popen('transmission-remote 8181 -t'+torrentdict['ID']+' -it').read()
stat = re.findall(r"(\d+)\sseeders",torrentstats)
if len(stat)>0:
torrentdict['Seeders']=stat[0]
else:
torrentdict['Seeders']=unknowndata
stat = re.findall(r"(\d+)\sleechers",torrentstats)
if len(stat)>0:
torrentdict['Leechers']=stat[0]
else:
torrentdict['Leechers']=unknowndata
tarray.append(torrentdict)
for torrent in tarray:
print("Name:"+torrent["Name"]+" Status:"+torrent["Status"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"])+" ETA:"+str(torrent["ETA"]))
peers = popen('transmission-remote 8181 -t'+torrent["ID"]+' -ip' + ' | egrep -v "Address"')
peerasseeder = False
for peer in peers:
if int(float(peer.split()[2])) == 100:
peerasseeder = True
if int(torrent["Seeders"])<maxseeders and int(torrent["Leechers"])!=0 and not peerasseeder and float(torrent["Ratio"])<maxratio:
if torrent["Status"]=="Stopped":
result=popen('transmission-remote 8181 -t'+torrent["ID"]+' -s').read()
logging.info("start:"+torrent["Name"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"]))
elif (peerasseeder or int(torrent["Seeders"])>3) and torrent["ETA"]=="Done" and float(torrent["Ratio"])>maxratio:
if torrent["Status"]=="Idle" or torrent["Status"]=="Seeding":
result=popen('transmission-remote 8181 -t'+torrent["ID"]+' -S').read()
logging.info("stop:"+torrent["Name"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"]))
exit(0)
how it works:
stop torrent if ratio has been reached or seeders>MAXSEEDERS
start torrent if only my seeding
what's all this:
Netgear ReadyNas 10400 is slow, but most importantly - hot and noisy at his place, but most of all - if seeding more torrents, it can't share plex because low cpu one core speed.
note:
crontab must run script w/o dots
do like this in /etc/crontab:
/2 * * * * root /root/scripts/transmission-vice_py
#!/usr/bin/python
from os import popen
from sys import exit
import re
import logging
logging.basicConfig(filename='/root/scripts/transmission-vice.log', format='%(asctime)s - %(message)s', level=logging.INFO)
maxratio = 5
maxseeders = 3
unknowndata = 0
tarray = []
rawtorrents=popen('transmission-remote 8181 -l | egrep -v "ID|Sum"').read()
for torrent in rawtorrents.split("\n"):
if len(torrent)==0:
break
spltorrent=torrent.split()
torrentdict={'ID':spltorrent[0],'Done':spltorrent[1],'ETA':spltorrent[4],
'Ratio':spltorrent[7],'Status':spltorrent[8],'Name':' '.join(tuple(spltorrent)[9:])}
torrentstats=popen('transmission-remote 8181 -t'+torrentdict['ID']+' -it').read()
stat = re.findall(r"(\d+)\sseeders",torrentstats)
if len(stat)>0:
torrentdict['Seeders']=stat[0]
else:
torrentdict['Seeders']=unknowndata
stat = re.findall(r"(\d+)\sleechers",torrentstats)
if len(stat)>0:
torrentdict['Leechers']=stat[0]
else:
torrentdict['Leechers']=unknowndata
tarray.append(torrentdict)
for torrent in tarray:
print("Name:"+torrent["Name"]+" Status:"+torrent["Status"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"])+" ETA:"+str(torrent["ETA"]))
peers = popen('transmission-remote 8181 -t'+torrent["ID"]+' -ip' + ' | egrep -v "Address"')
peerasseeder = False
for peer in peers:
if int(float(peer.split()[2])) == 100:
peerasseeder = True
if int(torrent["Seeders"])<maxseeders and int(torrent["Leechers"])!=0 and not peerasseeder and float(torrent["Ratio"])<maxratio:
if torrent["Status"]=="Stopped":
result=popen('transmission-remote 8181 -t'+torrent["ID"]+' -s').read()
logging.info("start:"+torrent["Name"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"]))
elif (peerasseeder or int(torrent["Seeders"])>3) and torrent["ETA"]=="Done" and float(torrent["Ratio"])>maxratio:
if torrent["Status"]=="Idle" or torrent["Status"]=="Seeding":
result=popen('transmission-remote 8181 -t'+torrent["ID"]+' -S').read()
logging.info("stop:"+torrent["Name"]+" Ratio:"+str(torrent["Ratio"])+" Seeders:"+str(torrent["Seeders"]))
exit(0)