Hi im trying to change my active listening port on intervals, because i use an ext VPN service and need to update once a houre. From another thread in this forum from 2011 i got this
client.core.set_config({"listen_ports":[sys.argv[1], sys.argv[1]],"random_port":False}).addCallback(on_port_set);
That updates the values in the config but deluge is not reading them in as active port. I tried alot of different stuff but nothing is working. How can i make it update the same way the gtk ui is doing when hitting the apply button?
Tried reading the doc but it says nothing about applying after changing the values.
Thanks in advance.
Changing the listenting_ports wont update active port
Re: Changing the listenting_ports wont update active port
Forget it, it now works. When i added the url request. Wierd. Maybe needed some time before i could run the update. anyhow i just need to get my ip automaticly and im all set. Publishing the code here if anyone else is using the privateinternetaccess.com service.
Code: Select all
#!/usr/bin/python
from deluge.ui.client import client as client
from twisted.internet import reactor
from deluge.log import setupLogger
setupLogger()
import urllib
import urllib2
import json
import sys
YOUR_USERNAME = ""
YOUR_PASSWORD = ""
YOUR_IP = ""
YOUR_CLIENT_ID = ""
API_URL = "https://www.privateinternetaccess.com/vpninfo/port_forward_assignment"
d = client.connect(host='127.0.0.1',username='',password='')
def on_connect_success(result):
def on_get_ports(status):
print "on_get_ports: ",status
client.disconnect()
reactor.stop()
def on_get_port(status):
client.core.get_config_value("listen_ports").addCallback(on_get_ports)
print resp["port"]," == ",status,"?"
def on_torrent_id(ids):
print ids
client.core.force_reannounce(ids)
client.core.get_listen_port().addCallback(on_get_port)
def on_port_set(void):
client.core.get_session_state().addCallback(on_torrent_id)
request = urllib2.Request(API_URL, urllib.urlencode(
{
"user":YOUR_USERNAME,
"pass":YOUR_PASSWORD,
"client_id":YOUR_CLIENT_ID,
"local_ip":YOUR_IP
}
))
response = ""
for line in urllib2.urlopen(request).readlines():
response += line
resp = json.loads(response)
if "port" in resp:
client.core.set_config({"listen_ports":[resp["port"], resp["port"]],"random_port":False}).addCallback(on_port_set);
elif "error" in resp:
print "Error: %s" % resp["error"]
sys.exit(-1)
else:
print "Error: no idea what failed!"
sys.exit(-2)
d.addCallback(on_connect_success)
def on_connect_fail(result):
print "connection to deluge failed"
d.addErrback(on_connect_fail)
reactor.run()
Re: Changing the listenting_ports wont update active port
Hi krise. I am also trying to setup the privateinternetaccess.com service with Deluge. I'm not sure where to put your code... I'm using Ubuntu 12.04, but I'm new to Linux. Thank you so much for publishing the code and any help to get it up and running would be greatly appreciated. Thanks again.
Re: Changing the listenting_ports wont update active port
Hello. I am new to the linux world. I am trying to setup Raspbian, with deluge, utilizing privateinternetaccess. Any chance of a little more explanation
?
