diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 539241ab..da8ac678 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -17,7 +17,8 @@ Connection Network - Device Name + Device Name + Unauthorized for PMS Advanced Username diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index 89b82879..7a37ec37 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -14,6 +14,8 @@ Caching-Mechanismus OK Nie anzeigen + Nicht autorisiert für PMS + Host SSL Zertifikat überprüfen (sicherer) Synchronisations-Fortschritt anzeigen diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 9d50e4d8..b98619a2 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -6,9 +6,7 @@ import logging import requests import xml.etree.ElementTree as etree -import xbmcgui - -from utils import settings, window, language as lang +from utils import settings, window, language as lang, dialog import clientinfo as client ############################################################################### @@ -280,10 +278,10 @@ class DownloadUtils(): log.debug('Setting PMS server status to ' 'unauthorized') window('plex_serverStatus', value="401") - xbmcgui.Dialog().notification( - lang(29999), - "Unauthorized for PMS", - xbmcgui.NOTIFICATION_ERROR) + dialog('notification', + lang(29999), + lang(30017), + icon='{error}') else: # there might be other 401 where e.g. PMS under strain log.info('PMS might only be under strain') diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 57fcc798..3f92e05f 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -91,14 +91,27 @@ def language(stringid): return ADDON.getLocalizedString(stringid) -def dialog(type_, *args, **kwargs): +def dialog(typus, *args, **kwargs): + """ + Displays xbmcgui Dialog. Pass a string as typus: + 'yesno', 'ok', 'notification', 'input', 'select', 'numeric' + Icons: + icon='{plex}' Display Plex standard icon + icon='{info}' xbmcgui.NOTIFICATION_INFO + icon='{warning}' xbmcgui.NOTIFICATION_WARNING + icon='{error}' xbmcgui.NOTIFICATION_ERROR + """ d = xbmcgui.Dialog() - if "icon" in kwargs: - kwargs['icon'] = kwargs['icon'].replace( - "{plex}", - "special://home/addons/plugin.video.plexkodiconnect/icon.png") + repl = { + '{plex}': 'special://home/addons/plugin.video.plexkodiconnect/icon.png', + '{info}': xbmcgui.NOTIFICATION_INFO, + '{warning}': xbmcgui.NOTIFICATION_WARNING, + '{error}': xbmcgui.NOTIFICATION_ERROR + } + for key, value in repl.iteritems(): + kwargs['icon'] = kwargs['icon'].replace(key, value) if "heading" in kwargs: kwargs['heading'] = kwargs['heading'].replace("{plex}", language(29999)) @@ -111,7 +124,7 @@ def dialog(type_, *args, **kwargs): 'select': d.select, 'numeric': d.numeric } - return types[type_](*args, **kwargs) + return types[typus](*args, **kwargs) def tryEncode(uniString, encoding='utf-8'): diff --git a/resources/lib/variables.py b/resources/lib/variables.py index d3f7a263..e7bb4caf 100644 --- a/resources/lib/variables.py +++ b/resources/lib/variables.py @@ -9,6 +9,8 @@ ADDON_VERSION = Addon().getAddonInfo('version') KODILANGUAGE = xbmc.getLanguage(xbmc.ISO_639_1) KODIVERSION = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) +KODILONGVERSION = xbmc.getInfoLabel('System.BuildVersion') +KODI_PROFILE = xbmc.translatePath("special://profile") if xbmc.getCondVisibility('system.platform.osx'): PLATFORM = "MacOSX" diff --git a/service.py b/service.py index ae86eead..9cc0f12a 100644 --- a/service.py +++ b/service.py @@ -3,35 +3,34 @@ ############################################################################### import logging -import os -import sys +from os import path as os_path +from sys import path as sys_path -import xbmc -import xbmcaddon -import xbmcgui +from xbmc import translatePath, Monitor, sleep +from xbmcaddon import Addon ############################################################################### -_addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect') +_addon = Addon(id='plugin.video.plexkodiconnect') try: _addon_path = _addon.getAddonInfo('path').decode('utf-8') except TypeError: _addon_path = _addon.getAddonInfo('path').decode() try: - _base_resource = xbmc.translatePath(os.path.join( + _base_resource = translatePath(os_path.join( _addon_path, 'resources', 'lib')).decode('utf-8') except TypeError: - _base_resource = xbmc.translatePath(os.path.join( + _base_resource = translatePath(os_path.join( _addon_path, 'resources', 'lib')).decode() -sys.path.append(_base_resource) +sys_path.append(_base_resource) ############################################################################### -from utils import settings, window, language as lang +from utils import settings, window, language as lang, dialog from userclient import UserClient import initialsetup from kodimonitor import KodiMonitor @@ -81,11 +80,11 @@ class Service(): def __init__(self): logLevel = self.getLogLevel() - self.monitor = xbmc.Monitor() + self.monitor = Monitor() window('plex_logLevel', value=str(logLevel)) window('plex_kodiProfile', - value=xbmc.translatePath("special://profile")) + value=translatePath("special://profile")) window('plex_context', value='true' if settings('enableContext') == "true" else "") window('fetch_pms_item_number', @@ -94,7 +93,7 @@ class Service(): # Initial logging log.warn("======== START %s ========" % v.ADDON_NAME) log.warn("Platform: %s" % v.PLATFORM) - log.warn("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion')) + log.warn("KODI Version: %s" % v.KODILONGVERSION) log.warn("%s Version: %s" % (v.ADDON_NAME, v.ADDON_VERSION)) log.warn("Using plugin paths: %s" % (settings('useDirectPaths') != "true")) @@ -137,7 +136,7 @@ class Service(): # Important: Threads depending on abortRequest will not trigger # if profile switch happens more than once. monitor = self.monitor - kodiProfile = xbmc.translatePath("special://profile") + kodiProfile = v.KODI_PROFILE # Detect playback start early on self.monitor_kodi_play = Monitor_Kodi_Play(self) @@ -184,12 +183,10 @@ class Service(): if welcome_msg is True: # Reset authentication warnings welcome_msg = False - xbmcgui.Dialog().notification( - heading=lang(29999), - message="%s %s" % (lang(33000), - self.user.currUser), - icon="special://home/addons/plugin." - "video.plexkodiconnect/icon.png", + dialog.notification( + lang(29999), + "%s %s" % (lang(33000), + self.user.currUser), time=2000, sound=False) # Start monitoring kodi events @@ -237,7 +234,7 @@ class Service(): if monitor.waitForAbort(5): # Abort was requested while waiting. We should exit break - xbmc.sleep(50) + sleep(50) else: # Wait until Plex server is online # or Kodi is shut down. @@ -256,13 +253,11 @@ class Service(): window('suspend_LibraryThread', value='true') log.error("Plex Media Server went offline") if settings('show_pms_offline') == 'true': - xbmcgui.Dialog().notification( - heading=lang(33001), - message="%s %s" - % (lang(29999), lang(33002)), - icon="special://home/addons/plugin.video." - "plexkodiconnect/icon.png", - sound=False) + dialog('notification', + lang(33001), + "%s %s" % (lang(29999), lang(33002)), + icon='{plex}', + sound=False) counter += 1 # Periodically check if the IP changed, e.g. per minute if counter > 20: @@ -284,13 +279,12 @@ class Service(): # Alert the user that server is online. if (welcome_msg is False and settings('show_pms_offline') == 'true'): - xbmcgui.Dialog().notification( - heading=lang(29999), - message=lang(33003), - icon="special://home/addons/plugin.video." - "plexkodiconnect/icon.png", - time=5000, - sound=False) + dialog('notification', + lang(29999), + lang(33003), + icon='{plex}', + time=5000, + sound=False) log.info("Server %s is online and ready." % server) window('plex_online', value="true") if window('plex_authenticated') == 'true': @@ -344,7 +338,7 @@ class Service(): delay = int(settings('startupDelay')) log.warn("Delaying Plex startup by: %s sec..." % delay) -if delay and xbmc.Monitor().waitForAbort(delay): +if delay and Monitor().waitForAbort(delay): # Start the service log.warn("Abort requested while waiting. PKC not started.") else: