forked from LBRYCommunity/lbry-sdk
send Download Started event
This commit is contained in:
parent
b201fc331c
commit
6a72b3683e
2 changed files with 34 additions and 1 deletions
|
@ -1,6 +1,21 @@
|
|||
import logging
|
||||
|
||||
from lbrynet.analytics import utils
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_sd_hash(stream_info):
|
||||
if not stream_info:
|
||||
return None
|
||||
try:
|
||||
return stream_info['sources']['lbry_sd_hash']
|
||||
except (KeyError, TypeError, ValueError):
|
||||
log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True)
|
||||
return None
|
||||
|
||||
|
||||
class Events(object):
|
||||
def __init__(self, context, lbry_id, session_id):
|
||||
self.context = context
|
||||
|
@ -19,6 +34,20 @@ class Events(object):
|
|||
'timestamp': utils.now()
|
||||
}
|
||||
|
||||
def download_started(self, name, stream_info=None):
|
||||
return {
|
||||
'userId': 'lbry',
|
||||
'event': 'Download Started',
|
||||
'properties': {
|
||||
'lbry_id': self.lbry_id,
|
||||
'session_id': self.session_id,
|
||||
'name': name,
|
||||
'stream_info': get_sd_hash(stream_info)
|
||||
},
|
||||
'context': self.context,
|
||||
'timestamp': utils.now()
|
||||
}
|
||||
|
||||
|
||||
def make_context(platform, wallet, is_dev=False):
|
||||
# TODO: distinguish between developer and release instances
|
||||
|
|
|
@ -561,10 +561,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
self.send_heartbeat.start(60)
|
||||
|
||||
def _send_heartbeat(self):
|
||||
log.debug('Sending heartbeat')
|
||||
heartbeat = self._events.heartbeat()
|
||||
self.analytics_api.track(heartbeat)
|
||||
|
||||
def _send_download_started(self, name, stream_info=None):
|
||||
event = self._events.download_started(name, stream_info)
|
||||
self.analytics_api.track(event)
|
||||
|
||||
def _get_platform(self):
|
||||
r = {
|
||||
"processor": platform.processor(),
|
||||
|
@ -1129,6 +1132,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
||||
If it already exists in the file manager, return the existing lbry file
|
||||
"""
|
||||
self._send_download_started(name)
|
||||
helper = _DownloadNameHelper(
|
||||
self, name, timeout, download_directory, file_name, wait_for_write)
|
||||
|
||||
|
|
Loading…
Reference in a new issue