change download_torrent_from_url to use the httpdownloader module

This commit is contained in:
Damien Churchill 2009-07-20 08:20:17 +00:00
commit a2893cc1b7

View file

@ -45,7 +45,7 @@ from types import FunctionType
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
from twisted.web import http, resource, server 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.configmanager import ConfigManager
from deluge.ui import common as uicommon from deluge.ui import common as uicommon
from deluge.ui.client import client, Client from deluge.ui.client import client, Client
@ -439,12 +439,15 @@ class WebApi(JSONComponent):
:returns: the temporary file name of the torrent file :returns: the temporary file name of the torrent file
:rtype: str :rtype: str
""" """
tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1]) 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 = Deferred()
d.callback(filename) httpdownloader.download_file(url, tmp_file).addCallback(self._on_torrent_downloaded, tmp_file, d)
return d return d
def _on_torrent_downloaded(self, result, filename, d):
log.debug("filename: %s", filename)
d.callback(filename)
@export @export
def get_torrent_info(self, filename): def get_torrent_info(self, filename):