BTG

By | 10 Oct 2008

Homepage: http://btg.berlios.de/ http://sourceforge.net/projects/btg.berlios/

Incoming directory

To have a directory scanned for .torrent files and let them be added to BTG, there is this nice bash script from the BTG HowTo:

#!/bin/sh

CLIENT=btgcli
# The directory containing the torrent files.
INCOMING_DIR=~/btg/incomming
# The directory to which .torrent files are moved
# to after loading them into BTG.
DONE_DIR=~/btg/incomming/done

GOT_SESSION=0
$CLIENT -A -n -c "detach" &> /dev/null && GOT_SESSION=1

if [ $GOT_SESSION -eq 0 ]
then
  $CLIENT -n -c "detach" &> /dev/null && GOT_SESSION=1
fi

if [ $GOT_SESSION -eq 0 ]
then
  echo "Unable to attach or create a BTG session."
  exit -1
fi

TORRENT_ADDED=0

cd $INCOMING_DIR && \
for f in `ls -1 *.torrent 2> /dev/null` ; do
  echo "Loading file: $f" && \
  $CLIENT -A -n -c "detach" -o $f &> /dev/null && \
  TORRENT_ADDED=`expr $TORRENT_ADDED + 1` && \
  mv $f $DONE_DIR
done

if [ $TORRENT_ADDED -gt 0 ]
then
  echo "Added $TORRENT_ADDED torrents to BTG."
fiCode language: PHP (php)

Set Speedlimits based on time of day

This script also comes from the BTG HowTo:

#!/bin/sh

# The location of the BTG client application.
CLIENT=btgcli

H=`date +%H`
O="none"

if [ "$H" -gt "0" ] || [ "$H" -lt "6" ]
then
    O="night"
fi

if [ "$H" -gt "6" ] || [ "$H" -lt "12" ]
then
    O="morning"
fi

if [ "$H" -gt "12" ] || [ "$H" -lt "16" ]
then
    O="midday"
fi

if [ "$H" -gt "16" ] || [ "$H" -lt "23" ]
then
    O="evening"
fi

# Max upload limit.
UL_MAX=75

# Global limits in KiB/sec.
UL=-1
DL=-1
SET_LIMIT=0

case "$O" in
    night)
       UL=$UL_MAX
       SET_LIMIT=1
       echo "Limit:$O:$UL:$DL"
       ;;
    morning)
       UL=`expr $UL_MAX - 20`
       SET_LIMIT=1
       echo "Limit:$O:$UL:$DL"
       ;;
    midday)
       UL=`expr $UL_MAX - 40`
       SET_LIMIT=1
       echo "Limit:$O:$UL:$DL"
       ;;
    evening)
       UL=`expr $UL_MAX - 70`
       SET_LIMIT=1
       echo "Limit:$O:$UL:$DL"
       ;;
    *)
       echo "Not setting limit."
       ;;
esac

if [ "$SET_LIMIT" -eq "0" ]
then
    exit 0
fi

GOT_SESSION=0
$CLIENT -A -n -c "detach" &> /dev/null && GOT_SESSION=1

if [ $GOT_SESSION -eq 0 ]
then
  $CLIENT -n -c "detach" &> /dev/null && GOT_SESSION=1
fi

if [ $GOT_SESSION -eq 0 ]
then
  echo "Unable to attach or create a BTG session."
  exit -1
fi

$CLIENT -A -n -c "glimit $UL $DL -1 -1;detach" &> /dev/null && \
echo "Limit set."Code language: PHP (php)

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)