2015-07-22 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-04-22 02:31:16 +00:00
|
|
|
|
2015-03-14 02:04:18 +00:00
|
|
|
import os
|
2015-03-15 02:43:06 +00:00
|
|
|
from uuid import uuid4 as uuid4
|
2015-03-14 02:04:18 +00:00
|
|
|
from Lock import Lock
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcgui
|
|
|
|
|
2015-04-22 02:31:16 +00:00
|
|
|
import Utils as utils
|
|
|
|
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
class ClientInformation():
|
|
|
|
|
2015-03-15 02:43:06 +00:00
|
|
|
def __init__(self):
|
2015-03-16 01:24:19 +00:00
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
self.addon = xbmcaddon.Addon()
|
2015-04-22 02:31:16 +00:00
|
|
|
self.addonName = self.getAddonName()
|
2015-03-16 01:24:19 +00:00
|
|
|
|
2015-04-22 02:31:16 +00:00
|
|
|
def logMsg(self, msg, lvl=1):
|
2015-03-16 01:24:19 +00:00
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
className = self.__class__.__name__
|
|
|
|
utils.logMsg("%s %s" % (self.addonName, className), msg, int(lvl))
|
2015-03-15 02:43:06 +00:00
|
|
|
|
|
|
|
def getAddonId(self):
|
|
|
|
# To use when declaring xbmcaddon.Addon(id=addonId)
|
2015-04-22 02:31:16 +00:00
|
|
|
return "plugin.video.emby"
|
2015-03-16 01:24:19 +00:00
|
|
|
|
|
|
|
def getAddonName(self):
|
|
|
|
# Useful for logging
|
2015-04-22 02:31:16 +00:00
|
|
|
return self.addon.getAddonInfo('name').upper()
|
2015-03-15 02:43:06 +00:00
|
|
|
|
|
|
|
def getVersion(self):
|
2015-04-22 02:31:16 +00:00
|
|
|
|
|
|
|
return self.addon.getAddonInfo('version')
|
|
|
|
|
|
|
|
def getDeviceName(self):
|
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
addon = self.addon
|
|
|
|
|
|
|
|
if addon.getSetting('deviceNameOpt') == "false":
|
|
|
|
# Use Kodi's deviceName
|
|
|
|
deviceName = xbmc.getInfoLabel('System.FriendlyName')
|
|
|
|
else:
|
|
|
|
deviceName = addon.getSetting('deviceName')
|
|
|
|
deviceName = deviceName.replace("\"", "_")
|
|
|
|
deviceName = deviceName.replace("/", "_")
|
2015-04-22 02:31:16 +00:00
|
|
|
|
|
|
|
return deviceName
|
2015-03-15 02:43:06 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def getMachineId(self):
|
|
|
|
|
2015-04-22 02:31:16 +00:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
clientId = WINDOW.getProperty("client_id")
|
2015-07-22 13:16:08 +00:00
|
|
|
if clientId:
|
2015-03-14 02:04:18 +00:00
|
|
|
return clientId
|
|
|
|
|
|
|
|
# we need to load and or generate a client machine id
|
2015-07-22 13:16:08 +00:00
|
|
|
addon = self.addon
|
|
|
|
addondir = addon.getAddonInfo('path').decode('utf-8')
|
|
|
|
machine_guid_lock_path = xbmc.translatePath(os.path.join(addondir, "machine_guid.lock")).decode('utf-8')
|
|
|
|
machine_guid_path = xbmc.translatePath(os.path.join(addondir, "machine_guid")).decode('utf-8')
|
2015-03-14 02:04:18 +00:00
|
|
|
clientId = ""
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-14 02:04:18 +00:00
|
|
|
try:
|
|
|
|
lock = Lock(machine_guid_lock_path)
|
|
|
|
locked = lock.acquire()
|
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
if locked:
|
2015-03-14 02:04:18 +00:00
|
|
|
|
|
|
|
fd = os.open(machine_guid_path, os.O_CREAT|os.O_RDWR)
|
|
|
|
clientId = os.read(fd, 256)
|
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
if len(clientId) == 0:
|
2015-03-14 02:04:18 +00:00
|
|
|
uuid = uuid4()
|
|
|
|
clientId = str("%012X" % uuid)
|
2015-04-22 02:31:16 +00:00
|
|
|
self.logMsg("ClientId saved to FILE: %s" % clientId, 2)
|
2015-03-14 02:04:18 +00:00
|
|
|
os.write(fd, clientId)
|
|
|
|
os.fsync(fd)
|
|
|
|
|
|
|
|
os.close(fd)
|
|
|
|
|
2015-04-22 02:31:16 +00:00
|
|
|
self.logMsg("ClientId saved to WINDOW: %s" % clientId, 1)
|
2015-07-22 13:16:08 +00:00
|
|
|
WINDOW.setProperty("client_id", clientId)
|
2015-03-14 02:04:18 +00:00
|
|
|
finally:
|
|
|
|
lock.release()
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
return clientId
|
|
|
|
|
|
|
|
def getPlatform(self):
|
|
|
|
|
|
|
|
if xbmc.getCondVisibility('system.platform.osx'):
|
|
|
|
return "OSX"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.atv2'):
|
|
|
|
return "ATV2"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.ios'):
|
|
|
|
return "iOS"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.windows'):
|
|
|
|
return "Windows"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.linux'):
|
|
|
|
return "Linux/RPi"
|
|
|
|
elif xbmc.getCondVisibility('system.platform.android'):
|
|
|
|
return "Linux/Android"
|
|
|
|
|
2015-07-22 13:16:08 +00:00
|
|
|
return "Unknown"
|