#!/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()
And this is Pause torrents while I'm using the computer, written , and concerning Python, Howtos, and Sundry Hacks
Comments
shivan: In order to use transmission-remote you still need to enable remote access, which turns on the webui at the same time.
# 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()
ah, didn't know that.
Also, I asked on #transmission and the JSON-RPC API is considered a good way to remotely control Transmission.
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!
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.
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
Dx: true, but I *am* a single-user environment so I don't care :)
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)
Anirudh: heh. Yes, it would. Big CSRF problem there, I admit it.
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.
whatever
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!
Brilliant, thanks. Any idea how you would amend the script if a password had been set?
[...] Pause torrents while I’m using the computer [...]
thanks this is very useful
[...] found my source here. The comments also include a patch for throttling the app rather than outright pausing [...]
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
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...
correct me if I'm wrong, but I think you can use transmission-remote, no need to enable the web interface.