Beispiel #1
0
    def __init__(self):

        logging.StreamHandler.__init__(self)
        self.setFormatter(MyFormatter())

        self.sensitive = {'Token': [], 'Server': []}

        for server in database.get_credentials()['Servers']:

            if server.get('AccessToken'):
                self.sensitive['Token'].append(server['AccessToken'])

            if server.get('LocalAddress'):
                self.sensitive['Server'].append(
                    server['LocalAddress'].split('://')[1])

            if server.get('RemoteAddress'):
                self.sensitive['Server'].append(
                    server['RemoteAddress'].split('://')[1])

            if server.get('ManualAddress'):
                self.sensitive['Server'].append(
                    server['ManualAddress'].split('://')[1])

        self.mask_info = settings('maskInfo.bool')
Beispiel #2
0
    def _save_servers(self, new_servers, default=False):
        credentials = get_credentials()

        if not new_servers:
            return credentials

        for new_server in new_servers:
            for server in credentials['Servers']:

                if server['Id'] == new_server['Id']:
                    server.update(new_server)

                    if default:
                        credentials['Servers'].remove(server)
                        credentials['Servers'].insert(0, server)

                    break
            else:
                if default:
                    credentials['Servers'].insert(0, new_server)
                else:
                    credentials['Servers'].append(new_server)

        if default:
            default_server = new_servers[0]

            for server in credentials['Servers']:

                if server['Id'] == default_server['Id']:
                    credentials['Servers'].remove(server)

            credentials['Servers'].insert(0, default_server)

        return credentials
Beispiel #3
0
    def remove_server(self, server_id):
        ''' Stop client and remove server.
        '''
        Jellyfin(server_id).close()
        credentials = get_credentials()

        for server in credentials['Servers']:
            if server['Id'] == server_id:
                credentials['Servers'].remove(server)

                break

        save_credentials(credentials)
        LOG.info("[ remove server ] %s", server_id)
Beispiel #4
0
    def setup_manual_server(self):
        ''' Setup manual servers
        '''
        client = self.get_client()
        client.set_credentials(get_credentials())
        manager = client.auth

        try:
            self.manual_server(manager)
        except RuntimeError:
            return

        credentials = client.get_credentials()
        save_credentials(credentials)
Beispiel #5
0
    def setup_login_manual(self):
        ''' Setup manual login by itself for default server.
        '''
        client = self.get_client()
        client.set_credentials(get_credentials())
        manager = client.auth

        try:
            self.login_manual(manager=manager)
        except RuntimeError:
            return

        credentials = client.get_credentials()
        save_credentials(credentials)
Beispiel #6
0
    def setup_login_connect(self):
        ''' Setup emby connect by itself.
        '''
        client = self.get_client()
        client.set_credentials(get_credentials())
        manager = client.auth

        try:
            self.login_connect(manager)
        except RuntimeError:
            return

        credentials = client.get_credentials()
        save_credentials(credentials)
Beispiel #7
0
    def set_ssl(self, server_id):
        ''' Allow user to setup ssl verification for additional servers.
        '''
        value = dialog("yesno", heading="{emby}", line1=_(33217))
        credentials = get_credentials()

        for server in credentials['Servers']:

            if server['Id'] == server_id:
                server['verify'] = bool(value)

                break

        save_credentials(credentials)
        LOG.info("[ ssl/%s/%s ]", server_id, server['verify'])
