PlexKodiConnect/resources/lib/clientinfo.py

94 lines
2.8 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2016-02-20 06:03:06 +11:00
###############################################################################
from uuid import uuid4
import xbmc
import xbmcaddon
import utils
2016-02-20 06:03:06 +11:00
###############################################################################
2016-01-27 03:20:13 +11:00
@utils.logging
class ClientInfo():
def __init__(self):
self.addon = xbmcaddon.Addon()
def getAddonName(self):
# Used for logging
2015-12-27 23:51:13 +11:00
return self.addon.getAddonInfo('name')
def getAddonId(self):
return "plugin.video.plexkodiconnect"
def getVersion(self):
return self.addon.getAddonInfo('version')
def getDeviceName(self):
if utils.settings('deviceNameOpt') == "false":
# Use Kodi's deviceName
deviceName = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8')
else:
deviceName = utils.settings('deviceName')
deviceName = deviceName.replace("\"", "_")
deviceName = deviceName.replace("/", "_")
return deviceName
def getPlatform(self):
if xbmc.getCondVisibility('system.platform.osx'):
return "MacOSX"
elif xbmc.getCondVisibility('system.platform.atv2'):
return "AppleTV2"
elif xbmc.getCondVisibility('system.platform.ios'):
return "iOS"
elif xbmc.getCondVisibility('system.platform.windows'):
return "Windows"
elif xbmc.getCondVisibility('system.platform.raspberrypi'):
return "RaspberryPi"
elif xbmc.getCondVisibility('system.platform.linux'):
return "Linux"
elif xbmc.getCondVisibility('system.platform.android'):
return "Android"
else:
return "Unknown"
2016-03-01 20:40:30 +11:00
def getDeviceId(self, reset=False):
2016-01-14 20:20:19 +11:00
"""
Returns a unique Plex client id "X-Plex-Client-Identifier" from Kodi
settings file.
Also loads Kodi window property 'plex_client_Id'
If id does not exist, create one and save in Kodi settings file.
"""
2016-03-01 20:40:30 +11:00
if reset is True:
2016-03-01 20:40:30 +11:00
utils.window('plex_client_Id', clear=True)
utils.settings('plex_client_Id', value="")
2016-01-14 20:20:19 +11:00
clientId = utils.window('plex_client_Id')
if clientId:
return clientId
2016-01-14 20:20:19 +11:00
clientId = utils.settings('plex_client_Id')
# Because Kodi appears to cache file settings!!
if clientId != "" and reset is False:
2016-01-14 20:20:19 +11:00
utils.window('plex_client_Id', value=clientId)
self.logMsg("Unique device Id plex_client_Id loaded: %s" % clientId, 1)
return clientId
2016-01-14 20:20:19 +11:00
self.logMsg("Generating a new deviceid.", 0)
clientId = str(uuid4())
utils.settings('plex_client_Id', value=clientId)
utils.window('plex_client_Id', value=clientId)
self.logMsg("Unique device Id plex_client_Id loaded: %s" % clientId, 1)
return clientId