mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-01-24 17:06:11 +00:00
Add utils dialog
Centralize for later, control icon, etc. Pylint.
This commit is contained in:
parent
9e9054865a
commit
21f8a62ebd
3 changed files with 63 additions and 50 deletions
|
@ -80,7 +80,6 @@ class InitialSetup(object):
|
|||
current_server = self.user_client.get_server()
|
||||
if current_server is not None:
|
||||
server = self.connectmanager.get_server(current_server)
|
||||
log.info(server)
|
||||
settings('ServerId', value=server['Id'])
|
||||
self.user_client.get_userid()
|
||||
self.user_client.get_token()
|
||||
|
|
|
@ -50,6 +50,23 @@ def language(string_id):
|
|||
# Central string retrieval - unicode
|
||||
return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id)
|
||||
|
||||
def dialog(type_, **kwargs):
|
||||
|
||||
d = xbmcgui.Dialog()
|
||||
|
||||
if "icon" in kwargs:
|
||||
kwargs['icon'] = kwargs['icon'].replace("{default}",
|
||||
"special://home/addons/plugin.video.emby/icon.png")
|
||||
|
||||
types = {
|
||||
'yesno': d.yesno,
|
||||
'ok': d.ok,
|
||||
'notification': d.notification,
|
||||
'input': d.input
|
||||
}
|
||||
return types[type_](**kwargs)
|
||||
|
||||
|
||||
class JSONRPC(object):
|
||||
|
||||
id_ = 1
|
||||
|
|
79
service.py
79
service.py
|
@ -5,21 +5,19 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import _strptime # Workaround for threads using datetime: _striptime is locked
|
||||
from datetime import datetime
|
||||
|
||||
import xbmc
|
||||
import xbmcaddon
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
|
||||
#################################################################################################
|
||||
|
||||
_addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
|
||||
_base_resource = xbmc.translatePath(os.path.join(_addon_path, 'resources', 'lib')).decode('utf-8')
|
||||
sys.path.append(_base_resource)
|
||||
_ADDON = xbmcaddon.Addon(id='plugin.video.emby')
|
||||
_CWD = _ADDON.getAddonInfo('path').decode('utf-8')
|
||||
_BASE_LIB = xbmc.translatePath(os.path.join(_CWD, 'resources', 'lib')).decode('utf-8')
|
||||
sys.path.append(_BASE_LIB)
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
@ -31,7 +29,7 @@ import librarysync
|
|||
import player
|
||||
import videonodes
|
||||
import websocket_client as wsc
|
||||
from utils import window, settings, language as lang
|
||||
from utils import window, settings, dialog, language as lang
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
@ -66,13 +64,13 @@ class Service(object):
|
|||
window('emby_kodiProfile', value=xbmc.translatePath('special://profile'))
|
||||
|
||||
# Initial logging
|
||||
log.warn("======== START %s ========" % self.addonName)
|
||||
log.warn("======== START %s ========", self.addonName)
|
||||
log.warn("Python Version: %s", sys.version)
|
||||
log.warn("Platform: %s" % (self.clientInfo.get_platform()))
|
||||
log.warn("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'))
|
||||
log.warn("%s Version: %s" % (self.addonName, self.clientInfo.get_version()))
|
||||
log.warn("Using plugin paths: %s" % (settings('useDirectPaths') == "0"))
|
||||
log.warn("Log Level: %s" % logLevel)
|
||||
log.warn("Platform: %s", self.clientInfo.get_platform())
|
||||
log.warn("KODI Version: %s", xbmc.getInfoLabel('System.BuildVersion'))
|
||||
log.warn("%s Version: %s", self.addonName, self.clientInfo.get_version())
|
||||
log.warn("Using plugin paths: %s", settings('useDirectPaths') == "0")
|
||||
log.warn("Log Level: %s", logLevel)
|
||||
|
||||
# Reset window props for profile switch
|
||||
properties = [
|
||||
|
@ -92,7 +90,7 @@ class Service(object):
|
|||
window('emby_minDBVersion', value="1.1.63")
|
||||
|
||||
|
||||
def ServiceEntryPoint(self):
|
||||
def service_entry_point(self):
|
||||
|
||||
# Important: Threads depending on abortRequest will not trigger
|
||||
# if profile switch happens more than once.
|
||||
|
@ -114,9 +112,8 @@ class Service(object):
|
|||
|
||||
if window('emby_kodiProfile') != kodiProfile:
|
||||
# Profile change happened, terminate this thread and others
|
||||
log.info("Kodi profile was: %s and changed to: %s. Terminating old Emby thread."
|
||||
% (kodiProfile, window('emby_kodiProfile')))
|
||||
|
||||
log.info("Kodi profile was: %s and changed to: %s. Terminating old Emby thread.",
|
||||
kodiProfile, window('emby_kodiProfile'))
|
||||
break
|
||||
|
||||
# Before proceeding, need to make sure:
|
||||
|
@ -171,14 +168,14 @@ class Service(object):
|
|||
add = ", %s" % ", ".join(additionalUsers)
|
||||
else:
|
||||
add = ""
|
||||
xbmcgui.Dialog().notification(
|
||||
heading=lang(29999),
|
||||
message=("%s %s%s!"
|
||||
% (lang(33000), user.get_username().decode('utf-8'),
|
||||
add.decode('utf-8'))),
|
||||
icon="special://home/addons/plugin.video.emby/icon.png",
|
||||
time=2000,
|
||||
sound=False)
|
||||
dialog(type_="notification",
|
||||
heading=lang(29999),
|
||||
message=("%s %s%s!"
|
||||
% (lang(33000), user.get_username().decode('utf-8'),
|
||||
add.decode('utf-8'))),
|
||||
icon="{default}",
|
||||
time=2000,
|
||||
sound=False)
|
||||
|
||||
# Start monitoring kodi events
|
||||
if not self.kodimonitor_running:
|
||||
|
@ -228,11 +225,11 @@ class Service(object):
|
|||
window('emby_online', value="false")
|
||||
|
||||
if settings('offlineMsg') == "true":
|
||||
xbmcgui.Dialog().notification(
|
||||
heading=lang(33001),
|
||||
message="%s %s" % (self.addonName, lang(33002)),
|
||||
icon="special://home/addons/plugin.video.emby/icon.png",
|
||||
sound=False)
|
||||
dialog(type_="notification",
|
||||
heading=lang(33001),
|
||||
message="%s %s" % (self.addonName, lang(33002)),
|
||||
icon="{default}",
|
||||
sound=False)
|
||||
|
||||
self.server_online = False
|
||||
|
||||
|
@ -257,12 +254,12 @@ class Service(object):
|
|||
# Abort was requested while waiting.
|
||||
break
|
||||
# Alert the user that server is online.
|
||||
xbmcgui.Dialog().notification(
|
||||
heading=lang(29999),
|
||||
message=lang(33003),
|
||||
icon="special://home/addons/plugin.video.emby/icon.png",
|
||||
time=2000,
|
||||
sound=False)
|
||||
dialog(type_="notification",
|
||||
heading=lang(29999),
|
||||
message=lang(33003),
|
||||
icon="{default}",
|
||||
time=2000,
|
||||
sound=False)
|
||||
|
||||
self.server_online = True
|
||||
log.info("Server is online and ready.")
|
||||
|
@ -294,14 +291,14 @@ class Service(object):
|
|||
if self.websocket_running:
|
||||
ws.stopClient()
|
||||
|
||||
log.warn("======== STOP %s ========" % self.addonName)
|
||||
log.warn("======== STOP %s ========", self.addonName)
|
||||
|
||||
# Delay option
|
||||
delay = int(settings('startupDelay'))
|
||||
log.warn("Delaying emby startup by: %s sec..." % delay)
|
||||
DELAY = int(settings('startupDelay'))
|
||||
log.warn("Delaying emby startup by: %s sec...", DELAY)
|
||||
|
||||
if delay and xbmc.Monitor().waitForAbort(delay):
|
||||
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
||||
# Start the service
|
||||
log.warn("Abort requested while waiting. Emby for kodi not started.")
|
||||
else:
|
||||
Service().ServiceEntryPoint()
|
||||
Service().service_entry_point()
|
||||
|
|
Loading…
Reference in a new issue