diff --git a/deluge/core/core.py b/deluge/core/core.py index a979f2283..cf1065b03 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -267,7 +267,7 @@ class Core(component.Component): :returns: a Deferred which returns the torrent_id as a str or None """ log.info("Attempting to add url %s", url) - def on_get_file(result): + def on_get_file(filename): # We got the file, so add it to the session data = open(filename, "rb").read() return self.add_torrent_file(filename, base64.encodestring(data), options) @@ -278,8 +278,7 @@ class Core(component.Component): log.error("Reason: %s", failure.getErrorMessage()) return failure - filename = url.split("/")[-1] - d = download_file(url, filename, headers=headers) + d = download_file(url, url.split("/")[-1], headers=headers) d.addCallback(on_get_file) d.addErrback(on_get_file_error) return d diff --git a/deluge/httpdownloader.py b/deluge/httpdownloader.py index f3afb3c66..4e65d89cb 100644 --- a/deluge/httpdownloader.py +++ b/deluge/httpdownloader.py @@ -43,14 +43,19 @@ class HTTPDownloader(client.HTTPDownloader): """ def __init__(self, url, filename, part_callback=None, headers=None): """ - :param url: str, the url to download from - :param filename: str, the filename to save the file as - :param part_callback: func, a function to be called when a part of data + :param url: the url to download from + :type url: string + :param filename: the filename to save the file as + :type filename: string + :param part_callback: a function to be called when a part of data is received, it's signature should be: func(data, current_length, total_length) - :param headers: dict, any optional headers to send + :type part_callback: function + :param headers: any optional headers to send + :type headers: dictionary """ self.__part_callback = part_callback self.current_length = 0 + self.value = filename client.HTTPDownloader.__init__(self, url, filename, headers=headers) def gotStatus(self, version, status, message): @@ -83,11 +88,19 @@ def download_file(url, filename, callback=None, headers=None): Downloads a file from a specific URL and returns a Deferred. You can also specify a callback function to be called as parts are received. - :param url: str, the url to download from - :param filename: str, the filename to save the file as - :param callback: func, a function to be called when a part of data is received, + :param url: the url to download from + :type url: string + :param filename: the filename to save the file as + :type filename: string + :param callback: a function to be called when a part of data is received, it's signature should be: func(data, current_length, total_length) - :param headers: dict, any optional headers to send + :type callback: function + :param headers: any optional headers to send + :type headers: dictionary + + :returns: the filename of the downloaded file + :rtype: Deferred + :raises t.w.e.PageRedirect: when server responds with a temporary redirect or permanently moved. :raises t.w.e.Error: for all other HTTP response errors (besides OK) diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index f72e1ccdb..66d47c7e5 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -636,7 +636,7 @@ class AddTorrentDialog(component.Component): def on_download_success(result): log.debug("Download success!") - self.add_from_files([tmp_file]) + self.add_from_files([result]) dialog.destroy() def on_download_fail(result): diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index b1eb94b36..57c1adbaf 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -456,12 +456,9 @@ class WebApi(JSONComponent): """ tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1]) - return httpdownloader.download_file(url, tmp_file).addCallback(self._on_torrent_downloaded, tmp_file) + log.debug("filename: %s", tmp_file) + return httpdownloader.download_file(url, tmp_file) - def _on_torrent_downloaded(self, result, filename): - log.debug("filename: %s", filename) - return filename - @export def get_torrent_info(self, filename): """