MODS: Queuing with Transmission BitTorrent Client

If you followed our previous article in adding a telnet utility to your Popcorn Hour C-200 and installed LTU 0.76, you also upgraded the Transmission torrent client in the process. The latest bittorrent client, Transmission 2.33, is packaged with the LTU 0.76. This is one of the strengths of having a custom package installed on the C-200. One thing to note though is that if you installed BusyBox 1.4.1 on the C-200, it conflicts with LTU 0.76. So better to uninstall BusyBox and retain LTU instead.

Having a telnet shell to the Popcorn Hour C-200 is very powerful. Here is a demonstration of how powerful and flexible having a shell access to the C-200 really is -- queuing with the transmission torrent client. The transmission bittorrent client doesn't have this feature by default, but that doesn't mean we can't do anything about it. Here's a script you can put on your C-200 that controls queuing of Transmission torrents.

#!/bin/sh

# *************
# Configuration
REMOTE="/nmt/apps/bin/transmission-remote"
USERNAME="nmt"
PASSWORD="1234"
MAXDOWN=2
MAXACTIVE=5
CONFIG="/share/.transmission/settings.json"

# *************
# Set-up variables
CMD="$REMOTE --auth $USERNAME:$PASSWORD"
MAXRATIO=$(cat $CONFIG | grep \"ratio-limit\":)
MAXRATIO=${MAXRATIO#*\"ratio-limit\": }
MAXRATIO=${MAXRATIO%*, }

# *************
# deal with downloads
DOWNACTIVE="$($CMD -l | tail -n +2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXDOWN -lt $DOWNACTIVE ]; then
    DOWNTOSTOP="$($CMD -l | tail -n +2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $DOWNACTIVE - $MAXDOWN) | awk '{ print $1; }')"
    for ID in $DOWNTOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXDOWN - $DOWNACTIVE) -gt 0 ] && (
    DOWNINACTIVE="$($CMD -l | tail -n +2 | grep -v 100% | grep Stopped | wc -l)"
    [ $DOWNINACTIVE -gt 0 ] && (
        DOWNTOSTART="$($CMD -l | tail -n +2 | grep -v 100% | grep Stopped | head -n $(expr $MAXDOWN - $DOWNACTIVE) | awk '{ print $1; }')"
        for ID in $DOWNTOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi
# Then deal with total active
ACTIVE="$($CMD -l | tail -n +2 | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXACTIVE -lt $ACTIVE ]; then
    TOSTOP="$($CMD -l | tail -n +2 | grep 100% | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $ACTIVE - $MAXACTIVE) | awk '{ print $1; }')"
    for ID in $TOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXACTIVE - $ACTIVE) -gt 0 ] && (
    SEEDINACTIVE="$($CMD -l | tail -n +2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (substr($0,52,4) < ratio) print $0 ;}' | wc -l)"
    [ $SEEDINACTIVE -gt 0 ] && (
        TOSTART="$($CMD -l | tail -n +2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (substr($0,52,4) < ratio) print $0 ;}' | head -n $(expr $MAXACTIVE - $ACTIVE) | awk '{ print $1; }')"
        for ID in $TOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )

On the above script, change the values for USERNAME, PASSWORD, MAXDOWN and MAXACTIVE. The script above contains the default values for the C-200. I tested the above script to work on my C-200. It will work on another 200 series Popcorn Hour too. A friend has tested it on his A-210 as well, and his feedback is good.

The script is working but how do you automate this? Linux just has the answer in cron. The script can be manually put in cron but the issue is, when the C-200 is rebooted, the entries get wiped out.

This is how to automate the queuing on the Transmission torrent client on the C-200. Edit the file /share/Apps/LTU/appinfo.json. Add the line:
crontab="*/5 * * * * /PATH/TO/torrent-queue.sh"

Verify that your crontab has entries above by rebooting the C-200 and check with "crontab -l". That's it folks, queuing working with the Transmission BT client. Now, imagine trying to do the same without shell access to your Popcorn Hour.

Credits: The original script was taken from http://pastie.org/632212. It was then adapted to work with the Popcorn Hour C-200.

You might also be interested in:

Feedback

We at pimp-my-rig strive to keep on improving, help us reach that goal by leaving comments or constructive criticisms. Don't miss out on our next feature -- subscribe via RSS (What is RSS?).

Share This

1 comments: