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
|
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):
|
class Events(object):
|
||||||
def __init__(self, context, lbry_id, session_id):
|
def __init__(self, context, lbry_id, session_id):
|
||||||
self.context = context
|
self.context = context
|
||||||
|
@ -19,6 +34,20 @@ class Events(object):
|
||||||
'timestamp': utils.now()
|
'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):
|
def make_context(platform, wallet, is_dev=False):
|
||||||
# TODO: distinguish between developer and release instances
|
# TODO: distinguish between developer and release instances
|
||||||
|
|
|
@ -561,10 +561,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.send_heartbeat.start(60)
|
self.send_heartbeat.start(60)
|
||||||
|
|
||||||
def _send_heartbeat(self):
|
def _send_heartbeat(self):
|
||||||
log.debug('Sending heartbeat')
|
|
||||||
heartbeat = self._events.heartbeat()
|
heartbeat = self._events.heartbeat()
|
||||||
self.analytics_api.track(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):
|
def _get_platform(self):
|
||||||
r = {
|
r = {
|
||||||
"processor": platform.processor(),
|
"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.
|
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
|
If it already exists in the file manager, return the existing lbry file
|
||||||
"""
|
"""
|
||||||
|
self._send_download_started(name)
|
||||||
helper = _DownloadNameHelper(
|
helper = _DownloadNameHelper(
|
||||||
self, name, timeout, download_directory, file_name, wait_for_write)
|
self, name, timeout, download_directory, file_name, wait_for_write)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue