download fix

This commit is contained in:
Jack 2016-06-28 01:51:05 -04:00
parent 7cc3e9d5ef
commit cc5d917c72
3 changed files with 19 additions and 18 deletions

View file

@ -24,7 +24,7 @@ from appdirs import user_data_dir
from urllib2 import urlopen
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version
from lbryum.version import ELECTRUM_VERSION as lbryum_version
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
@ -398,7 +398,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False):
def _log_starting_vals():
d = self._get_lbry_files()
d.addCallback(lambda r: json.dumps([d[1] for d in r]))
d.addCallback(lambda r: json.dumps([d[1] if not isinstance(d[1], UnknownNameError) else {'error': 'Pending claim'} for d in r]))
d.addCallback(lambda r: log.info("LBRY Files: " + r))
d.addCallback(lambda _: log.info("Starting balance: " + str(self.session.wallet.wallet_balance)))
return d
@ -1038,12 +1038,15 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _get_stream(stream_info):
def _wait_for_write():
if os.path.isfile(os.path.join(self.download_directory, self.streams[name].downloader.file_name)):
written_file = file(os.path.join(self.download_directory, self.streams[name].downloader.file_name))
written_file.seek(0, os.SEEK_END)
written_bytes = written_file.tell()
written_file.close()
else:
try:
if os.path.isfile(os.path.join(self.download_directory, self.streams[name].downloader.file_name)):
written_file = file(os.path.join(self.download_directory, self.streams[name].downloader.file_name))
written_file.seek(0, os.SEEK_END)
written_bytes = written_file.tell()
written_file.close()
else:
written_bytes = False
except:
written_bytes = False
if not written_bytes:

View file

@ -112,6 +112,7 @@ class GetStream(object):
self.timeout_counter = self.timeout * 2
def _set_status(x, status):
log.info("Download lbry://%s status changed to %s" % (self.resolved_name, status))
self.code = next(s for s in STREAM_STAGES if s[0] == status)
return x
@ -121,9 +122,8 @@ class GetStream(object):
self.d.addCallback(lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
self.d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
self.d.addCallback(lambda r: _set_status(r, DOWNLOAD_RUNNING_CODE))
self.d.addCallback(lambda metadata: (
next(factory for factory in metadata.factories if isinstance(factory, ManagedLBRYFileDownloaderFactory)),
metadata))
self.d.addCallback(lambda metadata: (next(factory for factory in metadata.factories if isinstance(factory, ManagedLBRYFileDownloaderFactory)),
metadata))
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
[self.data_rate, True],
self.payment_rate_manager,
@ -144,11 +144,9 @@ class GetStream(object):
return self.wallet.send_points_to_address(reserved_points, self.key_fee)
return defer.succeed(None)
if self.pay_key:
d = _pay_key_fee()
else:
d = defer.Deferred()
d = _pay_key_fee()
self.downloader = downloader
self.download_path = os.path.join(downloader.download_directory, downloader.file_name)
d.addCallback(lambda _: log.info("[%s] Downloading %s --> %s" % (datetime.now(), self.stream_hash, self.file_name)))
d.addCallback(lambda _: log.info("[%s] Downloading %s --> %s" % (datetime.now(), self.stream_hash, self.downloader.file_name)))
d.addCallback(lambda _: self.downloader.start())

View file

@ -10,7 +10,7 @@ from twisted.web import static
from twisted.internet import defer
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version
from lbryum.version import ELECTRUM_VERSION as lbryum_version
from zipfile import ZipFile
from appdirs import user_data_dir