Beispiel #8
0
    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')

        if (server_id) in self.pending:
            LOG.info("[ server/%s ] is already being registered", server_id
                     or 'default')

            return

        self.pending.append(server_id)
        credentials = get_credentials()

        if server_id is None and credentials['Servers']:
            credentials['Servers'] = [credentials['Servers'][0]]

        elif credentials['Servers']:
            for server in credentials['Servers']:

                if server['Id'] == server_id:
                    credentials['Servers'] = [server]

        server_select = True if server_id is None and not settings(
            'SyncInstallRunDone.bool') else False

        try:
            new_credentials = self.register_client(credentials, options,
                                                   server_id, server_select)
            credentials = self._save_servers(new_credentials['Servers'],
                                             server_id is None)
            new_credentials.update(credentials)
            save_credentials(new_credentials)
            Emby(server_id).start(not bool(server_id), True)
        except HTTPException as error:

            if error.status == 'ServerUnreachable':
                self.pending.remove(server_id)

                raise

        except ValueError as error:
            LOG.error(error)

        self.pending.remove(server_id)
Beispiel #9
0
    def setup_login_manual(self):
        ''' Setup manual login by itself for default server.
        '''
        credentials = get_credentials()
        client = self.get_client(
            credentials['Servers'][0] if credentials['Servers'] else {})
        client.set_credentials(credentials)
        manager = client.auth

        try:
            self.login_manual(manager=manager)
        except RuntimeError:
            return

        new_credentials = client.get_credentials()
        credentials = self._save_servers(new_credentials['Servers'])
        save_credentials(credentials)
Beispiel #10
0
    def setup_login_connect(self):
        ''' Setup emby connect by itself.
        '''
        credentials = get_credentials()
        client = self.get_client(
            credentials['Servers'][0] if credentials['Servers'] else {})
        client.set_credentials(credentials)
        manager = client.auth

        try:
            self.login_connect(manager)
        except RuntimeError:
            return

        new_credentials = client.get_credentials()
        credentials = self._save_servers(new_credentials['Servers'])
        save_credentials(credentials)
Beispiel #11
0
    def setup_manual_server(self):
        ''' Setup manual servers
        '''
        credentials = get_credentials()
        client = self.get_client(
            credentials['Servers'][0] if credentials['Servers'] else {})
        client.set_credentials(credentials)
        manager = client.auth

        try:
            self.manual_server(manager)
        except RuntimeError:
            return

        new_credentials = client.get_credentials()
        credentials = self._save_servers(new_credentials['Servers'])
        save_credentials(credentials)
Beispiel #12
0
    def __init__(self):

        logging.StreamHandler.__init__(self)
        self.setFormatter(MyFormatter())

        self.sensitive = {'Token': [], 'Server': []}

        for server in database.get_credentials()['Servers']:

            if server.get('AccessToken'):
                self.sensitive['Token'].append(server['AccessToken'])

            if server.get('address'):
                self.sensitive['Server'].append(
                    server['address'].split('://')[1])

        self.mask_info = settings('maskInfo.bool')

        if kodi_version() > 18:
            self.level = xbmc.LOGINFO
        else:
            self.level = xbmc.LOGNOTICE
Beispiel #13
0
    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())
        servers = credentials['Servers']

        if server_id is None and credentials['Servers']:
            credentials['Servers'] = [credentials['Servers'][0]]

        elif credentials['Servers']:

            for server in credentials['Servers']:

                if server['Id'] == server_id:
                    credentials['Servers'] = [server]

        server_select = True if server_id is None and not settings(
            'SyncInstallRunDone.bool') else False
        new_credentials = self.register_client(credentials, options, server_id,
                                               server_select)

        for server in servers:
            if server['Id'] == new_credentials['Servers'][0]['Id']:
                server = new_credentials['Servers'][0]

                break
        else:
            servers = new_credentials['Servers']

        credentials['Servers'] = servers
        save_credentials(credentials)

        try:
            Jellyfin(server_id).start(True)
        except ValueError as error:
            LOG.error(error)
