implement basic adding of torrents via url

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

View file

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

View file

@ -24,6 +24,7 @@
import os import os
import time import time
import base64
import urllib import urllib
import hashlib import hashlib
import logging import logging
@ -357,8 +358,10 @@ class WebApi(JSONComponent):
""" """
for torrent in torrents: for torrent in torrents:
filename = os.path.basename(torrent["path"]) filename = os.path.basename(torrent["path"])
fdump = open(torrent["path"], "r").read() fdump = base64.encodestring(open(torrent["path"], "r").read())
client.add_torrent_file(filename, fdump, torrent["options"]) 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 = Deferred()
d.callback(True) d.callback(True)
return d return d