mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-11-10 18:36:33 +00:00
Try something else
This commit is contained in:
parent
119657f989
commit
877daf2e14
4 changed files with 73 additions and 99 deletions
|
|
@ -508,7 +508,7 @@ def get_fanart(item_id, path, server_id=None):
|
||||||
list_li = []
|
list_li = []
|
||||||
directory = xbmc.translatePath("special://thumbnails/jellyfin/%s/" % item_id)
|
directory = xbmc.translatePath("special://thumbnails/jellyfin/%s/" % item_id)
|
||||||
jellyfin_client = Jellyfin(server_id).get_client()
|
jellyfin_client = Jellyfin(server_id).get_client()
|
||||||
server = jellyfin_client.auth..get_server_address()
|
server = jellyfin_client.auth.get_server_address()
|
||||||
|
|
||||||
if not xbmcvfs.exists(directory):
|
if not xbmcvfs.exists(directory):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from helper import has_attribute, LazyLogger, window, api, dialog, translate, settings
|
from helper import has_attribute, LazyLogger
|
||||||
|
|
||||||
from .client import JellyfinClient
|
from .client import JellyfinClient
|
||||||
from client import get_device_id
|
|
||||||
import connect
|
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
@ -17,21 +15,6 @@ LOG = LazyLogger()
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
def ensure_client():
|
|
||||||
|
|
||||||
def decorator(func):
|
|
||||||
def wrapper(self, *args, **kwargs):
|
|
||||||
|
|
||||||
if self.client.get(self.server_id) is None:
|
|
||||||
self.construct()
|
|
||||||
|
|
||||||
return func(self, *args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
class Jellyfin(object):
|
class Jellyfin(object):
|
||||||
|
|
||||||
''' This is your Jellyfinclient, you can create more than one. The server_id is only a temporary thing
|
''' This is your Jellyfinclient, you can create more than one. The server_id is only a temporary thing
|
||||||
|
|
@ -55,6 +38,9 @@ class Jellyfin(object):
|
||||||
self.__dict__ = self._shared_state
|
self.__dict__ = self._shared_state
|
||||||
self.server_id = server_id or "default"
|
self.server_id = server_id or "default"
|
||||||
|
|
||||||
|
if self.server_id not in self.client:
|
||||||
|
self.client[self.server_id] = JellyfinClient(self.server_id)
|
||||||
|
|
||||||
def get_client(self):
|
def get_client(self):
|
||||||
# type: () -> JellyfinClient
|
# type: () -> JellyfinClient
|
||||||
return self.client[self.server_id]
|
return self.client[self.server_id]
|
||||||
|
|
@ -82,7 +68,6 @@ class Jellyfin(object):
|
||||||
def get_active_clients(cls):
|
def get_active_clients(cls):
|
||||||
return cls.client
|
return cls.client
|
||||||
|
|
||||||
@ensure_client()
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
|
||||||
if has_attribute(self, name):
|
if has_attribute(self, name):
|
||||||
|
|
@ -90,78 +75,5 @@ class Jellyfin(object):
|
||||||
|
|
||||||
setattr(self.client[self.server_id], name, value)
|
setattr(self.client[self.server_id], name, value)
|
||||||
|
|
||||||
@ensure_client()
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.client[self.server_id], name)
|
return getattr(self.client[self.server_id], name)
|
||||||
|
|
||||||
def construct(self):
|
|
||||||
self.client[self.server_id] = JellyfinClient()
|
|
||||||
|
|
||||||
try:
|
|
||||||
connect.Connect().register(self.server_id)
|
|
||||||
self.register_client()
|
|
||||||
except Exception as error:
|
|
||||||
LOG.exception(error)
|
|
||||||
dialog("ok", "{jellyfin}", translate(33142))
|
|
||||||
return
|
|
||||||
|
|
||||||
LOG.info("---[ START JELLYFINCLIENT: %s ]---", self.server_id)
|
|
||||||
|
|
||||||
def register_client(self):
|
|
||||||
client = self.get_client()
|
|
||||||
device_id = get_device_id()
|
|
||||||
self.post_capabilities(client, device_id)
|
|
||||||
|
|
||||||
if self.server_id is None and settings('additionalUsers'):
|
|
||||||
users = settings('additionalUsers').split(',')
|
|
||||||
all_users = client.jellyfin.get_users()
|
|
||||||
|
|
||||||
for additional in users:
|
|
||||||
for user in all_users:
|
|
||||||
if user['Name'].lower() in additional.lower():
|
|
||||||
client.jellyfin.session_add_user(client.config.data['app.session'], user['Id'], True)
|
|
||||||
|
|
||||||
self.additional_users(client, device_id)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def additional_users(server, device_id):
|
|
||||||
''' Setup additional users images.
|
|
||||||
'''
|
|
||||||
for i in range(10):
|
|
||||||
window('JellyfinAdditionalUserImage.%s' % i, clear=True)
|
|
||||||
|
|
||||||
try:
|
|
||||||
session = server.jellyfin.get_device(device_id)
|
|
||||||
except Exception as error:
|
|
||||||
LOG.exception(error)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
for index, user in enumerate(session[0]['AdditionalUsers']):
|
|
||||||
|
|
||||||
info = server.jellyfin.get_user(user['UserId'])
|
|
||||||
image = api.API(info, server.config.data['auth.server']).get_user_artwork(user['UserId'])
|
|
||||||
window('JellyfinAdditionalUserImage.%s' % index, image)
|
|
||||||
window('JellyfinAdditionalUserPosition.%s' % user['UserId'], str(index))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def post_capabilities(client, device_id):
|
|
||||||
LOG.info("--[ post capabilities/%s ]", client.auth.server_id)
|
|
||||||
|
|
||||||
client.jellyfin.post_capabilities({
|
|
||||||
'PlayableMediaTypes': "Audio,Video",
|
|
||||||
'SupportsMediaControl': True,
|
|
||||||
'SupportedCommands': (
|
|
||||||
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
|
||||||
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
|
||||||
"GoHome,PageUp,NextLetter,GoToSearch,"
|
|
||||||
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
|
||||||
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
|
||||||
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
|
||||||
"SetRepeatMode,"
|
|
||||||
"Mute,Unmute,SetVolume,"
|
|
||||||
"Play,Playstate,PlayNext,PlayMediaSource"
|
|
||||||
),
|
|
||||||
})
|
|
||||||
session = client.jellyfin.get_device(device_id)
|
|
||||||
client.config.data['app.session'] = session[0]['Id']
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger, window, dialog, translate, settings
|
||||||
|
from helper import api as helper_api
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from .configuration import Config
|
from .configuration import Config
|
||||||
from .http import HTTP
|
from .http import HTTP
|
||||||
from .ws_client import WSClient
|
from .ws_client import WSClient
|
||||||
from .connection_manager import ConnectionManager, CONNECTION_STATE
|
from .connection_manager import ConnectionManager, CONNECTION_STATE
|
||||||
|
from client import get_device_id
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
@ -29,9 +31,7 @@ def callback(message, data):
|
||||||
|
|
||||||
class JellyfinClient(object):
|
class JellyfinClient(object):
|
||||||
|
|
||||||
logged_in = False
|
def __init__(self, server_id):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
LOG.debug("JellyfinClient initializing...")
|
LOG.debug("JellyfinClient initializing...")
|
||||||
|
|
||||||
self.config = Config()
|
self.config = Config()
|
||||||
|
|
@ -41,6 +41,66 @@ class JellyfinClient(object):
|
||||||
self.jellyfin = api.API(self.http)
|
self.jellyfin = api.API(self.http)
|
||||||
self.callback_ws = callback
|
self.callback_ws = callback
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
self.server_id = server_id
|
||||||
|
self.logged_in = False
|
||||||
|
|
||||||
|
def register_client(self):
|
||||||
|
device_id = get_device_id()
|
||||||
|
self.post_capabilities(self, device_id)
|
||||||
|
|
||||||
|
if self.server_id == 'default' and settings('additionalUsers'):
|
||||||
|
users = settings('additionalUsers').split(',')
|
||||||
|
all_users = self.jellyfin.get_users()
|
||||||
|
|
||||||
|
for additional in users:
|
||||||
|
for user in all_users:
|
||||||
|
if user['Name'].lower() in additional.lower():
|
||||||
|
self.jellyfin.session_add_user(self.config.data['app.session'], user['Id'], True)
|
||||||
|
|
||||||
|
self.additional_users(self, device_id)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def additional_users(client, device_id):
|
||||||
|
''' Setup additional users images.
|
||||||
|
'''
|
||||||
|
for i in range(10):
|
||||||
|
window('JellyfinAdditionalUserImage.%s' % i, clear=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
session = client.jellyfin.get_device(device_id)
|
||||||
|
except Exception as error:
|
||||||
|
LOG.exception(error)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
for index, user in enumerate(session[0]['AdditionalUsers']):
|
||||||
|
|
||||||
|
info = client.jellyfin.get_user(user['UserId'])
|
||||||
|
image = helper_api.API(info, client.config.data['auth.server']).get_user_artwork(user['UserId'])
|
||||||
|
window('JellyfinAdditionalUserImage.%s' % index, image)
|
||||||
|
window('JellyfinAdditionalUserPosition.%s' % user['UserId'], str(index))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def post_capabilities(client, device_id):
|
||||||
|
LOG.info("--[ post capabilities/%s ]", client.auth.server_id)
|
||||||
|
|
||||||
|
client.jellyfin.post_capabilities({
|
||||||
|
'PlayableMediaTypes': "Audio,Video",
|
||||||
|
'SupportsMediaControl': True,
|
||||||
|
'SupportedCommands': (
|
||||||
|
"MoveUp,MoveDown,MoveLeft,MoveRight,Select,"
|
||||||
|
"Back,ToggleContextMenu,ToggleFullscreen,ToggleOsdMenu,"
|
||||||
|
"GoHome,PageUp,NextLetter,GoToSearch,"
|
||||||
|
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
||||||
|
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
||||||
|
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
||||||
|
"SetRepeatMode,"
|
||||||
|
"Mute,Unmute,SetVolume,"
|
||||||
|
"Play,Playstate,PlayNext,PlayMediaSource"
|
||||||
|
),
|
||||||
|
})
|
||||||
|
session = client.jellyfin.get_device(device_id)
|
||||||
|
client.config.data['app.session'] = session[0]['Id']
|
||||||
|
|
||||||
def set_credentials(self, credentials=None):
|
def set_credentials(self, credentials=None):
|
||||||
self.auth.credentials.set_credentials(credentials or {})
|
self.auth.credentials.set_credentials(credentials or {})
|
||||||
|
|
@ -76,6 +136,9 @@ class JellyfinClient(object):
|
||||||
if websocket:
|
if websocket:
|
||||||
self.start_wsc()
|
self.start_wsc()
|
||||||
|
|
||||||
|
self.register_client()
|
||||||
|
LOG.info("---[ START JELLYFINCLIENT: %s ]---", self.server_id)
|
||||||
|
|
||||||
def start_wsc(self):
|
def start_wsc(self):
|
||||||
self.wsc.start()
|
self.wsc.start()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,10 @@ import threading
|
||||||
|
|
||||||
from kodi_six import xbmc
|
from kodi_six import xbmc
|
||||||
|
|
||||||
import connect
|
|
||||||
import player
|
import player
|
||||||
from client import get_device_id
|
from client import get_device_id
|
||||||
from objects import PlaylistWorker, on_play, on_update, special_listener
|
from objects import PlaylistWorker, on_play, on_update, special_listener
|
||||||
from helper import translate, settings, window, dialog, api, JSONRPC
|
from helper import settings, dialog, JSONRPC
|
||||||
from helper.utils import JsonDebugPrinter
|
from helper.utils import JsonDebugPrinter
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
from helper import LazyLogger
|
from helper import LazyLogger
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue