Using 1.3.14 I can no longer submit a torrent url. With prior versions I would send a request to the json api similar to this:
torrent = {'path': 'www.torrentsite.com/file.torrent'}
command = {'method': 'web.add_torrents',
'params': [[torrent]],
'id': command_id
}
command_id += 1
request = urllib2.Request(web_ui_url, post_data=json.dumps(command))
However, now I get the error
invalid mode ('rb') or filename: u'www.torrentsite.com/file.torrent'
What is the preferred method to add torrents via url?
1.3.14 Cannot add url via json api
-
- New User
- Posts: 6
- Joined: Mon Jan 23, 2017 8:43 pm
Re: 1.3.14 Cannot add url via json api
Are you setting the content header? See http://forum.deluge-torrent.org/viewtop ... =7&t=54428
-
- New User
- Posts: 6
- Joined: Mon Jan 23, 2017 8:43 pm
Re: 1.3.14 Cannot add url via json api
I am setting the header according to that thread. I can add magnet URIs fine, just not .torrent URLs.
The full(-ish) code I use is:
And the output from Deluge is:
This is for Watcher, btw. In case you are interested. https://github.com/nosmokingbandit/watcher
The full(-ish) code I use is:
Code: Select all
headers = {'Content-Type': 'application/json', 'User-Agent': 'Watcher'}
url = 'http://localhost:8112/json'
command = {'method': 'web.add_torrents',
'params': [[torrent]],
'id': DelugeWeb.command_id
}
DelugeWeb.command_id += 1
post_data = json.dumps(command)
request = Url.request(url, post_data=post_data, headers=headers)
request.add_header('cookie', DelugeWeb.cookie) # This is taken care of elsewhere
urllib2.urlopen(request)
Code: Select all
[ERROR ] 17:35:42 json_api:239 Error calling method `web.add_torrents`
[ERROR ] 17:35:42 json_api:240 [Errno 22] invalid mode ('rb') or filename: u'http://www.indexer.com/this_is_a_torrent.torrent'
Traceback (most recent call last):
File "deluge\ui\web\json_api.py", line 231, in _handle_request
File "deluge\ui\web\json_api.py", line 198, in _exec_local
File "deluge\ui\web\json_api.py", line 791, in add_torrents
IOError: [Errno 22] invalid mode ('rb') or filename: u'http://www.indexer.com/this_is_a_torrent.torrent'
This is for Watcher, btw. In case you are interested. https://github.com/nosmokingbandit/watcher
Re: 1.3.14 Cannot add url via json api
Ok with that log I see what you mean. You are using a URL for a file location, hence filename in error trace. See
http://git.deluge-torrent.org/deluge/tr ... table#n653
download_torrent_from_url
http://git.deluge-torrent.org/deluge/tr ... table#n653
Re: 1.3.14 Cannot add url via json api
There have been no changes to API though so not sure how it worked before for you.
-
- New User
- Posts: 6
- Joined: Mon Jan 23, 2017 8:43 pm
Re: 1.3.14 Cannot add url via json api
Yeah, that fixed me up. Thanks for the help, much appreciated
With a cursory glance over the entire api it doesn't seem possible to download the url and load it into Deluge in one command. Am I being dumb again or is this not possible? Have you considered adding the ability to do this?
I know it can be super annoying when other people make suggestions on how to code things, but perhaps you can add a quick test in WebApi.add_torrents() that tests if the passed torrent is a URL or not, then executes download_torrent_from_url() and loads the return value directly into the download queue?
Insert after line 789
Not a huge deal, but you'd save the overhead of one extra api request per url download.
With a cursory glance over the entire api it doesn't seem possible to download the url and load it into Deluge in one command. Am I being dumb again or is this not possible? Have you considered adding the ability to do this?
I know it can be super annoying when other people make suggestions on how to code things, but perhaps you can add a quick test in WebApi.add_torrents() that tests if the passed torrent is a URL or not, then executes download_torrent_from_url() and loads the return value directly into the download queue?
Insert after line 789
Code: Select all
if urlparse.urlparse(torrent['path']).scheme != "":
torrent['path'] = self.download_torrent_from_url(torrent)