implement basic adding of torrents via url

This commit is contained in:
Damien Churchill 2009-03-21 12:28:48 +00:00
parent 856cd63421
commit b2f01c177f
2 changed files with 28 additions and 6 deletions

View File

@ -22,12 +22,30 @@ Copyright:
*/
Deluge.Add = {
torrents: new Hash(),
onAdd: function() {
torrents = new Array();
this.torrents.each(function(info, hash) {
torrents.include({
path: info['filename'],
options: {}
});
});
Deluge.Client.web.add_torrents(torrents, {
onSuccess: function(result) {
}
})
this.Window.hide();
},
onRender: function(window) {
},
onTorrentAdded: function(info) {
this.Store.loadData([[info['info_hash'], info['name']]], true);
this.torrents[info['info_hash']] = info;
},
onUrl: function(button, event) {
@ -181,12 +199,11 @@ Deluge.Add.Url.Form = new Ext.form.FormPanel({
Deluge.Add.Url.Window = new Ext.Window({
layout: 'fit',
width: 300,
height: 150,
width: 350,
height: 115,
bodyStyle: 'padding: 10px 5px;',
buttonAlign: 'center',
closeAction: 'hide',
closable: false,
modal: true,
plain: true,
title: _('Add from Url'),
@ -214,7 +231,9 @@ Deluge.Add.Window = new Ext.Window({
buttons: [{
text: _('Cancel')
}, {
text: _('Add')
text: _('Add'),
handler: Deluge.Add.onAdd,
scope: Deluge.Add
}],
listeners: {'render': {fn: Deluge.Add.onRender, scope: Deluge.Add}}
});

View File

@ -24,6 +24,7 @@
import os
import time
import base64
import urllib
import hashlib
import logging
@ -357,8 +358,10 @@ class WebApi(JSONComponent):
"""
for torrent in torrents:
filename = os.path.basename(torrent["path"])
fdump = open(torrent["path"], "r").read()
client.add_torrent_file(filename, fdump, torrent["options"])
fdump = base64.encodestring(open(torrent["path"], "r").read())
log.info("Adding torrent from file `%s` with options `%r`",
filename, torrent["options"])
client.core.add_torrent_file(filename, fdump, torrent["options"])
d = Deferred()
d.callback(True)
return d