download fixes

This commit is contained in:
Jack 2016-07-20 20:17:01 -04:00
parent c232743963
commit 0bee2689d1

View file

@ -1599,13 +1599,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
# can spec what parameters it expects and how to set default values # can spec what parameters it expects and how to set default values
timeout = p.get('timeout', self.download_timeout) timeout = p.get('timeout', self.download_timeout)
download_directory = p.get('download_directory', self.download_directory) download_directory = p.get('download_directory', self.download_directory)
file_name = p.get('file_name') file_name = p.get('file_name', None)
stream_info = p.get('stream_info') stream_info = p.get('stream_info', None)
sd_hash = get_sd_hash(stream_info) sd_hash = get_sd_hash(stream_info)
wait_for_write = p.get('wait_for_write', True) wait_for_write = p.get('wait_for_write', True)
name = p.get('name') name = p.get('name')
return Parameters( return Parameters(
timout=timeout, timeout=timeout,
download_directory=download_directory, download_directory=download_directory,
file_name=file_name, file_name=file_name,
stream_info=stream_info, stream_info=stream_info,
@ -1633,13 +1633,14 @@ class LBRYDaemon(jsonrpc.JSONRPC):
return server.failure return server.failure
if params.name in self.waiting_on: if params.name in self.waiting_on:
return server.failure return server.failure
d = self._download_name(name=params.name, d = self._download_name(name=params.name,
timeout=params.timeout, timeout=params.timeout,
download_directory=params.download_directory, download_directory=params.download_directory,
stream_info=params.stream_info, stream_info=params.stream_info,
file_name=params.file_name, file_name=params.file_name,
wait_for_write=params.wait_for_write) wait_for_write=params.wait_for_write)
d.addCallback(get_output_callback(params)) # d.addCallback(get_output_callback(params))
d.addCallback(lambda message: self._render_response(message, OK_CODE)) d.addCallback(lambda message: self._render_response(message, OK_CODE))
return d return d
@ -2263,13 +2264,15 @@ class _DownloadNameHelper(object):
return d return d
def _wait_on_lbry_file(self, f): def _wait_on_lbry_file(self, f):
if f is not None:
written_bytes = self.get_written_bytes(f.file_name) written_bytes = self.get_written_bytes(f.file_name)
if not written_bytes: if written_bytes:
return defer.succeed(self._disp_file(f))
d = defer.succeed(None) d = defer.succeed(None)
d.addCallback(lambda _: reactor.callLater(1, self._wait_on_lbry_file, f)) d.addCallback(lambda _: reactor.callLater(1, self._wait_on_lbry_file, f))
return d return d
else:
return defer.succeed(self._disp_file(f))
def get_written_bytes(self, file_name): def get_written_bytes(self, file_name):
try: try: