Add support for cookies when adding a torrent by url.

Don't set torrent if torrentId is null.
Fix typo.
This commit is contained in:
John Garland 2009-08-01 02:38:30 +00:00
parent ded6bb9566
commit 9b0d4f6118
3 changed files with 13 additions and 6 deletions

View File

@ -78,13 +78,14 @@ Ext.deluge.add.UrlWindow = Ext.extend(Ext.deluge.add.Window, {
},
onAdd: function(field, e) {
if (field.id == 'url' && e.getKey() != e.ENTER) return;
if ((field.id == 'url' || field.id == 'cookies') && e.getKey() != e.ENTER) return;
var field = this.urlField;
var url = field.getValue();
var cookies = this.cookieField.getValue();
var torrentId = this.createTorrentId();
Deluge.Client.web.download_torrent_from_url(url, {
Deluge.Client.web.download_torrent_from_url(url, cookies, {
success: this.onDownload,
scope: this,
torrentId: torrentId
@ -107,4 +108,4 @@ Ext.deluge.add.UrlWindow = Ext.extend(Ext.deluge.add.Window, {
info['filename'] = request.options.filename;
this.fireEvent('add', request.options.torrentId, info);
}
});
});

View File

@ -270,6 +270,8 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
},
setTorrent: function(torrentId) {
if (!torrentId) return;
this.torrentId = torrentId;
this.optionsManager.changeId(torrentId);
@ -492,7 +494,7 @@ Ext.deluge.add.AddWindow = Ext.extend(Ext.deluge.add.Window, {
delete this.torrents[torrent.id];
this.grid.getStore().remove(torrent);
this.options.clear();
this.optionsPanel.clear();
},
onSelect: function(selModel, rowIndex, record) {

View File

@ -445,7 +445,7 @@ class WebApi(JSONComponent):
return main_deferred
@export
def download_torrent_from_url(self, url):
def download_torrent_from_url(self, url, cookie=None):
"""
Download a torrent file from a url to a temporary directory.
@ -457,7 +457,11 @@ class WebApi(JSONComponent):
tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1])
log.debug("filename: %s", tmp_file)
return httpdownloader.download_file(url, tmp_file)
headers = {}
if cookie:
headers["Cookie"] = str(cookie)
log.debug("cookie: %s", cookie)
return httpdownloader.download_file(url, tmp_file, headers=headers)
@export
def get_torrent_info(self, filename):