Beispiel #14
0
def run_vault():
    """
    Runs the program
    :return:
    """
    response = input(
        "Type 1 to add credentials to the vault \nType 2 to view your vault \nType 3 to retrieve a "
        "password \n")
    response = str(response)

    while response != "1" and response != "2" and response != "3":
        print("That is not a valid function, try again")
        response = input(
            "Type 1 to add credentials to the vault \nType 2 to view your vault \nType 3 to retrieve a "
            "password \n")

    if response == "1":
        website = input(
            "Please enter the website you would like to store your credentials for:"
        )
        email = input("Please enter the email you use to login")
        password = input("Please enter the password you use to login")

        encrypted = e.encrypt(password)

        database.update(website, email, encrypted)
    elif response == "2":
        database.view_db()
    elif response == "3":
        database.view_db()
        website_id = input(
            "Please input the ID you would like your credentials for as a number:\n"
        )
        credentials = database.get_credentials(website_id)
        print("Your credentials for " + credentials[0] + ":\nEmail: " +
              credentials[1] + "\nPassword: " + credentials[2])
    return 0
Beispiel #15
0
def listing():

    ''' Display all emby nodes and dynamic entries when appropriate.
    '''
    total = int(window('Emby.nodes.total') or 0)
    sync = get_sync()
    whitelist = [x.replace('Mixed:', "") for x in sync['Whitelist']]
    servers = get_credentials()['Servers'][1:]

    for i in range(total):

        window_prop = "Emby.nodes.%s" % i
        path = window('%s.index' % window_prop)

        if not path:
            path = window('%s.content' % window_prop) or window('%s.path' % window_prop)

        label = window('%s.title' % window_prop)
        node = window('%s.type' % window_prop)
        artwork = window('%s.artwork' % window_prop)
        view_id = window('%s.id' % window_prop)
        context = []

        if view_id and node in ('movies', 'tvshows', 'musicvideos', 'music', 'mixed') and view_id not in whitelist:
            label = "%s %s" % (label.decode('utf-8'), _(33166))
            context.append((_(33123), "RunPlugin(plugin://plugin.video.emby/?mode=synclib&id=%s)" % view_id))

        if view_id and node in ('movies', 'tvshows', 'musicvideos', 'music') and view_id in whitelist:

            context.append((_(33136), "RunPlugin(plugin://plugin.video.emby/?mode=updatelib&id=%s)" % view_id))
            context.append((_(33132), "RunPlugin(plugin://plugin.video.emby/?mode=repairlib&id=%s)" % view_id))
            context.append((_(33133), "RunPlugin(plugin://plugin.video.emby/?mode=removelib&id=%s)" % view_id))

        LOG.debug("--[ listing/%s/%s ] %s", node, label, path)

        if path:
            if xbmc.getCondVisibility('Window.IsActive(Pictures)') and node in ('photos', 'homevideos'):
                directory(label, path, artwork=artwork)
            elif xbmc.getCondVisibility('Window.IsActive(Videos)') and node not in ('photos', 'music', 'audiobooks'):
                directory(label, path, artwork=artwork, context=context)
            elif xbmc.getCondVisibility('Window.IsActive(Music)') and node in ('music'):
                directory(label, path, artwork=artwork, context=context)
            elif not xbmc.getCondVisibility('Window.IsActive(Videos) | Window.IsActive(Pictures) | Window.IsActive(Music)'):
                directory(label, path, artwork=artwork)

    for server in servers:
        context = []

        if server.get('ManualAddress'):
            context.append((_(33141), "RunPlugin(plugin://plugin.video.emby/?mode=removeserver&server=%s)" % server['Id']))

        if 'AccessToken' not in server:
            directory("%s (%s)" % (server['Name'], _(30539)), "plugin://plugin.video.emby/?mode=login&server=%s" % server['Id'], False, context=context)
        else:
            directory(server['Name'], "plugin://plugin.video.emby/?mode=browse&server=%s" % server['Id'], context=context)


    directory(_(33194), "plugin://plugin.video.emby/?mode=managelibs", True)
    directory(_(33134), "plugin://plugin.video.emby/?mode=addserver", False)
    directory(_(33054), "plugin://plugin.video.emby/?mode=adduser", False)
    directory(_(5), "plugin://plugin.video.emby/?mode=settings", False)
    directory(_(33059), "plugin://plugin.video.emby/?mode=texturecache", False)
    directory(_(33058), "plugin://plugin.video.emby/?mode=reset", False)
    directory(_(33192), "plugin://plugin.video.emby/?mode=restartservice", False)

    if settings('backupPath'):
        directory(_(33092), "plugin://plugin.video.emby/?mode=backup", False)

    directory(_(33163), None, False, artwork="special://home/addons/plugin.video.emby/donations.png")

    xbmcplugin.setContent(int(sys.argv[1]), 'files')
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Beispiel #16
0
def listing():
    ''' Display all jellyfin nodes and dynamic entries when appropriate.
    '''
    total = int(window('Jellyfin.nodes.total') or 0)
    sync = get_sync()
    whitelist = [x.replace('Mixed:', "") for x in sync['Whitelist']]
    servers = get_credentials()['Servers'][1:]

    for i in range(total):

        window_prop = "Jellyfin.nodes.%s" % i
        path = window('%s.index' % window_prop)

        if not path:
            path = window('%s.content' % window_prop) or window(
                '%s.path' % window_prop)

        label = window('%s.title' % window_prop)
        node = window('%s.type' % window_prop)
        artwork = window('%s.artwork' % window_prop)
        view_id = window('%s.id' % window_prop)
        context = []

        if view_id and node in ('movies', 'tvshows', 'musicvideos', 'music',
                                'mixed') and view_id not in whitelist:
            label = "%s %s" % (label, translate(33166))
            context.append((
                translate(33123),
                "RunPlugin(plugin://plugin.video.jellyfin/?mode=synclib&id=%s)"
                % view_id))

        if view_id and node in ('movies', 'tvshows', 'musicvideos',
                                'music') and view_id in whitelist:

            context.append((translate(
                33136
            ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=updatelib&id=%s)"
                            % view_id))
            context.append((translate(
                33132
            ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=repairlib&id=%s)"
                            % view_id))
            context.append((translate(
                33133
            ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=removelib&id=%s)"
                            % view_id))

        LOG.debug("--[ listing/%s/%s ] %s", node, label, path)

        if path:
            directory(label, path, artwork=artwork, context=context)

    for server in servers:
        context = []

        if server.get('ManualAddress'):
            context.append((translate(
                33141
            ), "RunPlugin(plugin://plugin.video.jellyfin/?mode=removeserver&server=%s)"
                            % server['Id']))

        if 'AccessToken' not in server:
            directory("%s (%s)" % (server['Name'], translate(30539)),
                      "plugin://plugin.video.jellyfin/?mode=login&server=%s" %
                      server['Id'],
                      False,
                      context=context)
        else:
            directory(server['Name'],
                      "plugin://plugin.video.jellyfin/?mode=browse&server=%s" %
                      server['Id'],
                      context=context)

    directory(translate(33194),
              "plugin://plugin.video.jellyfin/?mode=managelibs", True)
    directory(translate(33134),
              "plugin://plugin.video.jellyfin/?mode=addserver", False)
    directory(translate(33054), "plugin://plugin.video.jellyfin/?mode=adduser",
              False)
    directory(translate(5), "plugin://plugin.video.jellyfin/?mode=settings",
              False)
    directory(translate(33161),
              "plugin://plugin.video.jellyfin/?mode=updatepassword", False)
    directory(translate(33058), "plugin://plugin.video.jellyfin/?mode=reset",
              False)
    directory(translate(33180),
              "plugin://plugin.video.jellyfin/?mode=restartservice", False)

    if settings('backupPath'):
        directory(translate(33092),
                  "plugin://plugin.video.jellyfin/?mode=backup", False)

    xbmcplugin.setContent(PROCESS_HANDLE, 'files')
    xbmcplugin.endOfDirectory(PROCESS_HANDLE)