2015-12-24 19:51:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2018-05-10 23:21:08 +00:00
|
|
|
import hashlib
|
2015-12-26 18:39:54 +00:00
|
|
|
import os
|
2018-05-10 23:21:08 +00:00
|
|
|
import platform
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
2016-01-18 09:00:32 +00:00
|
|
|
import xbmcvfs
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2018-01-15 02:11:36 +00:00
|
|
|
from utils import window, settings, create_id
|
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):
|
|
|
|
|
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"
|
2015-12-24 19:51:47 +00:00
|
|
|
|
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 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"
|
|
|
|
|
2018-05-10 09:09:25 +00:00
|
|
|
@classmethod
|
2018-05-10 23:21:08 +00:00
|
|
|
def get_device_id(cls):
|
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
|
|
|
|
2018-05-10 23:21:08 +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
|
|
|
if reset and xbmcvfs.exists(emby_guid):
|
|
|
|
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...")
|
2018-01-15 02:11:36 +00:00
|
|
|
client_id = str("%012X" % create_id())
|
2016-09-05 02:20:47 +00:00
|
|
|
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()
|
2018-05-10 23:21:08 +00:00
|
|
|
"""
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2018-05-13 03:44:02 +00:00
|
|
|
guid = ''.join(platform.uname())
|
2018-05-10 23:21:08 +00:00
|
|
|
client_id = hashlib.sha1(guid).hexdigest().upper()
|
|
|
|
|
|
|
|
xbmc.log("EMBY DeviceId: %s" % client_id, level=xbmc.LOGNOTICE)
|
2016-09-05 02:20:47 +00:00
|
|
|
window('emby_deviceId', value=client_id)
|
|
|
|
|
|
|
|
return client_id
|