This is as days pass by, by Stuart Langridge

And this is Pause torrents while I'm using the computer, written , and concerning Python, Howtos, and Sundry Hacks

I use the Transmission BitTorrent client, and it's pretty cool. However, it's irritating when it eats my bandwidth while I'm trying to do stuff. So, one obvious hack would be to disable it when the screensaver is off (i.e., I'm using the computer) and enable it only when the screensaver is on (i.e., I'm in bed). Fortunately, Transmission has an API (which you have to enable by turning on the web interface in Preferences) and you can watch the Gnome screensaver for changes. So, a quick Python script later, and throw that Python script and Transmission itself into your session Startup Programs to make them run whenever you log in, and Bob's your uncle. the script:
#!/usr/bin/env python
import dbus, urllib
from dbus.mainloop.glib import DBusGMainLoop

START_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-start"
STOP_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-stop"

DBusGMainLoop(set_as_default=True)
sess=dbus.SessionBus()
def sig(screensaverActive):
  if screensaverActive:
    data = urllib.urlopen(START_TORRENTS).read()
  else:
    data = urllib.urlopen(STOP_TORRENTS).read()

sess.add_signal_receiver(sig, 'ActiveChanged','org.gnome.ScreenSaver')
import gobject
loop = gobject.MainLoop()
loop.run()

Comments

shivan

correct me if I'm wrong, but I think you can use transmission-remote, no need to enable the web interface.

Gimp

shivan: In order to use transmission-remote you still need to enable remote access, which turns on the webui at the same time.

jegHegy

# Thanks for this!

# This patch will make it so it throttles upload speed instead of pausing. Useful for ADSL connections.

7,8d6

<  THROTTLE_UPLOAD = "http://localhost:9091/transmission/rpc?method=session-set&speed-limit-up=15&speed-limit-up-enabled=1

< MAX_UPLOAD = "http://localhost:9091/transmission/rpc?method=session-set&speed-limit-up-enabled=0

14c12

<     data = urllib.urlopen(MAX_UPLOAD).read()

---

>     data = urllib.urlopen(START_TORRENTS).read()

16c14

<      data = urllib.urlopen(THROTTLE_UPLOAD).read()

---

>     data = urllib.urlopen(STOP_TORRENTS).read()

shivan

ah, didn't know that.

sil

Also, I asked on #transmission and the JSON-RPC API is considered a good way to remotely control Transmission.

apan

another idea is to use QoS in your router/laptop that prioritizes your interactive protocols, and http. then you can be a good puppy and seed that warez att full speed to all the other warez puppies and still get work done!

knipknap

This is one of those problems that shouldn't exist in the first place. The desktop should just prioritize whatever application you are currently using, and not grant other applications to hog your resources. This is just so 1980.

D

I'm actually with apan on this. The scripts will work well in a single user environment, but if my interwobz turned to treacle every time Essk went to bed I'd be fuming.

IMO, a proper solution is superior to a single machine hack. Although I do cheat, I rent a dedicated box on 100mbit full duplex for torrenting ;-)

-Dx

sil

Dx: true, but I *am* a single-user environment so I don't care :)

Anirudh

I never used transmission or torrents but this rpc seems to be interesting.

So if I have [img src="http://localhost:9091/transmission/rpc?method=torrent-stop"] in my html page, your torrents would stop downloading?

(testing html inserted here. Load this page while a torrent is running)

sil

Anirudh: heh. Yes, it would. Big CSRF problem there, I admit it.

J.B. Nicholson-Owens

Transmission 1.33 (6608) (and I assume later) will let you disable the web interface entirely (so none of the URLs you're using will work) or set credentials to control the web interface (so you have to supply proper credentials before any of the URLs you're using will work). The defaults might be bad (web access on by default with "transmission" as login and password) but it's reconfigurable: There's a GUI configuration panel for this in the Transmission preferences in the "Web" tab.

Anonymous Coward

whatever

sil

JBNO: indeed it does. I noted that you have to enable the web interface (it was disabled by default in T 1.34 (6778) in Ubuntu intrepid), but didn't note what you have to do if you set a password; this was a hack for me rather than totally general-purpose!

gnudoc

Brilliant, thanks. Any idea how you would amend the script if a password had been set?

Google Reader Shared Items - November 18, 2008 at Simple Nerd

[...] Pause torrents while I’m using the computer [...]

Torrent Moon

thanks this is very useful

Pause Torrent Downloads When Screensaver Is Inactive | tail -f /dev/null

[...] found my source here.  The comments also include a patch for throttling the app rather than outright pausing [...]

Evan Carroll

Firstly, your forum integrates badly with yahoo. OpenID v1 is not supported by yahoo, when I returned I lost my message.

I think integrating transmission with X-screensaver by proxy through gnome-faster-user-switch-applet is the best bet. This way you can be mark yourself as away the torrents will continue download, pidgin will place you in away status, and you can watch a movie. Then when you mark yourself as "available" your torrents will cease and other applications will get the event that corresponds to you being at the comp.

The fast user switch applet is the first applet that handles away-status events. The screensaver by default will put you in away-status too ;)

http://trac.transmissionbt.com/ticket/1616

sil

Evan: yeah, openid is a bit broken. A fix is in the works.


The reason I didn't integrate with the switch applet is that not everyone's using it...

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.