print a message when a download finishes

This commit is contained in:
Jimmy Kiselak 2016-01-22 18:16:00 -05:00
parent 6b724ba8db
commit f34b96f565
3 changed files with 21 additions and 2 deletions

View file

@ -75,6 +75,9 @@ class CryptStreamDownloader(object):
self.points_paid = 0.0 self.points_paid = 0.0
def __str__(self):
return str(self.stream_name)
def toggle_running(self): def toggle_running(self):
if self.stopped is True: if self.stopped is True:
return self.start() return self.start()

View file

@ -172,8 +172,15 @@ class LBRYFileSaver(LBRYFileDownloader):
stream_info_manager, payment_rate_manager, wallet, upload_allowed) stream_info_manager, payment_rate_manager, wallet, upload_allowed)
self.download_directory = download_directory self.download_directory = download_directory
self.file_name = file_name self.file_name = file_name
self.file_written_to = None
self.file_handle = None self.file_handle = None
def __str__(self):
if self.file_written_to is not None:
return str(self.file_written_to)
else:
return str(self.file_name)
def set_stream_info(self): def set_stream_info(self):
d = LBRYFileDownloader.set_stream_info(self) d = LBRYFileDownloader.set_stream_info(self)
@ -210,6 +217,7 @@ class LBRYFileSaver(LBRYFileDownloader):
file_name = file_name + "_" + str(ext_num) file_name = file_name + "_" + str(ext_num)
try: try:
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb') self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb')
self.file_written_to = os.path.join(self.download_directory, file_name)
except IOError: except IOError:
log.error(traceback.format_exc()) log.error(traceback.format_exc())
raise ValueError("Failed to open %s. Make sure you have permission to save files to that" raise ValueError("Failed to open %s. Make sure you have permission to save files to that"

View file

@ -481,7 +481,6 @@ class AddStream(CommandHandler):
self.options_chosen = [] self.options_chosen = []
self.current_option = None self.current_option = None
self.current_choice = None self.current_choice = None
self.downloader = None
self.got_options_response = False self.got_options_response = False
self.loading_failed = False self.loading_failed = False
self.payment_rate_manager = PaymentRateManager(base_payment_rate_manager) self.payment_rate_manager = PaymentRateManager(base_payment_rate_manager)
@ -764,10 +763,19 @@ class AddStream(CommandHandler):
def _start_download(self): def _start_download(self):
d = self._make_downloader() d = self._make_downloader()
d.addCallback(lambda stream_downloader: stream_downloader.start())
def do_download(stream_downloader):
d = stream_downloader.start()
d.addCallback(lambda _: self._download_succeeded(stream_downloader))
return d
d.addCallback(do_download)
d.addErrback(self._handle_download_error) d.addErrback(self._handle_download_error)
return d return d
def _download_succeeded(self, stream_downloader):
self.console.sendLine("%s has successfully downloaded." % str(stream_downloader))
def _handle_download_error(self, err): def _handle_download_error(self, err):
if err.check(InsufficientFundsError): if err.check(InsufficientFundsError):
self.console.sendLine("Download stopped due to insufficient funds.") self.console.sendLine("Download stopped due to insufficient funds.")