Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user to session non-interactively #829

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions jellyfin_kodi/entrypoint/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self):
elif mode == 'settings':
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.jellyfin)')
elif mode == 'adduser':
add_user(api_client)
add_user(api_client, params)
elif mode == 'updatepassword':
event('UpdatePassword')
elif mode == 'thememedia':
Expand Down Expand Up @@ -751,7 +751,7 @@ def create_listitem(item):
return li


def add_user(api_client):
def add_user(api_client, params: dict):

''' Add or remove users from the default server session.
'''
Expand All @@ -762,27 +762,38 @@ def add_user(api_client):
users = api_client.get_users()
current = session[0]['AdditionalUsers']

result = dialog("select", translate(33061), [translate(33062), translate(33063)] if current else [translate(33062)])
if params.get('remove'):
result = True
elif params.get('add'):
result = False
else:
result = dialog("select", translate(33061), [translate(33062), translate(33063)] if current else [translate(33062)])

if result < 0:
return

if not result: # Add user
eligible = [x for x in users if x['Id'] not in [current_user['UserId'] for current_user in current]]
resp = dialog("select", translate(33064), [x['Name'] for x in eligible])
if params.get('add'):
user = [x for x in current if x['UserName'] == params.get('add')][0]
else:
resp = dialog("select", translate(33064), [x['Name'] for x in eligible])

if resp < 0:
return
if resp < 0:
return

user = eligible[resp]
user = eligible[resp]
event('AddUser', {'Id': user['Id'], 'Add': True})
else: # Remove user
resp = dialog("select", translate(33064), [x['UserName'] for x in current])
if params.get('remove'):
user = [x for x in current if x['UserName'] == params.get('remove')][0]
else:
resp = dialog("select", translate(33064), [x['UserName'] for x in current])

if resp < 0:
return
if resp < 0:
return

user = current[resp]
user = current[resp]
event('AddUser', {'Id': user['UserId'], 'Add': False})


Expand Down