Thursday, March 6, 2008

My silly ktorrent script

I cant explain why ( nor that I intend to ), when I increase my upload speed on ktorrent, the download speed shoots up for a while ... And thus the following script comes into being ... dcop rocks !!!

#!/bin/bash

while [ 1 ]
do
#echo "[+] stopping all"
#dcop ktorrent KTorrent stopAll 1
echo -e "\n[+] INCREASING Upload-rate\n"
dcop ktorrent KTorrent setMaxUploadSpeed 0
sleeptime=10
for ((i=1;i<=$sleeptime;i++))
do
info=`dcop ktorrent KTorrent getInfo | grep "Speed" | awk '{print "UP:",$3,$4," \tDOWN:",$7,$8}'`
eta=`dcop ktorrent KTorrent getTorrentInfo 0 | awk '{if(NR==8) print $1}'`
echo -e "\t$i.$info \tETA:$eta"
sleep 1
done

#dcop ktorrent KTorrent startAll 1
up=`dcop ktorrent KTorrent getInfo | grep "Speed" | sed 's/Speed//g' | awk '{print $2}' | awk -F "." '{print $1}'`
if [ $up -gt 5 ];then
echo -e "\n[+] DECREASING Upload-rate\n"
dcop ktorrent KTorrent setMaxUploadSpeed 1
sleeptime=20
for ((i=1;i<=$sleeptime;i++))
do
info=`dcop ktorrent KTorrent getInfo | grep "Speed" | awk '{print "UP:",$3,$4," \tDOWN:",$7,$8}'`
eta=`dcop ktorrent KTorrent getTorrentInfo 0 | awk '{if(NR==8) print $0}'`
echo -e "\t$i.$info \tETA:$eta"
sleep 1
done
fi
done