Refactor service.py
This commit is contained in:
parent
1b74f25dfa
commit
b1f6bd1edf
6 changed files with 60 additions and 50 deletions
|
@ -17,7 +17,8 @@
|
|||
|
||||
<string id="30014">Connection</string>
|
||||
<string id="30015">Network</string>
|
||||
<string id="30016">Device Name</string>
|
||||
<string id="30016">Device Name</string>
|
||||
<string id="30017">Unauthorized for PMS</string>
|
||||
|
||||
<string id="30022">Advanced</string>
|
||||
<string id="30024">Username</string><!-- Verified -->
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
<string id="30011">Caching-Mechanismus</string>
|
||||
<string id="30012">OK</string>
|
||||
<string id="30013">Nie anzeigen</string>
|
||||
<string id="30017">Nicht autorisiert für PMS</string>
|
||||
|
||||
|
||||
<string id="30500">Host SSL Zertifikat überprüfen (sicherer)</string>
|
||||
<string id="30507">Synchronisations-Fortschritt anzeigen</string>
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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'):
|
||||
|
|
|
@ -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"
|
||||
|
|
66
service.py
66
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:
|
||||
|
|
Loading…
Reference in a new issue