2015-12-24 19:51:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
|
|
|
|
import clientinfo
|
2016-09-04 10:18:31 +00:00
|
|
|
import connectmanager
|
|
|
|
import connect.connectionmanager as connectionmanager
|
2015-12-24 19:51:47 +00:00
|
|
|
import userclient
|
2016-07-24 08:59:48 +00:00
|
|
|
from utils import settings, language as lang, passwordsXML
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
2016-09-04 10:18:31 +00:00
|
|
|
STATE = connectionmanager.ConnectionState
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
2016-09-04 10:18:31 +00:00
|
|
|
class InitialSetup(object):
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
2016-09-04 10:18:31 +00:00
|
|
|
self.addon_id = clientinfo.ClientInfo().getAddonId()
|
|
|
|
self.user_client = userclient.UserClient()
|
|
|
|
self.connectmanager = connectmanager.ConnectManager()
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
# Check server, user, direct paths, music, direct stream if not direct path.
|
2016-09-04 10:18:31 +00:00
|
|
|
addon_id = self.addon_id
|
2016-06-19 21:24:34 +00:00
|
|
|
dialog = xbmcgui.Dialog()
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
##### SERVER INFO #####
|
2016-09-04 10:18:31 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
log.debug("Initial setup called.")
|
2015-12-24 19:51:47 +00:00
|
|
|
|
2016-09-04 10:18:31 +00:00
|
|
|
###$ Begin transition phase $###
|
|
|
|
if settings('server') == "":
|
|
|
|
current_server = self.user_client.get_server()
|
2016-09-05 00:14:25 +00:00
|
|
|
server = self.connectmanager.get_server(current_server)
|
|
|
|
settings('ServerId', value=server['Id'])
|
2016-09-04 10:18:31 +00:00
|
|
|
self.user_client.get_userid()
|
|
|
|
self.user_client.get_token()
|
|
|
|
###$ End transition phase $###
|
|
|
|
|
2016-09-05 00:14:25 +00:00
|
|
|
if settings('server'):
|
|
|
|
current_state = self.connectmanager.get_state()
|
|
|
|
for server in current_state['Servers']:
|
|
|
|
if server['Id'] == settings('serverId'):
|
|
|
|
server_address = self.connectmanager.get_address(server)
|
|
|
|
self._set_server(server_address, server)
|
|
|
|
self._set_user(server['UserId'], server['AccessToken'])
|
|
|
|
break
|
2015-12-24 19:51:47 +00:00
|
|
|
return
|
2016-09-04 10:18:31 +00:00
|
|
|
|
2015-12-24 19:51:47 +00:00
|
|
|
try:
|
2016-09-04 10:18:31 +00:00
|
|
|
server = self.connectmanager.select_servers()
|
|
|
|
log.info("Server: %s", server)
|
|
|
|
|
|
|
|
except RuntimeError as error:
|
|
|
|
log.exception(error)
|
|
|
|
xbmc.executebuiltin('Addon.OpenSettings(%s)' % addon_id)
|
2015-12-24 19:51:47 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
2016-09-04 10:18:31 +00:00
|
|
|
server_address = self.connectmanager.get_address(server)
|
2016-09-05 00:14:25 +00:00
|
|
|
self._set_server(server_address, server)
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
if not server.get('AccessToken') and not server.get('UserId'):
|
|
|
|
try:
|
|
|
|
user = self.connectmanager.login(server)
|
|
|
|
log.info("User authenticated: %s", user)
|
|
|
|
except RuntimeError as error:
|
|
|
|
log.exception(error)
|
|
|
|
xbmc.executebuiltin('Addon.OpenSettings(%s)' % addon_id)
|
|
|
|
return
|
|
|
|
settings('username', value=user['User']['Name'])
|
|
|
|
self._set_user(user['User']['Id'], user['AccessToken'])
|
|
|
|
else:
|
|
|
|
user = self.connectmanager.get_state()
|
|
|
|
settings('connectUsername', value=user['ConnectUser']['Name'])
|
|
|
|
self._set_user(server['UserId'], server['AccessToken'])
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
##### ADDITIONAL PROMPTS #####
|
|
|
|
|
2016-09-04 10:18:31 +00:00
|
|
|
direct_paths = dialog.yesno(heading=lang(30511),
|
|
|
|
line1=lang(33035),
|
|
|
|
nolabel=lang(33036),
|
|
|
|
yeslabel=lang(33037))
|
|
|
|
if direct_paths:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("User opted to use direct paths.")
|
2016-06-18 03:03:28 +00:00
|
|
|
settings('useDirectPaths', value="1")
|
2015-12-24 19:51:47 +00:00
|
|
|
|
|
|
|
# ask for credentials
|
2016-09-04 10:18:31 +00:00
|
|
|
credentials = dialog.yesno(heading=lang(30517), line1=lang(33038))
|
2015-12-24 19:51:47 +00:00
|
|
|
if credentials:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Presenting network credentials dialog.")
|
2016-06-18 03:03:28 +00:00
|
|
|
passwordsXML()
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
music_disabled = dialog.yesno(heading=lang(29999), line1=lang(33039))
|
|
|
|
if music_disabled:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("User opted to disable Emby music library.")
|
2016-06-18 03:03:28 +00:00
|
|
|
settings('enableMusic', value="false")
|
2015-12-24 19:51:47 +00:00
|
|
|
else:
|
|
|
|
# Only prompt if the user didn't select direct paths for videos
|
2016-09-04 10:18:31 +00:00
|
|
|
if not direct_paths:
|
|
|
|
music_access = dialog.yesno(heading=lang(29999), line1=lang(33040))
|
|
|
|
if music_access:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("User opted to direct stream music.")
|
2016-06-18 03:03:28 +00:00
|
|
|
settings('streamMusic', value="true")
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
@classmethod
|
2016-09-05 00:14:25 +00:00
|
|
|
def _set_server(cls, server_address, server):
|
2016-09-04 10:18:31 +00:00
|
|
|
|
2016-09-05 00:14:25 +00:00
|
|
|
settings('serverName', value=server['Name'])
|
|
|
|
settings('serverId', value=server['Id'])
|
|
|
|
settings('server', value=server_address)
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _set_user(cls, user_id, token):
|
|
|
|
|
|
|
|
settings('userId', value=user_id)
|
|
|
|
settings('token', value=token)
|