Skip to content

Commit

Permalink
+ support displaying server messages as notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Mar 1, 2020
1 parent dbb0176 commit 9068184
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- improve mapping of studios, overviews, MPAA and video / audio streams
- redact HTTP request bodies that might contain a password
- download the server's icon to avoid unsupported HTTP HEAD requests
- support displaying server messages as notifications

[B]Version 0.0.5[/B]
- make Direct Play configurable
Expand Down
4 changes: 4 additions & 0 deletions emby/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
WS_DATA = 'Data'
WS_MESSAGE_TYPE_LIBRARY_CHANGED = 'LibraryChanged'
WS_MESSAGE_TYPE_USER_DATA_CHANGED = 'UserDataChanged'
WS_MESSAGE_TYPE_SERVER_SHUTTING_DOWN = 'ServerShuttingDown'
WS_MESSAGE_TYPE_SERVER_RESTARTING = 'ServerRestarting'
WS_LIBRARY_CHANGED_ITEMS_ADDED = 'ItemsAdded'
WS_LIBRARY_CHANGED_ITEMS_UPDATED = 'ItemsUpdated'
WS_LIBRARY_CHANGED_ITEMS_REMOVED = 'ItemsRemoved'
Expand Down Expand Up @@ -186,6 +188,8 @@
SETTING_PROVIDER_PLAYBACK_ALLOW_DIRECT_PLAY = 'emby.allowdirectplay'
SETTING_PROVIDER_PLAYBACK_ENABLE_EXTERNAL_SUBTITLES = 'emby.enableexternalsubtitles'

SETTING_PROVIDER_INTERFACE_SHOW_SERVER_MESSAGES = 'emby.showservermessages'

# media import setting identifiers and values
SETTING_IMPORT_VIEWS = 'emby.importviews'
SETTING_IMPORT_VIEWS_OPTION_ALL = 'all'
Expand Down
21 changes: 20 additions & 1 deletion emby/provider_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import websocket

import xbmc
import xbmcgui
import xbmcmediaimport

from emby.api.library import Library
from emby.constants import *
from emby.server import Server

from lib import kodi
from lib.utils import log, mediaImport2str, mediaProvider2str, Url
from lib.utils import localise, log, mediaImport2str, mediaProvider2str, Url

class ProviderObserver:
class Action:
Expand Down Expand Up @@ -141,6 +142,8 @@ def _ProcessMessage(self, messageObj):
self._ProcessMessageLibraryChanged(data)
elif messageType == WS_MESSAGE_TYPE_USER_DATA_CHANGED:
self._ProcessMessageUserDataChanged(data)
elif messageType in (WS_MESSAGE_TYPE_SERVER_SHUTTING_DOWN, WS_MESSAGE_TYPE_SERVER_RESTARTING):
self._ProcessMessageServer(messageType, data)
else:
ProviderObserver.log('ignoring "{}" message from {}'.format(messageType, mediaProvider2str(self._mediaProvider)), xbmc.LOGDEBUG)

Expand Down Expand Up @@ -226,6 +229,19 @@ def _ProcessMessageUserDataChanged(self, data):

self._ChangeItems(changedItems)

def _ProcessMessageServer(self, messageType, data):
if not self._settings.getBool(SETTING_PROVIDER_INTERFACE_SHOW_SERVER_MESSAGES):
return

if messageType == WS_MESSAGE_TYPE_SERVER_SHUTTING_DOWN:
message = 32051
elif messageType == WS_MESSAGE_TYPE_SERVER_RESTARTING:
message = 32052
else:
return

xbmcgui.Dialog().notification('Emby Media Importer', localise(message).format(self._mediaProvider.getFriendlyName()), self._mediaProvider.getIconUrl())

def _ChangeItems(self, changedItems):
# map the changed items to their media import
changedItemsMap = {}
Expand Down Expand Up @@ -280,6 +296,9 @@ def _StartAction(self, mediaProvider):
# if we are already connected check if something important changed in the media provider
if self._connected:
if kodi.Api.compareMediaProviders(self._mediaProvider, mediaProvider):
# update the media provider and settings anyway
self._mediaProvider = mediaProvider
self._settings = self._mediaProvider.prepareSettings()
return True

self._StopAction(restart=True)
Expand Down
18 changes: 18 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,25 @@ msgctxt "#32032"
msgid "Enable external subtitles"
msgstr ""

msgctxt "#32033"
msgid "Interface"
msgstr ""

msgctxt "#32034"
msgid "Show server messages as notifications"
msgstr ""

#. Titel of the dialog to enter the base URI of the Emby server to lookup
msgctxt "#32050"
msgid "Emby server base URI"
msgstr ""

#. Text of the notification when an Emby server is shutting down
msgctxt "#32051"
msgid "{} is shutting down."
msgstr ""

#. Text of the notification when an Emby server is restarting
msgctxt "#32052"
msgid "{} is restarting."
msgstr ""
9 changes: 9 additions & 0 deletions resources/providersettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,14 @@
</setting>
</group>
</category>
<category id="interface" label="32033">
<group id="1">
<setting id="emby.showservermessages" type="boolean" label="32034">
<level>0</level>
<default>false</default>
<control type="toggle" />
</setting>
</group>
</category>
</section>
</settings>

0 comments on commit 9068184

Please sign in to comment.