From a2893cc1b709f1ce94e443f4093d1cb7ef53bb2b Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Mon, 20 Jul 2009 08:20:17 +0000 Subject: [PATCH] change download_torrent_from_url to use the httpdownloader module --- deluge/ui/web/json_api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 7e5e1573d..e3f2227d8 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -45,7 +45,7 @@ from types import FunctionType from twisted.internet.defer import Deferred, DeferredList from twisted.web import http, resource, server -from deluge import common, component +from deluge import common, component, httpdownloader from deluge.configmanager import ConfigManager from deluge.ui import common as uicommon from deluge.ui.client import client, Client @@ -439,12 +439,15 @@ class WebApi(JSONComponent): :returns: the temporary file name of the torrent file :rtype: str """ + tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1]) - filename, headers = urllib.urlretrieve(url, tmp_file) - log.debug("filename: %s", filename) d = Deferred() - d.callback(filename) + httpdownloader.download_file(url, tmp_file).addCallback(self._on_torrent_downloaded, tmp_file, d) return d + + def _on_torrent_downloaded(self, result, filename, d): + log.debug("filename: %s", filename) + d.callback(filename) @export def get_torrent_info(self, filename):