2015-12-24 19:51:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2015-12-26 18:39:54 +00:00
|
|
|
import os
|
2015-12-24 19:51:47 +00:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
2016-01-18 09:00:32 +00:00
|
|
|
import xbmcvfs
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
from utils import window, settings
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
##################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
|
|
|
|
|
|
|
##################################################################################################
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
class ClientInfo(object):
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.addon = xbmcaddon.Addon()
|
|
|
|
|
2016-09-05 03:33:34 +00:00
|
|
|
def get_addon_name(self):
|
2015-12-24 19:51:47 +00:00
|
|
|
# Used for logging
|
|
|
|
return self.addon.getAddonInfo('name').upper()
|
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
@classmethod
|
2016-09-05 03:33:34 +00:00
|
|
|
def get_addon_id(cls):
|
2015-12-24 19:51:47 +00:00
|
|
|
return "plugin.video.emby"
|
|
|
|
|
2016-09-05 03:33:34 +00:00
|
|
|
def get_version(self):
|
2015-12-24 19:51:47 +00:00
|
|
|
return self.addon.getAddonInfo('version')
|
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
@classmethod
|
2016-09-05 03:33:34 +00:00
|
|
|
def get_device_name(cls):
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-06-16 21:24:07 +00:00
|
|
|
if settings('deviceNameOpt') == "false":
|
2015-12-24 19:51:47 +00:00
|
|
|
# Use Kodi's deviceName
|
2016-09-05 03:33:34 +00:00
|
|
|
device_name = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8')
|
2015-12-24 19:51:47 +00:00
|
|
|
else:
|
2016-09-05 03:33:34 +00:00
|
|
|
device_name = settings('deviceName')
|
|
|
|
device_name = device_name.replace("\"", "_")
|
|
|
|
device_name = device_name.replace("/", "_")
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 03:33:34 +00:00
|
|
|
return device_name
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 03:58:46 +00:00
|
|
|
@classmethod
|
|
|
|
def get_platform(cls):
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
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"
|
2016-09-02 06:21:15 +00:00
|
|
|
elif xbmc.getCondVisibility('system.platform.android'):
|
2015-12-24 19:51:47 +00:00
|
|
|
return "Linux/Android"
|
2016-09-05 02:20:47 +00:00
|
|
|
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
|
2016-09-02 06:21:15 +00:00
|
|
|
return "Linux/RPi"
|
2016-09-05 02:20:47 +00:00
|
|
|
elif xbmc.getCondVisibility('system.platform.linux'):
|
2016-09-02 06:21:15 +00:00
|
|
|
return "Linux"
|
2015-12-24 19:51:47 +00:00
|
|
|
else:
|
|
|
|
return "Unknown"
|
|
|
|
|
2016-09-05 03:33:34 +00:00
|
|
|
def get_device_id(self, reset=False):
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
client_id = window('emby_deviceId')
|
|
|
|
if client_id:
|
|
|
|
return client_id
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
emby_guid = xbmc.translatePath("special://temp/emby_guid").decode('utf-8')
|
2016-09-05 03:33:34 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
###$ Begin migration $###
|
|
|
|
if not xbmcvfs.exists(emby_guid):
|
|
|
|
addon_path = self.addon.getAddonInfo('path').decode('utf-8')
|
|
|
|
if os.path.supports_unicode_filenames:
|
|
|
|
path = os.path.join(addon_path, "machine_guid")
|
|
|
|
else:
|
|
|
|
path = os.path.join(addon_path.encode('utf-8'), "machine_guid")
|
2016-09-05 03:33:34 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
guid_file = xbmc.translatePath(path).decode('utf-8')
|
|
|
|
if xbmcvfs.exists(guid_file):
|
|
|
|
xbmcvfs.copy(guid_file, emby_guid)
|
|
|
|
###$ End migration $###
|
|
|
|
|
|
|
|
if reset and xbmcvfs.exists(emby_guid):
|
2016-02-29 05:20:59 +00:00
|
|
|
# Reset the file
|
2016-09-05 02:20:47 +00:00
|
|
|
xbmcvfs.delete(emby_guid)
|
2016-02-29 05:20:59 +00:00
|
|
|
|
2016-09-05 02:20:47 +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" % uuid4())
|
|
|
|
guid = xbmcvfs.File(emby_guid, 'w')
|
|
|
|
guid.write(client_id)
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
guid.close()
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-05 02:20:47 +00:00
|
|
|
log.info("DeviceId loaded: %s", client_id)
|
|
|
|
window('emby_deviceId', value=client_id)
|
|
|
|
|
|
|
|
return client_id
|