mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04: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):
|
||||
|
||||
self.addon = xbmcaddon.Addon()
|
||||
self.addonName = self.getAddonName()
|
||||
|
||||
|
||||
def getAddonName(self):
|
||||
# Used for logging
|
||||
return self.addon.getAddonInfo('name').upper()
|
||||
|
||||
def getAddonId(self):
|
||||
|
||||
@classmethod
|
||||
def getAddonId(cls):
|
||||
return "plugin.video.emby"
|
||||
|
||||
def getVersion(self):
|
||||
|
||||
return self.addon.getAddonInfo('version')
|
||||
|
||||
def getDeviceName(self):
|
||||
@classmethod
|
||||
def getDeviceName(cls):
|
||||
|
||||
if settings('deviceNameOpt') == "false":
|
||||
# Use Kodi's deviceName
|
||||
|
@ -73,33 +71,40 @@ class ClientInfo():
|
|||
|
||||
def getDeviceId(self, reset=False):
|
||||
|
||||
clientId = window('emby_deviceId')
|
||||
if clientId:
|
||||
return clientId
|
||||
client_id = window('emby_deviceId')
|
||||
if client_id:
|
||||
return client_id
|
||||
|
||||
emby_guid = xbmc.translatePath("special://temp/emby_guid").decode('utf-8')
|
||||
|
||||
###$ 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")
|
||||
|
||||
GUID_file = xbmc.translatePath(path).decode('utf-8')
|
||||
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(GUID_file):
|
||||
if reset and xbmcvfs.exists(emby_guid):
|
||||
# Reset the file
|
||||
xbmcvfs.delete(GUID_file)
|
||||
xbmcvfs.delete(emby_guid)
|
||||
|
||||
GUID = xbmcvfs.File(GUID_file)
|
||||
clientId = GUID.read()
|
||||
if not clientId:
|
||||
log.info("Generating a new deviceid...")
|
||||
clientId = str("%012X" % uuid4())
|
||||
GUID = xbmcvfs.File(GUID_file, 'w')
|
||||
GUID.write(clientId)
|
||||
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)
|
||||
|
||||
GUID.close()
|
||||
guid.close()
|
||||
|
||||
log.info("DeviceId loaded: %s" % clientId)
|
||||
window('emby_deviceId', value=clientId)
|
||||
log.info("DeviceId loaded: %s", client_id)
|
||||
window('emby_deviceId', value=client_id)
|
||||
|
||||
return clientId
|
||||
return client_id
|
||||
|
|
|
@ -40,14 +40,14 @@ class InitialSetup(object):
|
|||
|
||||
log.debug("Initial setup called.")
|
||||
|
||||
###$ Begin transition phase $###
|
||||
###$ Begin migration $###
|
||||
if settings('server') == "":
|
||||
current_server = self.user_client.get_server()
|
||||
server = self.connectmanager.get_server(current_server)
|
||||
settings('ServerId', value=server['Id'])
|
||||
self.user_client.get_userid()
|
||||
self.user_client.get_token()
|
||||
###$ End transition phase $###
|
||||
###$ End migration $###
|
||||
|
||||
if settings('server'):
|
||||
current_state = self.connectmanager.get_state()
|
||||
|
|
|
@ -60,7 +60,7 @@ class UserClient(threading.Thread):
|
|||
@classmethod
|
||||
def get_server(cls):
|
||||
|
||||
###$ Begin transition phase $###
|
||||
###$ Begin migration $###
|
||||
if settings('server') == "":
|
||||
http = "https" if settings('https') == "true" else "http"
|
||||
host = settings('ipaddress')
|
||||
|
@ -68,7 +68,7 @@ class UserClient(threading.Thread):
|
|||
|
||||
if host and port:
|
||||
settings('server', value="%s://%s:%s" % (http, host, port))
|
||||
###$ End transition phase $###
|
||||
###$ End migration $###
|
||||
|
||||
return settings('server') or None
|
||||
|
||||
|
@ -120,20 +120,20 @@ class UserClient(threading.Thread):
|
|||
@classmethod
|
||||
def get_userid(cls):
|
||||
|
||||
###$ Begin transition phase $###
|
||||
###$ Begin migration $###
|
||||
if settings('userId') == "":
|
||||
settings('userId', value=settings('userId%s' % settings('username')))
|
||||
###$ End transition phase $###
|
||||
###$ End migration $###
|
||||
|
||||
return settings('userId') or None
|
||||
|
||||
@classmethod
|
||||
def get_token(cls):
|
||||
|
||||
###$ Begin transition phase $###
|
||||
###$ Begin migration $###
|
||||
if settings('token') == "":
|
||||
settings('token', value=settings('accessToken'))
|
||||
###$ End transition phase $###
|
||||
###$ End migration $###
|
||||
|
||||
return settings('token') or None
|
||||
|
||||
|
|
Loading…
Reference in a new issue