jellyfin-kodi/resources/lib/clientinfo.py

98 lines
2.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#################################################################################################
import logging
2015-12-26 18:39:54 +00:00
import os
import xbmc
import xbmcaddon
import xbmcvfs
from utils import window, settings, create_id
##################################################################################################
log = logging.getLogger("EMBY."+__name__)
##################################################################################################
class ClientInfo(object):
def __init__(self):
2016-09-25 02:34:11 +00:00
self.addon = xbmcaddon.Addon(self.get_addon_id())
@staticmethod
def get_addon_id():
return "plugin.video.emby"
def get_addon_name(self):
# Used for logging
return self.addon.getAddonInfo('name').upper()
def get_version(self):
return self.addon.getAddonInfo('version')
@classmethod
def get_device_name(cls):
2016-06-16 21:24:07 +00:00
if settings('deviceNameOpt') == "false":
# Use Kodi's deviceName
device_name = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8')
else:
device_name = settings('deviceName')
device_name = device_name.replace("\"", "_")
device_name = device_name.replace("/", "_")
return device_name
2016-09-05 03:58:46 +00:00
@classmethod
def get_platform(cls):
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.android'):
return "Linux/Android"
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
return "Linux/RPi"
elif xbmc.getCondVisibility('system.platform.linux'):
return "Linux"
else:
return "Unknown"
@classmethod
2018-05-16 22:46:38 +00:00
def get_device_id(cls, reset=False):
client_id = window('emby_deviceId')
if client_id:
return client_id
emby_guid = xbmc.translatePath("special://temp/emby_guid").decode('utf-8')
if reset and xbmcvfs.exists(emby_guid):
xbmcvfs.delete(emby_guid)
2016-02-29 05:20:59 +00:00
guid = xbmcvfs.File(emby_guid)
client_id = guid.read()
if not client_id:
log.info("Generating a new guid...")
client_id = str("%012X" % create_id())
guid = xbmcvfs.File(emby_guid, 'w')
guid.write(client_id)
guid.close()
2018-05-16 22:46:38 +00:00
log.info("DeviceId loaded: %s", client_id)
window('emby_deviceId', value=client_id)
return client_id