diff --git a/lbrynet/analytics/events.py b/lbrynet/analytics/events.py index 310ee1ce1..d211754ee 100644 --- a/lbrynet/analytics/events.py +++ b/lbrynet/analytics/events.py @@ -55,6 +55,20 @@ class Events(object): } return self._event('Download Started', properties) + def download_errored(self, name, stream_info=None): + properties = { + 'name': name, + 'stream_info': get_sd_hash(stream_info) + } + return self._event('Download Errored', properties) + + def download_finished(self, name, stream_info=None): + properties = { + 'name': name, + 'stream_info': get_sd_hash(stream_info) + } + return self._event('Download Finished', properties) + def error(self, message, sd_hash=None): properties = { 'message': message, diff --git a/lbrynet/analytics/manager.py b/lbrynet/analytics/manager.py index 5af578b61..b8d00526b 100644 --- a/lbrynet/analytics/manager.py +++ b/lbrynet/analytics/manager.py @@ -74,6 +74,14 @@ class Manager(object): event = self.events_generator.download_started(name, stream_info) self.analytics_api.track(event) + def send_download_errored(self, name, stream_info=None): + event = self.events_generator.download_errored(name, stream_info) + self.analytics_api.track(event) + + def send_download_finished(self, name, stream_info=None): + event = self.events_generator.download_finished(name, stream_info) + self.analytics_api.track(event) + def send_error(self, message, sd_hash=None): event = self.events_generator.error(message, sd_hash) self.analytics_api.track(event) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 295494087..7d1b65096 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -790,7 +790,7 @@ class Daemon(AuthJSONRPCServer): If it already exists in the file manager, return the existing lbry file """ timeout = timeout if timeout is not None else conf.settings.download_timeout - self.analytics_manager.send_download_started(name, stream_info) + helper = _DownloadNameHelper( self, name, timeout, download_directory, file_name, wait_for_write) @@ -1504,6 +1504,9 @@ class Daemon(AuthJSONRPCServer): # TODO: return a useful error message here, like "already # waiting for name to be resolved" defer.returnValue(server.failure) + name = params.name + stream_info = params.stream_info + self.analytics_manager.send_download_started(name, stream_info) try: sd_hash, file_path = yield self._download_name( name=params.name, @@ -1514,6 +1517,7 @@ class Daemon(AuthJSONRPCServer): wait_for_write=params.wait_for_write ) except Exception as e: + self.analytics_manager.send_download_errored(name, stream_info) log.exception('Failed to get %s', params.name) response = yield self._render_response(str(e), OK_CODE) else: @@ -1522,6 +1526,10 @@ class Daemon(AuthJSONRPCServer): 'stream_hash': params.sd_hash if params.stream_info else sd_hash, 'path': file_path } + stream = self.streams.get(name) + if stream: + stream.downloader.finished_deferred.addCallback( + lambda _: self.analytics_manager.send_download_finished(name, stream_info)) response = yield self._render_response(message, OK_CODE) defer.returnValue(response)