Пример #1
0
    def register_client(self, credentials=None, options=None, server_id=None, server_selection=False):

        client = self.get_client(server_id)
        self.client = client
        self.connect_manager = client.auth

        if server_id is None:
            client.config.data['app.default'] = True

        try:
            state = client.authenticate(credentials or {}, options or {})

            if state['State'] == CONNECTION_STATE['SignedIn']:
                client.callback_ws = event

                if server_id is None:  # Only assign for default server

                    client.callback = event
                    self.get_user(client)

                    settings('serverName', client.config.data['auth.server-name'])
                    settings('server', client.config.data['auth.server'])

                event('ServerOnline', {'ServerId': server_id})
                event('LoadServer', {'ServerId': server_id})

                return state['Credentials']

            elif (server_selection or state['State'] == CONNECTION_STATE['ServerSelection'] or state['State'] == CONNECTION_STATE['Unavailable'] and not settings('SyncInstallRunDone.bool')):

                self.select_servers(state)

            elif state['State'] == CONNECTION_STATE['ServerSignIn']:
                if 'ExchangeToken' not in state['Servers'][0]:
                    self.login()

            elif state['State'] == CONNECTION_STATE['Unavailable'] and state['Status_Code'] == 401:
                # If the saved credentials don't work, restart the addon to force the password dialog to open
                window('jellyfin.restart', clear=True)

            elif state['State'] == CONNECTION_STATE['Unavailable']:
                raise HTTPException('ServerUnreachable', {})

            return self.register_client(state['Credentials'], options, server_id, False)

        except RuntimeError as error:

            LOG.exception(error)
            xbmc.executebuiltin('Addon.OpenSettings(%s)' % addon_id())

            raise Exception('User sign in interrupted')

        except HTTPException as error:

            if error.status == 'ServerUnreachable':
                event('ServerUnreachable', {'ServerId': server_id})

            return client.get_credentials()
Пример #2
0
    def _add_editcontrol(self, x, y, height, width, password=0):

        media = os.path.join(xbmcaddon.Addon(addon_id()).getAddonInfo('path'), 'resources', 'skins', 'default', 'media')
        control = xbmcgui.ControlImage(0, 0, 0, 0,
                                       filename=os.path.join(media, "white.png"),
                                       aspectRatio=0,
                                       colorDiffuse="ff111111")
        control.setPosition(x, y)
        control.setHeight(height)
        control.setWidth(width)

        self.addControl(control)
        return control
Пример #3
0
    def _add_editcontrol(self, x, y, height, width):

        media = os.path.join(xbmcaddon.Addon(addon_id()).getAddonInfo('path'), 'resources', 'skins', 'default', 'media')
        control = xbmcgui.ControlEdit(0, 0, 0, 0,
                                      label="User",
                                      font="font13",
                                      textColor="FF00A4DC",
                                      disabledColor="FF888888",
                                      focusTexture="-",
                                      noFocusTexture="-")
        control.setPosition(x, y)
        control.setHeight(height)
        control.setWidth(width)

        self.addControl(control)
        return control
Пример #4
0
def get_version():
    return xbmcaddon.Addon(addon_id()).getAddonInfo('version')
Пример #5
0
def get_addon_name():
    
    ''' Used for logging.
    '''
    return xbmcaddon.Addon(addon_id()).getAddonInfo('name').upper()
Пример #6
0
from kodi_six import xbmc, xbmcaddon

import client
from database import get_credentials, save_credentials
from dialogs import ServerConnect, UsersConnect, LoginManual, ServerManual
from helper import settings, addon_id, event, api, window
from jellyfin import Jellyfin
from jellyfin.connection_manager import CONNECTION_STATE
from jellyfin.exceptions import HTTPException
from helper import LazyLogger

##################################################################################################

LOG = LazyLogger(__name__)
XML_PATH = (xbmcaddon.Addon(addon_id()).getAddonInfo('path'), "default",
            "1080i")

##################################################################################################


class Connect(object):
    def __init__(self):
        self.info = client.get_info()

    def register(self, server_id=None, options={}):
        ''' Login into server. If server is None, then it will show the proper prompts to login, etc.
            If a server id is specified then only a login dialog will be shown for that server.
        '''
        LOG.info("--[ server/%s ]", server_id or 'default')
        credentials = dict(get_credentials())