mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-01-24 17:06:11 +00:00
Migrate device id to different location
Moves the file outside of add-on folder so it persists reinstalls.
This commit is contained in:
parent
7b2a7d1e65
commit
d36bb3d232
3 changed files with 46 additions and 41 deletions
|
@ -19,28 +19,26 @@ log = logging.getLogger("EMBY."+__name__)
|
||||||
##################################################################################################
|
##################################################################################################
|
||||||
|
|
||||||
|
|
||||||
class ClientInfo():
|
class ClientInfo(object):
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.addon = xbmcaddon.Addon()
|
self.addon = xbmcaddon.Addon()
|
||||||
self.addonName = self.getAddonName()
|
|
||||||
|
|
||||||
|
|
||||||
def getAddonName(self):
|
def getAddonName(self):
|
||||||
# Used for logging
|
# Used for logging
|
||||||
return self.addon.getAddonInfo('name').upper()
|
return self.addon.getAddonInfo('name').upper()
|
||||||
|
|
||||||
def getAddonId(self):
|
@classmethod
|
||||||
|
def getAddonId(cls):
|
||||||
return "plugin.video.emby"
|
return "plugin.video.emby"
|
||||||
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
|
|
||||||
return self.addon.getAddonInfo('version')
|
return self.addon.getAddonInfo('version')
|
||||||
|
|
||||||
def getDeviceName(self):
|
@classmethod
|
||||||
|
def getDeviceName(cls):
|
||||||
|
|
||||||
if settings('deviceNameOpt') == "false":
|
if settings('deviceNameOpt') == "false":
|
||||||
# Use Kodi's deviceName
|
# Use Kodi's deviceName
|
||||||
|
@ -64,42 +62,49 @@ class ClientInfo():
|
||||||
return "Windows"
|
return "Windows"
|
||||||
elif xbmc.getCondVisibility('system.platform.android'):
|
elif xbmc.getCondVisibility('system.platform.android'):
|
||||||
return "Linux/Android"
|
return "Linux/Android"
|
||||||
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
|
elif xbmc.getCondVisibility('system.platform.linux.raspberrypi'):
|
||||||
return "Linux/RPi"
|
return "Linux/RPi"
|
||||||
elif xbmc.getCondVisibility('system.platform.linux'):
|
elif xbmc.getCondVisibility('system.platform.linux'):
|
||||||
return "Linux"
|
return "Linux"
|
||||||
else:
|
else:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
|
|
||||||
def getDeviceId(self, reset=False):
|
def getDeviceId(self, reset=False):
|
||||||
|
|
||||||
clientId = window('emby_deviceId')
|
client_id = window('emby_deviceId')
|
||||||
if clientId:
|
if client_id:
|
||||||
return clientId
|
return client_id
|
||||||
|
|
||||||
addon_path = self.addon.getAddonInfo('path').decode('utf-8')
|
emby_guid = xbmc.translatePath("special://temp/emby_guid").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")
|
|
||||||
|
|
||||||
GUID_file = xbmc.translatePath(path).decode('utf-8')
|
###$ Begin migration $###
|
||||||
|
if not xbmcvfs.exists(emby_guid):
|
||||||
if reset and xbmcvfs.exists(GUID_file):
|
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")
|
||||||
|
|
||||||
|
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):
|
||||||
# Reset the file
|
# Reset the file
|
||||||
xbmcvfs.delete(GUID_file)
|
xbmcvfs.delete(emby_guid)
|
||||||
|
|
||||||
GUID = xbmcvfs.File(GUID_file)
|
guid = xbmcvfs.File(emby_guid)
|
||||||
clientId = GUID.read()
|
client_id = guid.read()
|
||||||
if not clientId:
|
if not client_id:
|
||||||
log.info("Generating a new deviceid...")
|
log.info("Generating a new guid...")
|
||||||
clientId = str("%012X" % uuid4())
|
client_id = str("%012X" % uuid4())
|
||||||
GUID = xbmcvfs.File(GUID_file, 'w')
|
guid = xbmcvfs.File(emby_guid, 'w')
|
||||||
GUID.write(clientId)
|
guid.write(client_id)
|
||||||
|
|
||||||
GUID.close()
|
guid.close()
|
||||||
|
|
||||||
log.info("DeviceId loaded: %s" % clientId)
|
log.info("DeviceId loaded: %s", client_id)
|
||||||
window('emby_deviceId', value=clientId)
|
window('emby_deviceId', value=client_id)
|
||||||
|
|
||||||
return clientId
|
return client_id
|
||||||
|
|
|
@ -40,14 +40,14 @@ class InitialSetup(object):
|
||||||
|
|
||||||
log.debug("Initial setup called.")
|
log.debug("Initial setup called.")
|
||||||
|
|
||||||
###$ Begin transition phase $###
|
###$ Begin migration $###
|
||||||
if settings('server') == "":
|
if settings('server') == "":
|
||||||
current_server = self.user_client.get_server()
|
current_server = self.user_client.get_server()
|
||||||
server = self.connectmanager.get_server(current_server)
|
server = self.connectmanager.get_server(current_server)
|
||||||
settings('ServerId', value=server['Id'])
|
settings('ServerId', value=server['Id'])
|
||||||
self.user_client.get_userid()
|
self.user_client.get_userid()
|
||||||
self.user_client.get_token()
|
self.user_client.get_token()
|
||||||
###$ End transition phase $###
|
###$ End migration $###
|
||||||
|
|
||||||
if settings('server'):
|
if settings('server'):
|
||||||
current_state = self.connectmanager.get_state()
|
current_state = self.connectmanager.get_state()
|
||||||
|
|
|
@ -60,7 +60,7 @@ class UserClient(threading.Thread):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_server(cls):
|
def get_server(cls):
|
||||||
|
|
||||||
###$ Begin transition phase $###
|
###$ Begin migration $###
|
||||||
if settings('server') == "":
|
if settings('server') == "":
|
||||||
http = "https" if settings('https') == "true" else "http"
|
http = "https" if settings('https') == "true" else "http"
|
||||||
host = settings('ipaddress')
|
host = settings('ipaddress')
|
||||||
|
@ -68,7 +68,7 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
if host and port:
|
if host and port:
|
||||||
settings('server', value="%s://%s:%s" % (http, host, port))
|
settings('server', value="%s://%s:%s" % (http, host, port))
|
||||||
###$ End transition phase $###
|
###$ End migration $###
|
||||||
|
|
||||||
return settings('server') or None
|
return settings('server') or None
|
||||||
|
|
||||||
|
@ -120,20 +120,20 @@ class UserClient(threading.Thread):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_userid(cls):
|
def get_userid(cls):
|
||||||
|
|
||||||
###$ Begin transition phase $###
|
###$ Begin migration $###
|
||||||
if settings('userId') == "":
|
if settings('userId') == "":
|
||||||
settings('userId', value=settings('userId%s' % settings('username')))
|
settings('userId', value=settings('userId%s' % settings('username')))
|
||||||
###$ End transition phase $###
|
###$ End migration $###
|
||||||
|
|
||||||
return settings('userId') or None
|
return settings('userId') or None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_token(cls):
|
def get_token(cls):
|
||||||
|
|
||||||
###$ Begin transition phase $###
|
###$ Begin migration $###
|
||||||
if settings('token') == "":
|
if settings('token') == "":
|
||||||
settings('token', value=settings('accessToken'))
|
settings('token', value=settings('accessToken'))
|
||||||
###$ End transition phase $###
|
###$ End migration $###
|
||||||
|
|
||||||
return settings('token') or None
|
return settings('token') or None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue