2015-12-25 06:51:47 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
import logging
|
2015-12-27 05:39:54 +11:00
|
|
|
import os
|
2015-12-25 06:51:47 +11:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
2016-01-18 20:00:32 +11:00
|
|
|
import xbmcvfs
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
from utils import window, settings
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
##################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
|
|
|
|
|
|
|
##################################################################################################
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
|
|
|
|
class ClientInfo():
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.addon = xbmcaddon.Addon()
|
|
|
|
self.addonName = self.getAddonName()
|
|
|
|
|
|
|
|
|
|
|
|
def getAddonName(self):
|
|
|
|
# Used for logging
|
|
|
|
return self.addon.getAddonInfo('name').upper()
|
|
|
|
|
|
|
|
def getAddonId(self):
|
|
|
|
|
|
|
|
return "plugin.video.emby"
|
|
|
|
|
|
|
|
def getVersion(self):
|
|
|
|
|
|
|
|
return self.addon.getAddonInfo('version')
|
|
|
|
|
|
|
|
def getDeviceName(self):
|
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
if settings('deviceNameOpt') == "false":
|
2015-12-25 06:51:47 +11:00
|
|
|
# Use Kodi's deviceName
|
2016-01-22 12:19:25 +11:00
|
|
|
deviceName = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8')
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
2016-06-17 07:24:07 +10:00
|
|
|
deviceName = settings('deviceName')
|
2015-12-25 06:51:47 +11:00
|
|
|
deviceName = deviceName.replace("\"", "_")
|
|
|
|
deviceName = deviceName.replace("/", "_")
|
|
|
|
|
|
|
|
return deviceName
|
|
|
|
|
|
|
|
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"
|
|
|
|
else:
|
|
|
|
return "Unknown"
|
|
|
|
|
2016-02-29 16:20:59 +11:00
|
|
|
def getDeviceId(self, reset=False):
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
clientId = window('emby_deviceId')
|
2015-12-25 06:51:47 +11:00
|
|
|
if clientId:
|
|
|
|
return clientId
|
|
|
|
|
|
|
|
addon_path = self.addon.getAddonInfo('path').decode('utf-8')
|
2016-01-30 10:53:52 +11:00
|
|
|
if os.path.supports_unicode_filenames:
|
2016-06-17 07:24:07 +10:00
|
|
|
path = os.path.join(addon_path, "machine_guid")
|
2016-01-30 10:53:52 +11:00
|
|
|
else:
|
2016-06-17 07:24:07 +10:00
|
|
|
path = os.path.join(addon_path.encode('utf-8'), "machine_guid")
|
|
|
|
|
|
|
|
GUID_file = xbmc.translatePath(path).decode('utf-8')
|
|
|
|
|
2016-02-29 16:20:59 +11:00
|
|
|
if reset and xbmcvfs.exists(GUID_file):
|
|
|
|
# Reset the file
|
|
|
|
xbmcvfs.delete(GUID_file)
|
|
|
|
|
2016-01-30 11:13:13 +11:00
|
|
|
GUID = xbmcvfs.File(GUID_file)
|
|
|
|
clientId = GUID.read()
|
|
|
|
if not clientId:
|
2016-07-24 18:59:48 +10:00
|
|
|
log.info("Generating a new deviceid...")
|
2015-12-25 06:51:47 +11:00
|
|
|
clientId = str("%012X" % uuid4())
|
2016-01-30 10:53:52 +11:00
|
|
|
GUID = xbmcvfs.File(GUID_file, 'w')
|
2015-12-25 06:51:47 +11:00
|
|
|
GUID.write(clientId)
|
|
|
|
|
2016-01-30 11:13:13 +11:00
|
|
|
GUID.close()
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
log.info("DeviceId loaded: %s" % clientId)
|
2016-06-17 07:24:07 +10:00
|
|
|
window('emby_deviceId', value=clientId)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
return clientId
|