2016-10-09 22:05:51 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2016-10-10 02:02:23 +00:00
|
|
|
import traceback
|
2016-10-09 09:14:45 +00:00
|
|
|
import requests
|
|
|
|
import logging
|
|
|
|
import clientinfo
|
|
|
|
import md5
|
2016-10-15 02:56:05 +00:00
|
|
|
import xbmc
|
|
|
|
import platform
|
2016-10-14 03:35:34 +00:00
|
|
|
import xbmcgui
|
2016-10-09 09:14:45 +00:00
|
|
|
from utils import window, settings, language as lang
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
|
|
|
|
2016-10-13 00:47:43 +00:00
|
|
|
# for info on the metrics that can be sent to Google Analytics
|
|
|
|
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#events
|
|
|
|
|
2016-10-09 09:14:45 +00:00
|
|
|
class GoogleAnalytics():
|
|
|
|
|
2016-10-10 02:44:06 +00:00
|
|
|
testing = False
|
2016-10-09 09:14:45 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
client_info = clientinfo.ClientInfo()
|
|
|
|
self.version = client_info.get_version()
|
2016-10-15 02:56:05 +00:00
|
|
|
self.device_id = client_info.get_device_id()
|
|
|
|
self.userAgent = "Kodi (" + self.getUserAgentOS() + ")"
|
2016-10-09 09:14:45 +00:00
|
|
|
|
|
|
|
# Use set user name
|
|
|
|
self.user_name = settings('username') or settings('connectUsername') or 'None'
|
|
|
|
|
|
|
|
# use md5 for client and user for analytics
|
|
|
|
self.device_id = md5.new(self.device_id).hexdigest()
|
|
|
|
self.user_name = md5.new(self.user_name).hexdigest()
|
2016-10-14 03:35:34 +00:00
|
|
|
|
|
|
|
# resolution
|
|
|
|
self.height = xbmcgui.Window(10000).getHeight()
|
|
|
|
self.width = xbmcgui.Window(10000).getWidth()
|
2016-10-09 09:14:45 +00:00
|
|
|
|
2016-10-15 02:56:05 +00:00
|
|
|
def getUserAgentOS(self):
|
|
|
|
|
|
|
|
return platform.system()
|
|
|
|
|
|
|
|
'''
|
|
|
|
if xbmc.getCondVisibility('system.platform.osx'):
|
|
|
|
return "OSX"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.ios'):
|
|
|
|
return "iOS"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.windows'):
|
|
|
|
return "Windows"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.android'):
|
|
|
|
return "Android"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
|
|
|
|
return "Linux"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.linux'):
|
|
|
|
return "Linux"
|
|
|
|
else:
|
|
|
|
return platform.system()
|
|
|
|
'''
|
|
|
|
|
2016-10-09 22:05:51 +00:00
|
|
|
def formatException(self):
|
|
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
2016-10-10 02:02:23 +00:00
|
|
|
|
|
|
|
stackFrames = traceback.extract_tb(exc_tb)
|
|
|
|
if(len(stackFrames) > 0):
|
|
|
|
stackFrames = traceback.extract_tb(exc_tb)[-1]
|
|
|
|
else:
|
|
|
|
stackFrames = None
|
|
|
|
log.error(str(stackFrames))
|
|
|
|
|
|
|
|
errorType = "NA"
|
|
|
|
errorFile = "NA"
|
|
|
|
|
|
|
|
if(stackFrames != None):
|
|
|
|
fileName = os.path.split(stackFrames[0])[1]
|
|
|
|
|
2016-10-13 04:01:09 +00:00
|
|
|
errorFile = "%s:%s(%s)(%s)" % (fileName, stackFrames[1], exc_obj.message, stackFrames[3].strip())
|
|
|
|
errorFile = errorFile[0:499]
|
2016-10-10 02:02:23 +00:00
|
|
|
errorType = "%s" % (exc_type.__name__)
|
|
|
|
del(exc_type, exc_obj, exc_tb)
|
|
|
|
log.error(errorType + " - " + errorFile)
|
|
|
|
|
2016-10-09 22:50:30 +00:00
|
|
|
return errorType, errorFile
|
2016-10-09 22:05:51 +00:00
|
|
|
|
2016-10-09 22:50:30 +00:00
|
|
|
def sendEventData(self, eventCategory, eventAction, eventLabel=None):
|
2016-10-13 00:47:43 +00:00
|
|
|
|
2016-10-09 09:14:45 +00:00
|
|
|
# all the data we can send to Google Analytics
|
|
|
|
data = {}
|
|
|
|
data['v'] = '1'
|
|
|
|
data['tid'] = 'UA-85356267-1' # tracking id, this is the account ID
|
|
|
|
|
|
|
|
data['ds'] = 'plugin' # data source
|
|
|
|
|
|
|
|
data['an'] = 'Kodi4Emby' # App Name
|
|
|
|
data['aid'] = '1' # App ID
|
|
|
|
data['av'] = self.version # App Version
|
|
|
|
#data['aiid'] = '1.1' # App installer ID
|
|
|
|
|
|
|
|
data['cid'] = self.device_id # Client ID
|
2016-10-12 05:16:05 +00:00
|
|
|
#data['uid'] = self.user_name # User ID
|
2016-10-09 09:14:45 +00:00
|
|
|
|
2016-10-15 02:56:05 +00:00
|
|
|
data['ua'] = self.userAgent # user agent string
|
2016-10-09 09:14:45 +00:00
|
|
|
|
|
|
|
data['t'] = 'event' # action type
|
|
|
|
data['ec'] = eventCategory # Event Category
|
|
|
|
data['ea'] = eventAction # Event Action
|
2016-10-14 03:35:34 +00:00
|
|
|
|
|
|
|
# add width and height
|
|
|
|
data['sr'] = str(self.width) + "x" + str(self.height)
|
2016-10-09 22:50:30 +00:00
|
|
|
|
|
|
|
if(eventLabel != None):
|
|
|
|
data['el'] = eventLabel # Event Label
|
2016-10-09 09:14:45 +00:00
|
|
|
|
2016-10-13 00:47:43 +00:00
|
|
|
self.sendData(data)
|
|
|
|
|
|
|
|
def sendData(self, data):
|
|
|
|
|
2016-10-09 11:49:46 +00:00
|
|
|
log.info("GA: " + str(data))
|
2016-10-09 09:14:45 +00:00
|
|
|
|
2016-10-13 00:47:43 +00:00
|
|
|
if(settings('metricLogging') == "false"):
|
|
|
|
return
|
|
|
|
|
2016-10-09 09:14:45 +00:00
|
|
|
if(self.testing):
|
|
|
|
url = "https://www.google-analytics.com/debug/collect" # test URL
|
|
|
|
else:
|
|
|
|
url = "https://www.google-analytics.com/collect" # prod URL
|
|
|
|
|
2016-10-09 11:49:46 +00:00
|
|
|
try:
|
|
|
|
r = requests.post(url, data)
|
|
|
|
except Exception as error:
|
|
|
|
log.error(error)
|
2016-10-09 09:14:45 +00:00
|
|
|
|
|
|
|
if(self.testing):
|
2016-10-09 22:05:51 +00:00
|
|
|
log.info("GA: " + r.text.encode('utf-8'))
|
2016-10-13 00:47:43 +00:00
|
|
|
|
|
|
|
|
2016-10-09 09:14:45 +00:00
|
|
|
|