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()
correct me if I’m wrong, but I think you can use transmission-remote, no need to enable the web interface.
Posted by shivan on November 16th, 2008.
shivan: In order to use transmission-remote you still need to enable remote access, which turns on the webui at the same time.
Posted by Gimp on November 16th, 2008.
# 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()
Posted by jegHegy on November 16th, 2008.
ah, didn’t know that.
Posted by shivan on November 16th, 2008.
Also, I asked on #transmission and the JSON-RPC API is considered a good way to remotely control Transmission.
Posted by sil on November 16th, 2008.
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!
Posted by apan on November 16th, 2008.
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.
Posted by knipknap on November 16th, 2008.
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
Posted by D on November 16th, 2008.
Dx: true, but I *am* a single-user environment so I don’t care :)
Posted by sil on November 16th, 2008.
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)
Posted by Anirudh on November 16th, 2008.
Anirudh: heh. Yes, it would. Big CSRF problem there, I admit it.
Posted by sil on November 17th, 2008.
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.
Posted by J.B. Nicholson-Owens on November 17th, 2008.
whatever
Posted by Anonymous on November 18th, 2008.
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!
Posted by sil on November 18th, 2008.
Brilliant, thanks. Any idea how you would amend the script if a password had been set?
Posted by gnudoc on November 19th, 2008.
[...] Pause torrents while I’m using the computer [...]
Posted by Google Reader Shared Items - November 18, 2008 at Simple Nerd on November 19th, 2008.
thanks this is very useful
Posted by Torrent Moon on November 24th, 2008.
[...] found my source here. The comments also include a patch for throttling the app rather than outright pausing [...]
Posted by Pause Torrent Downloads When Screensaver Is Inactive | tail -f /dev/null on December 7th, 2008.
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
Posted by Evan Carroll on December 22nd, 2008.
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…
Posted by sil on December 22nd, 2008.